You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2019/12/12 18:03:31 UTC
svn commit: r1871275 -
/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java
Author: tilman
Date: Thu Dec 12 18:03:31 2019
New Revision: 1871275
URL: http://svn.apache.org/viewvc?rev=1871275&view=rev
Log:
PDFBOX-4708: copy from trunk, remove try-with-resources
Added:
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java
- copied, changed from r1871273, pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java
Copied: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java (from r1871273, pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java)
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java?p2=pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java&p1=pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java&r1=1871273&r2=1871275&rev=1871275&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java Thu Dec 12 18:03:31 2019
@@ -33,6 +33,7 @@ import org.apache.pdfbox.pdmodel.PDDocum
import org.apache.pdfbox.rendering.PDFRenderer;
import org.apache.pdfbox.rendering.TestPDFToImage;
import org.junit.Before;
+import org.junit.Test;
/**
* Test flatten different forms and compare with rendering.
@@ -41,7 +42,8 @@ import org.junit.Before;
* as the test results need manual inspection. Enable as needed.
*
*/
-public class PDAcroFormFlattenTest {
+public class PDAcroFormFlattenTest
+{
private static final File IN_DIR = new File("target/test-output/flatten/in");
private static final File OUT_DIR = new File("target/test-output/flatten/out");
@@ -56,7 +58,7 @@ public class PDAcroFormFlattenTest {
/*
* PDFBOX-142 Filled template.
*/
- // @Test
+ //@Test
public void testFlattenPDFBOX142() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12742551/Testformular1.pdf";
@@ -68,7 +70,7 @@ public class PDAcroFormFlattenTest {
/*
* PDFBOX-563 Filled template.
*/
- // @Test
+ //@Test
public void testFlattenPDFBOX563() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12425859/TestFax_56972.pdf";
@@ -80,7 +82,7 @@ public class PDAcroFormFlattenTest {
/*
* PDFBOX-2469 Empty template.
*/
- // @Test
+ //@Test
public void testFlattenPDFBOX2469Empty() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12682897/FormI-9-English.pdf";
@@ -92,7 +94,7 @@ public class PDAcroFormFlattenTest {
/*
* PDFBOX-2469 Filled template.
*/
- // @Test
+ //@Test
public void testFlattenPDFBOX2469Filled() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12678455/testPDF_acroForm.pdf";
@@ -104,7 +106,7 @@ public class PDAcroFormFlattenTest {
/*
* PDFBOX-2586 Empty template.
*/
- // @Test
+ //@Test
public void testFlattenPDFBOX2586() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12689788/test.pdf";
@@ -116,7 +118,7 @@ public class PDAcroFormFlattenTest {
/*
* PDFBOX-3083 Filled template rotated.
*/
- // @Test
+ //@Test
public void testFlattenPDFBOX3083() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12770263/mypdf.pdf";
@@ -128,7 +130,7 @@ public class PDAcroFormFlattenTest {
/*
* PDFBOX-3262 Hidden fields
*/
- // @Test
+ //@Test
public void testFlattenPDFBOX3262() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12792007/hidden_fields.pdf";
@@ -140,7 +142,7 @@ public class PDAcroFormFlattenTest {
/*
* PDFBOX-3396 Signed Document 1.
*/
- // @Test
+ //@Test
public void testFlattenPDFBOX3396_1() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12816014/Signed-Document-1.pdf";
@@ -152,7 +154,7 @@ public class PDAcroFormFlattenTest {
/*
* PDFBOX-3396 Signed Document 2.
*/
- // @Test
+ //@Test
public void testFlattenPDFBOX3396_2() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12816016/Signed-Document-2.pdf";
@@ -164,7 +166,7 @@ public class PDAcroFormFlattenTest {
/*
* PDFBOX-3396 Signed Document 3.
*/
- // @Test
+ //@Test
public void testFlattenPDFBOX3396_3() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12821307/Signed-Document-3.pdf";
@@ -176,7 +178,7 @@ public class PDAcroFormFlattenTest {
/*
* PDFBOX-3396 Signed Document 4.
*/
- // @Test
+ //@Test
public void testFlattenPDFBOX3396_4() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12821308/Signed-Document-4.pdf";
@@ -188,7 +190,7 @@ public class PDAcroFormFlattenTest {
/*
* PDFBOX-3587 Empty template.
*/
- // @Test
+ //@Test
public void testFlattenOpenOfficeForm() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12839977/OpenOfficeForm.pdf";
@@ -200,7 +202,7 @@ public class PDAcroFormFlattenTest {
/*
* PDFBOX-3587 Filled template.
*/
- // @Test
+ //@Test
public void testFlattenOpenOfficeFormFilled() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12840280/OpenOfficeForm_filled.pdf";
@@ -212,7 +214,7 @@ public class PDAcroFormFlattenTest {
/**
* PDFBOX-4157 Filled template.
*/
- // @Test
+ //@Test
public void testFlattenPDFBox4157() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12976553/PDFBOX-4157-filled.pdf";
@@ -224,7 +226,7 @@ public class PDAcroFormFlattenTest {
/**
* PDFBOX-4172 Filled template.
*/
- // @Test
+ //@Test
public void testFlattenPDFBox4172() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12976552/PDFBOX-4172-filled.pdf";
@@ -236,7 +238,7 @@ public class PDAcroFormFlattenTest {
/**
* PDFBOX-4615 Filled template.
*/
- // @Test
+ //@Test
public void testFlattenPDFBox4615() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12976452/resetboundingbox-filled.pdf";
@@ -248,7 +250,7 @@ public class PDAcroFormFlattenTest {
/**
* PDFBOX-4693: page is not rotated, but the appearance stream is.
*/
- // @Test
+ //@Test
public void testFlattenPDFBox4693() throws IOException
{
String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12986337/stenotypeTest-3_rotate_no_flatten.pdf";
@@ -268,13 +270,12 @@ public class PDAcroFormFlattenTest {
File inputFile = new File(IN_DIR, targetFileName);
File outputFile = new File(OUT_DIR, targetFileName);
- try (PDDocument testPdf = PDDocument.load(inputFile))
- {
- testPdf.getDocumentCatalog().getAcroForm().flatten();
- testPdf.setAllSecurityToBeRemoved(true);
- assertTrue(testPdf.getDocumentCatalog().getAcroForm().getFields().isEmpty());
- testPdf.save(outputFile);
- }
+ PDDocument testPdf = PDDocument.load(inputFile);
+ testPdf.getDocumentCatalog().getAcroForm().flatten();
+ testPdf.setAllSecurityToBeRemoved(true);
+ assertTrue(testPdf.getDocumentCatalog().getAcroForm().getFields().isEmpty());
+ testPdf.save(outputFile);
+ testPdf.close();
// compare rendering
TestPDFToImage testPDFToImage = new TestPDFToImage(TestPDFToImage.class.getName());
@@ -305,19 +306,18 @@ public class PDAcroFormFlattenTest {
File file = new File(IN_DIR,targetFile);
- try (PDDocument document = PDDocument.load(file, (String)null))
- {
- String outputPrefix = IN_DIR.getAbsolutePath() + '/' + file.getName() + "-";
- int numPages = document.getNumberOfPages();
+ PDDocument document = PDDocument.load(file, (String) null);
+ String outputPrefix = IN_DIR.getAbsolutePath() + '/' + file.getName() + "-";
+ int numPages = document.getNumberOfPages();
- PDFRenderer renderer = new PDFRenderer(document);
- for (int i = 0; i < numPages; i++)
- {
- String fileName = outputPrefix + (i + 1) + ".png";
- BufferedImage image = renderer.renderImageWithDPI(i, 96); // Windows native DPI
- ImageIO.write(image, "PNG", new File(fileName));
- }
+ PDFRenderer renderer = new PDFRenderer(document);
+ for (int i = 0; i < numPages; i++)
+ {
+ String fileName = outputPrefix + (i + 1) + ".png";
+ BufferedImage image = renderer.renderImageWithDPI(i, 96); // Windows native DPI
+ ImageIO.write(image, "PNG", new File(fileName));
}
+ document.close();
}
/*
@@ -327,17 +327,18 @@ public class PDAcroFormFlattenTest {
{
URL url = new URL(sourceUrl);
- try (InputStream is = url.openStream();
- OutputStream os = new FileOutputStream(new File(IN_DIR,targetFile)))
- {
+ InputStream is = url.openStream();
+ OutputStream os = new FileOutputStream(new File(IN_DIR, targetFile));
- byte[] b = new byte[2048];
- int length;
+ byte[] b = new byte[2048];
+ int length;
- while ((length = is.read(b)) != -1) {
- os.write(b, 0, length);
- }
+ while ((length = is.read(b)) != -1)
+ {
+ os.write(b, 0, length);
}
+ is.close();
+ os.close();
}
/*