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/08/02 18:03:16 UTC
svn commit: r1864262 -
/pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java
Author: tilman
Date: Fri Aug 2 18:03:16 2019
New Revision: 1864262
URL: http://svn.apache.org/viewvc?rev=1864262&view=rev
Log:
PDFBOX-4071: replace tabs, remove trailing spaces
Modified:
pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java
Modified: pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java?rev=1864262&r1=1864261&r2=1864262&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java (original)
+++ pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java Fri Aug 2 18:03:16 2019
@@ -36,179 +36,179 @@ import org.junit.Before;
/**
* Test flatten different forms and compare with rendering.
- *
+ *
* The tests are currently disabled to not run within the CI environment
* as the test results need manual inspection. Enable as needed.
- *
+ *
*/
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");
-
+
+ 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");
+
@Before
public void setUp()
{
- IN_DIR.mkdirs();;
- OUT_DIR.mkdirs();;
+ IN_DIR.mkdirs();
+ OUT_DIR.mkdirs();
}
- /*
- * PDFBOX-142 Filled template.
- */
- // @Test
+ /*
+ * PDFBOX-142 Filled template.
+ */
+ // @Test
public void testFlattenPDFBOX142() throws IOException
{
- String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12742551/Testformular1.pdf";
- String targetFileName = "Testformular1.pdf";
-
- flattenAndCompare(sourceUrl, targetFileName);
- }
-
- /*
- * PDFBOX-563 Filled template.
- */
- // @Test
+ String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12742551/Testformular1.pdf";
+ String targetFileName = "Testformular1.pdf";
+
+ flattenAndCompare(sourceUrl, targetFileName);
+ }
+
+ /*
+ * PDFBOX-563 Filled template.
+ */
+ // @Test
public void testFlattenPDFBOX563() throws IOException
{
- String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12425859/TestFax_56972.pdf";
- String targetFileName = "TestFax_56972.pdf";
-
- flattenAndCompare(sourceUrl, targetFileName);
- }
-
- /*
- * PDFBOX-2469 Empty template.
- */
- // @Test
+ String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12425859/TestFax_56972.pdf";
+ String targetFileName = "TestFax_56972.pdf";
+
+ flattenAndCompare(sourceUrl, targetFileName);
+ }
+
+ /*
+ * PDFBOX-2469 Empty template.
+ */
+ // @Test
public void testFlattenPDFBOX2469Empty() throws IOException
{
- String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12682897/FormI-9-English.pdf";
- String targetFileName = "FormI-9-English.pdf";
-
- flattenAndCompare(sourceUrl, targetFileName);
- }
-
- /*
- * PDFBOX-2469 Filled template.
- */
- // @Test
+ String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12682897/FormI-9-English.pdf";
+ String targetFileName = "FormI-9-English.pdf";
+
+ flattenAndCompare(sourceUrl, targetFileName);
+ }
+
+ /*
+ * PDFBOX-2469 Filled template.
+ */
+ // @Test
public void testFlattenPDFBOX2469Filled() throws IOException
{
- String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12678455/testPDF_acroForm.pdf";
- String targetFileName = "testPDF_acroForm.pdf";
-
- flattenAndCompare(sourceUrl, targetFileName);
- }
-
- /*
- * PDFBOX-2586 Empty template.
- */
- // @Test
+ String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12678455/testPDF_acroForm.pdf";
+ String targetFileName = "testPDF_acroForm.pdf";
+
+ flattenAndCompare(sourceUrl, targetFileName);
+ }
+
+ /*
+ * PDFBOX-2586 Empty template.
+ */
+ // @Test
public void testFlattenPDFBOX2586() throws IOException
{
- String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12689788/test.pdf";
- String targetFileName = "test-2586.pdf";
-
- flattenAndCompare(sourceUrl, targetFileName);
- }
-
- /*
- * PDFBOX-3083 Filled template rotated.
- */
- // @Test
+ String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12689788/test.pdf";
+ String targetFileName = "test-2586.pdf";
+
+ flattenAndCompare(sourceUrl, targetFileName);
+ }
+
+ /*
+ * PDFBOX-3083 Filled template rotated.
+ */
+ // @Test
public void testFlattenPDFBOX3083() throws IOException
{
- String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12770263/mypdf.pdf";
- String targetFileName = "mypdf.pdf";
-
- flattenAndCompare(sourceUrl, targetFileName);
- }
-
- /*
- * PDFBOX-3262 Hidden fields
- */
- // @Test
+ String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12770263/mypdf.pdf";
+ String targetFileName = "mypdf.pdf";
+
+ flattenAndCompare(sourceUrl, targetFileName);
+ }
+
+ /*
+ * PDFBOX-3262 Hidden fields
+ */
+ // @Test
public void testFlattenPDFBOX3262() throws IOException
{
- String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12792007/hidden_fields.pdf";
- String targetFileName = "hidden_fields.pdf";
-
- assertTrue(flattenAndCompare(sourceUrl, targetFileName));
- }
-
- /*
- * PDFBOX-3396 Signed Document 1.
- */
- // @Test
+ String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12792007/hidden_fields.pdf";
+ String targetFileName = "hidden_fields.pdf";
+
+ assertTrue(flattenAndCompare(sourceUrl, targetFileName));
+ }
+
+ /*
+ * PDFBOX-3396 Signed Document 1.
+ */
+ // @Test
public void testFlattenPDFBOX3396_1() throws IOException
{
- String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12816014/Signed-Document-1.pdf";
- String targetFileName = "Signed-Document-1.pdf";
-
- flattenAndCompare(sourceUrl, targetFileName);
+ String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12816014/Signed-Document-1.pdf";
+ String targetFileName = "Signed-Document-1.pdf";
+
+ flattenAndCompare(sourceUrl, targetFileName);
}
- /*
- * PDFBOX-3396 Signed Document 2.
- */
- // @Test
+ /*
+ * PDFBOX-3396 Signed Document 2.
+ */
+ // @Test
public void testFlattenPDFBOX3396_2() throws IOException
{
- String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12816016/Signed-Document-2.pdf";
- String targetFileName = "Signed-Document-2.pdf";
-
- flattenAndCompare(sourceUrl, targetFileName);
- }
-
- /*
- * PDFBOX-3396 Signed Document 3.
- */
- // @Test
+ String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12816016/Signed-Document-2.pdf";
+ String targetFileName = "Signed-Document-2.pdf";
+
+ flattenAndCompare(sourceUrl, targetFileName);
+ }
+
+ /*
+ * PDFBOX-3396 Signed Document 3.
+ */
+ // @Test
public void testFlattenPDFBOX3396_3() throws IOException
{
- String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12821307/Signed-Document-3.pdf";
- String targetFileName = "Signed-Document-3.pdf";
-
- flattenAndCompare(sourceUrl, targetFileName);
- }
-
- /*
- * PDFBOX-3396 Signed Document 4.
- */
- // @Test
+ String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12821307/Signed-Document-3.pdf";
+ String targetFileName = "Signed-Document-3.pdf";
+
+ flattenAndCompare(sourceUrl, targetFileName);
+ }
+
+ /*
+ * PDFBOX-3396 Signed Document 4.
+ */
+ // @Test
public void testFlattenPDFBOX3396_4() throws IOException
{
- String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12821308/Signed-Document-4.pdf";
- String targetFileName = "Signed-Document-4.pdf";
-
- flattenAndCompare(sourceUrl, targetFileName);
- }
-
- /*
- * PDFBOX-3587 Empty template.
- */
- // @Test
+ String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12821308/Signed-Document-4.pdf";
+ String targetFileName = "Signed-Document-4.pdf";
+
+ flattenAndCompare(sourceUrl, targetFileName);
+ }
+
+ /*
+ * PDFBOX-3587 Empty template.
+ */
+ // @Test
public void testFlattenOpenOfficeForm() throws IOException
{
- String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12839977/OpenOfficeForm.pdf";
- String targetFileName = "OpenOfficeForm.pdf";
-
- flattenAndCompare(sourceUrl, targetFileName);
- }
-
- /*
- * PDFBOX-3587 Filled template.
- */
- // @Test
+ String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12839977/OpenOfficeForm.pdf";
+ String targetFileName = "OpenOfficeForm.pdf";
+
+ flattenAndCompare(sourceUrl, targetFileName);
+ }
+
+ /*
+ * PDFBOX-3587 Filled template.
+ */
+ // @Test
public void testFlattenOpenOfficeFormFilled() throws IOException
{
- String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12840280/OpenOfficeForm_filled.pdf";
- String targetFileName = "OpenOfficeForm_filled.pdf";
-
- flattenAndCompare(sourceUrl, targetFileName);
+ String sourceUrl = "https://issues.apache.org/jira/secure/attachment/12840280/OpenOfficeForm_filled.pdf";
+ String targetFileName = "OpenOfficeForm_filled.pdf";
+
+ flattenAndCompare(sourceUrl, targetFileName);
}
-
+
/**
* PDFBOX-4157 Filled template.
@@ -246,24 +246,24 @@ public class PDAcroFormFlattenTest {
flattenAndCompare(sourceUrl, targetFileName);
}
- /*
- * Flatten and compare with generated image samples.
- */
- private static boolean flattenAndCompare(String sourceUrl, String targetFileName) throws IOException
- {
-
- generateSamples(sourceUrl,targetFileName);
-
- File inputFile = new File(IN_DIR, targetFileName);
+ /*
+ * Flatten and compare with generated image samples.
+ */
+ private static boolean flattenAndCompare(String sourceUrl, String targetFileName) throws IOException
+ {
+
+ generateSamples(sourceUrl,targetFileName);
+
+ 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);
- }
+
+ try (PDDocument testPdf = PDDocument.load(inputFile))
+ {
+ testPdf.getDocumentCatalog().getAcroForm().flatten();
+ testPdf.setAllSecurityToBeRemoved(true);
+ assertTrue(testPdf.getDocumentCatalog().getAcroForm().getFields().isEmpty());
+ testPdf.save(outputFile);
+ }
// compare rendering
TestPDFToImage testPDFToImage = new TestPDFToImage(TestPDFToImage.class.getName());
@@ -276,67 +276,67 @@ public class PDAcroFormFlattenTest {
}
else
{
- // cleanup input and output directory for matching files.
- removeAllRenditions(inputFile);
- inputFile.delete();
- outputFile.delete();
+ // cleanup input and output directory for matching files.
+ removeAllRenditions(inputFile);
+ inputFile.delete();
+ outputFile.delete();
}
-
+
return true;
- }
-
- /*
- * Generate the sample images to which the PDF will be compared after flatten.
- */
- private static void generateSamples(String sourceUrl, String targetFile) throws IOException
- {
- getFromUrl(sourceUrl, targetFile);
-
- 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();
-
- 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));
- }
- }
- }
-
- /*
- * Get a PDF from URL and copy to file for processing.
- */
- private static void getFromUrl(String sourceUrl, String targetFile) throws IOException
- {
- URL url = new URL(sourceUrl);
-
- try (InputStream is = url.openStream();
- OutputStream os = new FileOutputStream(new File(IN_DIR,targetFile)))
- {
-
- byte[] b = new byte[2048];
- int length;
-
- while ((length = is.read(b)) != -1) {
- os.write(b, 0, length);
- }
- }
- }
-
- /*
- * Remove renditions for the PDF from the input directory for which there is no
- * corresponding rendition in the output directory.
- * Renditions in the output directory which were identical to the ones in the
- * input directory will have been deleted by the TestPDFToImage utility.
- */
- private static void removeMatchingRenditions(final File inputFile)
- {
+ }
+
+ /*
+ * Generate the sample images to which the PDF will be compared after flatten.
+ */
+ private static void generateSamples(String sourceUrl, String targetFile) throws IOException
+ {
+ getFromUrl(sourceUrl, targetFile);
+
+ 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();
+
+ 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));
+ }
+ }
+ }
+
+ /*
+ * Get a PDF from URL and copy to file for processing.
+ */
+ private static void getFromUrl(String sourceUrl, String targetFile) throws IOException
+ {
+ URL url = new URL(sourceUrl);
+
+ try (InputStream is = url.openStream();
+ OutputStream os = new FileOutputStream(new File(IN_DIR,targetFile)))
+ {
+
+ byte[] b = new byte[2048];
+ int length;
+
+ while ((length = is.read(b)) != -1) {
+ os.write(b, 0, length);
+ }
+ }
+ }
+
+ /*
+ * Remove renditions for the PDF from the input directory for which there is no
+ * corresponding rendition in the output directory.
+ * Renditions in the output directory which were identical to the ones in the
+ * input directory will have been deleted by the TestPDFToImage utility.
+ */
+ private static void removeMatchingRenditions(final File inputFile)
+ {
File[] testFiles = inputFile.getParentFile().listFiles(new FilenameFilter()
{
@Override
@@ -345,22 +345,22 @@ public class PDAcroFormFlattenTest {
return (name.startsWith(inputFile.getName()) && name.toLowerCase().endsWith(".png"));
}
});
-
+
for (File testFile : testFiles)
{
- if (! new File(OUT_DIR, testFile.getName()).exists())
- {
- testFile.delete();
- }
+ if (! new File(OUT_DIR, testFile.getName()).exists())
+ {
+ testFile.delete();
+ }
}
- }
-
- /*
- * Remove renditions for the PDF from the input directory.
- * The output directory will have been cleaned by the TestPDFToImage utility.
- */
- private static void removeAllRenditions(final File inputFile)
- {
+ }
+
+ /*
+ * Remove renditions for the PDF from the input directory.
+ * The output directory will have been cleaned by the TestPDFToImage utility.
+ */
+ private static void removeAllRenditions(final File inputFile)
+ {
File[] testFiles = inputFile.getParentFile().listFiles(new FilenameFilter()
{
@Override
@@ -369,10 +369,10 @@ public class PDAcroFormFlattenTest {
return (name.startsWith(inputFile.getName()) && name.toLowerCase().endsWith(".png"));
}
});
-
+
for (File testFile : testFiles)
{
- testFile.delete();
+ testFile.delete();
}
- }
+ }
}