diff --git a/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java b/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java index f7ada096e1d..54a80994dbc 100644 --- a/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java +++ b/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java @@ -113,6 +113,7 @@ import org.apache.pdfbox.filter.FilterFactory; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.common.PDPageLabels; import org.apache.pdfbox.pdmodel.encryption.AccessPermission; import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException; @@ -1242,7 +1243,7 @@ private void readPDFFile(final File file, String password) throws IOException @Override PDDocument open() throws IOException { - return PDDocument.load(file, password); + return PDFParser.load(file, password); } }; document = documentOpener.parse(); @@ -1280,7 +1281,7 @@ private void readPDFurl(final String urlString, String password) throws IOExcept @Override PDDocument open() throws IOException { - return PDDocument.load(new URL(urlString).openStream(), password); + return PDFParser.load(new URL(urlString).openStream(), password); } }; document = documentOpener.parse(); diff --git a/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PDFTreeModel.java b/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PDFTreeModel.java index 65fc64cef12..29496184416 100644 --- a/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PDFTreeModel.java +++ b/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PDFTreeModel.java @@ -134,10 +134,6 @@ else if( parent instanceof ArrayEntry ) { retval = getChild( ((ArrayEntry)parent).getValue(), index ); } - else if( parent instanceof COSDocument ) - { - retval = ((COSDocument)parent).getObjects().get( index ); - } else if( parent instanceof DocumentEntry) { retval = ((DocumentEntry)parent).getPage(index); @@ -186,10 +182,6 @@ else if( parent instanceof ArrayEntry ) { retval = getChildCount(((ArrayEntry) parent).getValue()); } - else if( parent instanceof COSDocument ) - { - retval = ((COSDocument)parent).getObjects().size(); - } else if( parent instanceof DocumentEntry ) { retval = ((DocumentEntry)parent).getPageCount(); @@ -256,10 +248,6 @@ else if( parent instanceof ArrayEntry ) { retval = getIndexOfChild( ((ArrayEntry)parent).getValue(), child ); } - else if( parent instanceof COSDocument ) - { - retval = ((COSDocument)parent).getObjects().indexOf( child ); - } else if( parent instanceof DocumentEntry ) { retval = ((DocumentEntry)parent).indexOf( (PageEntry)child ); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/AddBorderToField.java b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/AddBorderToField.java index ed4d14277d7..e1994ea6b11 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/AddBorderToField.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/AddBorderToField.java @@ -22,6 +22,7 @@ import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.graphics.color.PDColor; import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget; @@ -46,7 +47,7 @@ private AddBorderToField() public static void main(String[] args) throws IOException { // Load the PDF document created by SimpleForm.java - try (PDDocument document = PDDocument.load(new File("target/SimpleForm.pdf"))) + try (PDDocument document = PDFParser.load(new File("target/SimpleForm.pdf"))) { PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm(); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java index db95b943f63..064f0e23257 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateCheckBox.java @@ -20,8 +20,8 @@ import java.io.IOException; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; -import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.common.PDRectangle; diff --git a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateRadioButtons.java b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateRadioButtons.java index ac39ffb2e26..70714409ec6 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateRadioButtons.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/CreateRadioButtons.java @@ -22,8 +22,8 @@ import java.util.List; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; -import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.common.PDRectangle; diff --git a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/DetermineTextFitsField.java b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/DetermineTextFitsField.java index e9055f49e47..7a489e760ec 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/DetermineTextFitsField.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/DetermineTextFitsField.java @@ -22,6 +22,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.font.PDFont; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget; @@ -43,7 +44,7 @@ private DetermineTextFitsField() public static void main(String[] args) throws IOException { - try (PDDocument document = PDDocument.load(new File("target/SimpleForm.pdf"))) + try (PDDocument document = PDFParser.load(new File("target/SimpleForm.pdf"))) { PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm(); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/FieldTriggers.java b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/FieldTriggers.java index 86cbdeb84ba..213889c56fa 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/FieldTriggers.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/FieldTriggers.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript; import org.apache.pdfbox.pdmodel.interactive.action.PDAnnotationAdditionalActions; import org.apache.pdfbox.pdmodel.interactive.action.PDFormFieldAdditionalActions; @@ -45,7 +46,7 @@ private FieldTriggers() public static void main(String[] args) throws IOException { // Load the PDF document created by SimpleForm.java - try (PDDocument document = PDDocument.load(new File("target/SimpleForm.pdf"))) + try (PDDocument document = PDFParser.load(new File("target/SimpleForm.pdf"))) { PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm(); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/FillFormField.java b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/FillFormField.java index d095bddda5c..1aa2d83e565 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/FillFormField.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/FillFormField.java @@ -20,6 +20,7 @@ import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; import org.apache.pdfbox.pdmodel.interactive.form.PDTextField; @@ -37,7 +38,7 @@ public static void main(String[] args) throws IOException { String formTemplate = "src/main/resources/org/apache/pdfbox/examples/interactive/form/FillFormField.pdf"; - try (PDDocument pdfDocument = PDDocument.load(new File(formTemplate))) + try (PDDocument pdfDocument = PDFParser.load(new File(formTemplate))) { // get the document catalog PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm(); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/PrintFields.java b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/PrintFields.java index 319122c1f34..87c162e73ac 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/PrintFields.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/PrintFields.java @@ -19,7 +19,9 @@ import java.io.File; import java.io.IOException; import java.util.List; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; import org.apache.pdfbox.pdmodel.interactive.form.PDField; @@ -106,7 +108,7 @@ public static void main(String[] args) throws IOException } else { - pdf = PDDocument.load(new File(args[0])); + pdf = PDFParser.load(new File(args[0])); PrintFields exporter = new PrintFields(); exporter.printFields(pdf); } diff --git a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/SetField.java b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/SetField.java index 371f62febd5..e38d03e53b5 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/SetField.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/SetField.java @@ -18,7 +18,9 @@ import java.io.File; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; import org.apache.pdfbox.pdmodel.interactive.form.PDCheckBox; @@ -106,7 +108,7 @@ private void setField(String[] args) throws IOException else { SetField example = new SetField(); - pdf = PDDocument.load(new File(args[0])); + pdf = PDFParser.load(new File(args[0])); example.setField(pdf, args[1], args[2]); pdf.save(args[0]); } diff --git a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/UpdateFieldOnDocumentOpen.java b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/UpdateFieldOnDocumentOpen.java index 2f8c9feff12..db58a2c994d 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/UpdateFieldOnDocumentOpen.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/interactive/form/UpdateFieldOnDocumentOpen.java @@ -19,7 +19,9 @@ import java.io.File; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript; /** @@ -40,7 +42,7 @@ private UpdateFieldOnDocumentOpen() public static void main(String[] args) throws IOException { // Load the PDF document created by SimpleForm.java - try (PDDocument document = PDDocument.load(new File("target/SimpleForm.pdf"))) + try (PDDocument document = PDFParser.load(new File("target/SimpleForm.pdf"))) { // Note that the JavaScript will depend on the reader application. // The classes and methods available to Adobe Reader and Adobe Acrobat diff --git a/examples/src/main/java/org/apache/pdfbox/examples/lucene/LucenePDFDocument.java b/examples/src/main/java/org/apache/pdfbox/examples/lucene/LucenePDFDocument.java index 51f550fcdf7..974e43f20ac 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/lucene/LucenePDFDocument.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/lucene/LucenePDFDocument.java @@ -35,6 +35,7 @@ import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexOptions; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocumentInformation; import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException; @@ -352,7 +353,7 @@ public static Document getDocument(URL url) throws IOException */ private void addContent(Document document, InputStream is, String documentLocation) throws IOException { - try (PDDocument pdfDocument = PDDocument.load(is)) + try (PDDocument pdfDocument = PDFParser.load(is)) { // create a writer where to append the text content. StringWriter writer = new StringWriter(); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddAnnotations.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddAnnotations.java index 0444f42b9f3..43512419a57 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddAnnotations.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddAnnotations.java @@ -19,7 +19,6 @@ import java.io.IOException; import java.util.List; import org.apache.pdfbox.cos.COSName; - import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddImageToPDF.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddImageToPDF.java index 5265e3cba13..718cbbbe070 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddImageToPDF.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddImageToPDF.java @@ -18,7 +18,9 @@ import java.io.File; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream.AppendMode; @@ -45,7 +47,7 @@ public class AddImageToPDF public void createPDFFromImage( String inputFile, String imagePath, String outputFile ) throws IOException { - try (PDDocument doc = PDDocument.load(new File(inputFile))) + try (PDDocument doc = PDFParser.load(new File(inputFile))) { //we will add the image to the first page. PDPage page = doc.getPage(0); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddJavascript.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddJavascript.java index 8621848c23e..9d8f0fc5f8d 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddJavascript.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddJavascript.java @@ -17,6 +17,7 @@ package org.apache.pdfbox.examples.pdmodel; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript; import java.io.File; @@ -49,7 +50,7 @@ public static void main( String[] args ) throws IOException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { PDActionJavaScript javascript = new PDActionJavaScript( "app.alert( {cMsg: 'PDFBox rocks!', nIcon: 3, nType: 0, cTitle: 'PDFBox Javascript example' } );"); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java index b26609c6aa1..3bee94820b8 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.PDPageContentStream; @@ -56,7 +57,7 @@ public AddMessageToEachPage() */ public void doIt( String file, String message, String outfile ) throws IOException { - try (PDDocument doc = PDDocument.load(new File(file))) + try (PDDocument doc = PDFParser.load(new File(file))) { PDFont font = PDType1Font.HELVETICA_BOLD; float fontSize = 36.0f; diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMetadataFromDocInfo.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMetadataFromDocInfo.java index 319948b4385..3ba16b6711c 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMetadataFromDocInfo.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMetadataFromDocInfo.java @@ -17,6 +17,7 @@ package org.apache.pdfbox.examples.pdmodel; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDDocumentInformation; import org.apache.pdfbox.pdmodel.common.PDMetadata; @@ -61,7 +62,7 @@ public static void main( String[] args ) throws IOException, TransformerExceptio } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { if (document.isEncrypted()) { diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateBookmarks.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateBookmarks.java index 89e7b4296d3..8bbd5f4046a 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateBookmarks.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateBookmarks.java @@ -20,6 +20,7 @@ import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PageMode; import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination; @@ -55,7 +56,7 @@ public static void main( String[] args ) throws IOException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { if (document.isEncrypted()) { diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateGradientShadingPDF.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateGradientShadingPDF.java index a036e30befa..bc817737839 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateGradientShadingPDF.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateGradientShadingPDF.java @@ -27,6 +27,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSNumber; import org.apache.pdfbox.cos.COSStream; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.function.PDFunctionType2; @@ -57,7 +58,6 @@ public class CreateGradientShadingPDF */ public void create(String file) throws IOException { - try (PDDocument document = new PDDocument()) { PDPage page = new PDPage(); @@ -191,7 +191,7 @@ public void create(String file) throws IOException document.save(file); } - try (PDDocument document = PDDocument.load(new File(file))) + try (PDDocument document = PDFParser.load(new File(file))) { // render the PDF and save it into a PNG file BufferedImage bim = new PDFRenderer(document).renderImageWithDPI(0, 100); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePDFA.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePDFA.java index c4a1c77134e..6ffe37a6478 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePDFA.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePDFA.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; import javax.xml.transform.TransformerException; + import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFonts.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFonts.java index 97335136020..580160c1ecd 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFonts.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFonts.java @@ -19,6 +19,7 @@ import java.io.File; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractEmbeddedFiles.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractEmbeddedFiles.java index 76a531bf4e2..d045799a87e 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractEmbeddedFiles.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractEmbeddedFiles.java @@ -22,7 +22,9 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary; import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode; import org.apache.pdfbox.pdmodel.PDPage; @@ -60,7 +62,7 @@ public static void main( String[] args ) throws IOException File pdfFile = new File(args[0]); String filePath = pdfFile.getParent() + System.getProperty("file.separator"); - try (PDDocument document = PDDocument.load(pdfFile)) + try (PDDocument document = PDFParser.load(pdfFile)) { PDDocumentNameDictionary namesDictionary = new PDDocumentNameDictionary(document.getDocumentCatalog()); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractMetadata.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractMetadata.java index 9edb5c938cb..5ce2605ac99 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractMetadata.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractMetadata.java @@ -17,6 +17,7 @@ package org.apache.pdfbox.examples.pdmodel; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDDocumentInformation; import org.apache.pdfbox.pdmodel.common.PDMetadata; @@ -62,7 +63,7 @@ public static void main(String[] args) throws IOException, XmpParsingException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { PDDocumentCatalog catalog = document.getDocumentCatalog(); PDMetadata meta = catalog.getMetadata(); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractTTFFonts.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractTTFFonts.java index e37bd293460..520a987346c 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractTTFFonts.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractTTFFonts.java @@ -25,6 +25,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.common.PDStream; @@ -121,7 +122,7 @@ private void extractFonts(String[] args) throws IOException { prefix = pdfFile.substring(0, pdfFile.length() - 4); } - try (PDDocument document = PDDocument.load(new File(pdfFile), password)) + try (PDDocument document = PDFParser.load(new File(pdfFile), password)) { for (PDPage page : document.getPages()) { diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/GoToSecondBookmarkOnOpen.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/GoToSecondBookmarkOnOpen.java index 28fdcdcc937..43163c9bba6 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/GoToSecondBookmarkOnOpen.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/GoToSecondBookmarkOnOpen.java @@ -17,6 +17,7 @@ package org.apache.pdfbox.examples.pdmodel; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.interactive.action.PDActionGoTo; import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination; import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline; @@ -52,7 +53,7 @@ public static void main( String[] args ) throws IOException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { if( document.isEncrypted() ) { diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java index d5daa86983f..f7ebc8e568a 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java @@ -19,6 +19,7 @@ import java.io.File; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1.java index 3e18c94d001..77796a449bc 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1.java @@ -19,6 +19,7 @@ import java.io.FileInputStream; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ImageToPDF.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ImageToPDF.java index 6c37b4b3120..b26781c4a56 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ImageToPDF.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ImageToPDF.java @@ -17,6 +17,7 @@ package org.apache.pdfbox.examples.pdmodel; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintBookmarks.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintBookmarks.java index 957f7f20213..d7cb6dd4c56 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintBookmarks.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintBookmarks.java @@ -20,6 +20,7 @@ import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.interactive.action.PDActionGoTo; import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDNamedDestination; import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination; @@ -50,7 +51,7 @@ public static void main( String[] args ) throws IOException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { PrintBookmarks meta = new PrintBookmarks(); PDDocumentOutline outline = document.getDocumentCatalog().getDocumentOutline(); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintDocumentMetaData.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintDocumentMetaData.java index 12523e1f334..bbf9be49990 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintDocumentMetaData.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintDocumentMetaData.java @@ -17,6 +17,7 @@ package org.apache.pdfbox.examples.pdmodel; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDDocumentInformation; import org.apache.pdfbox.pdmodel.common.PDMetadata; @@ -50,7 +51,7 @@ public static void main( String[] args ) throws IOException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { PrintDocumentMetaData meta = new PrintDocumentMetaData(); meta.printMetadata( document ); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintURLs.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintURLs.java index 407309c53c6..b404fcd8aea 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintURLs.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintURLs.java @@ -24,6 +24,7 @@ import java.util.List; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.interactive.action.PDAction; @@ -67,7 +68,7 @@ public static void main(String[] args) throws IOException } else { - doc = PDDocument.load( new File(args[0]) ); + doc = PDFParser.load(new File(args[0])); int pageNum = 0; for( PDPage page : doc.getPages() ) { diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/RemoveFirstPage.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/RemoveFirstPage.java index a4fbb54cd3d..811cae06d4e 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/RemoveFirstPage.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/RemoveFirstPage.java @@ -17,6 +17,7 @@ package org.apache.pdfbox.examples.pdmodel; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import java.io.File; import java.io.IOException; @@ -48,7 +49,7 @@ public static void main( String[] args ) throws IOException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { if( document.isEncrypted() ) { diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ReplaceURLs.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ReplaceURLs.java index 682cae7e869..33e9d067440 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ReplaceURLs.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ReplaceURLs.java @@ -21,6 +21,7 @@ import java.util.List; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.interactive.action.PDAction; import org.apache.pdfbox.pdmodel.interactive.action.PDActionURI; @@ -66,7 +67,7 @@ public static void main(String[] args) throws IOException } else { - doc = PDDocument.load( new File(args[0]) ); + doc = PDFParser.load(new File(args[0])); int pageNum = 0; for( PDPage page : doc.getPages() ) { diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStamp.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStamp.java index 6b0aede8f4b..e09e2ddabc4 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStamp.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStamp.java @@ -17,6 +17,7 @@ package org.apache.pdfbox.examples.pdmodel; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; @@ -53,7 +54,7 @@ public static void main( String[] args ) throws IOException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { if( document.isEncrypted() ) { diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStampWithImage.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStampWithImage.java index 7fc369af6bc..0203580cff7 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStampWithImage.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/RubberStampWithImage.java @@ -26,6 +26,7 @@ import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.common.PDRectangle; @@ -63,7 +64,7 @@ public void doIt( String[] args ) throws IOException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { if( document.isEncrypted() ) { diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ShowColorBoxes.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ShowColorBoxes.java index 93fc04f3227..f52a847795c 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ShowColorBoxes.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ShowColorBoxes.java @@ -18,6 +18,7 @@ import java.awt.Color; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; diff --git a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/SuperimposePage.java b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/SuperimposePage.java index c3c3ef16589..5bc0bc572f9 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/SuperimposePage.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/SuperimposePage.java @@ -18,13 +18,15 @@ import java.io.File; import java.io.IOException; -import org.apache.pdfbox.pdmodel.PDDocument; + import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.font.PDType1Font; import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject; import org.apache.pdfbox.multipdf.LayerUtility; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.util.Matrix; /** @@ -48,7 +50,7 @@ public static void main(String[] args) throws IOException String sourcePath = args[0]; String destPath = args[1]; - try (PDDocument sourceDoc = PDDocument.load(new File(sourcePath))) + try (PDDocument sourceDoc = PDFParser.load(new File(sourcePath))) { int sourcePage = 1; diff --git a/examples/src/main/java/org/apache/pdfbox/examples/printing/Printing.java b/examples/src/main/java/org/apache/pdfbox/examples/printing/Printing.java index 8b3aafefd92..e97281c3a69 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/printing/Printing.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/printing/Printing.java @@ -28,7 +28,9 @@ import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.standard.PageRanges; import javax.print.attribute.standard.Sides; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.interactive.viewerpreferences.PDViewerPreferences; import org.apache.pdfbox.printing.PDFPageable; import org.apache.pdfbox.printing.PDFPrintable; @@ -54,7 +56,7 @@ public static void main(String[] args) throws PrinterException, IOException } String filename = args[0]; - try (PDDocument document = PDDocument.load(new File(filename))) + try (PDDocument document = PDFParser.load(new File(filename))) { // choose your printing method: print(document); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/rendering/CustomGraphicsStreamEngine.java b/examples/src/main/java/org/apache/pdfbox/examples/rendering/CustomGraphicsStreamEngine.java index 19a5ffbccbe..8d26f3cee35 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/rendering/CustomGraphicsStreamEngine.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/rendering/CustomGraphicsStreamEngine.java @@ -25,6 +25,7 @@ import org.apache.pdfbox.cos.COSArray; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.font.PDFont; import org.apache.pdfbox.pdmodel.graphics.image.PDImage; @@ -57,7 +58,7 @@ public static void main(String[] args) throws IOException File file = new File("src/main/resources/org/apache/pdfbox/examples/rendering/", "custom-render-demo.pdf"); - try (PDDocument doc = PDDocument.load(file)) + try (PDDocument doc = PDFParser.load(file)) { PDPage page = doc.getPage(0); CustomGraphicsStreamEngine engine = new CustomGraphicsStreamEngine(page); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/rendering/CustomPageDrawer.java b/examples/src/main/java/org/apache/pdfbox/examples/rendering/CustomPageDrawer.java index ed2633705d0..b472b378e72 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/rendering/CustomPageDrawer.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/rendering/CustomPageDrawer.java @@ -31,6 +31,7 @@ import javax.imageio.ImageIO; import org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.font.PDFont; import org.apache.pdfbox.pdmodel.graphics.color.PDColor; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; @@ -56,7 +57,7 @@ public static void main(String[] args) throws IOException File file = new File("src/main/resources/org/apache/pdfbox/examples/rendering/", "custom-render-demo.pdf"); - try (PDDocument doc = PDDocument.load(file)) + try (PDDocument doc = PDFParser.load(file)) { PDFRenderer renderer = new MyPDFRenderer(doc); BufferedImage image = renderer.renderImage(0); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmbeddedTimeStamp.java b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmbeddedTimeStamp.java index 8ecf412597c..28c099c5cd7 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmbeddedTimeStamp.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateEmbeddedTimeStamp.java @@ -31,6 +31,7 @@ import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.io.IOUtils; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature; import org.apache.pdfbox.util.Hex; @@ -88,7 +89,7 @@ public void embedTimeStamp(File inFile, File outFile) throws IOException } // sign - try (PDDocument doc = PDDocument.load(inFile)) + try (PDDocument doc = PDFParser.load(inFile)) { document = doc; processTimeStamping(outFile, inFile.getAbsolutePath()); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java index 5f0b18c43b5..bd7153def0f 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java @@ -30,6 +30,7 @@ import java.security.cert.CertificateException; import java.util.Calendar; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.ExternalSigningSupport; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature; @@ -105,7 +106,7 @@ public void signDetached(File inFile, File outFile, String tsaUrl) throws IOExce // sign try (FileOutputStream fos = new FileOutputStream(outFile); - PDDocument doc = PDDocument.load(inFile)) + PDDocument doc = PDFParser.load(inFile)) { signDetached(doc, fos); } diff --git a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignedTimeStamp.java b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignedTimeStamp.java index e127b208d6c..8c0e64cec14 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignedTimeStamp.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignedTimeStamp.java @@ -27,6 +27,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.cos.COSName; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface; @@ -83,7 +84,7 @@ public void signDetached(File inFile, File outFile) throws IOException } // sign - try (PDDocument doc = PDDocument.load(inFile); + try (PDDocument doc = PDFParser.load(inFile); FileOutputStream fos = new FileOutputStream(outFile)) { signDetached(doc, fos); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java index d3e70fca094..99c5eeff751 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java @@ -31,6 +31,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.io.IOUtils; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.ExternalSigningSupport; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature; @@ -190,7 +191,7 @@ public void signPDF(File inputFile, File signedFile, String tsaUrl, String signa // creating output document and prepare the IO streams. try (FileOutputStream fos = new FileOutputStream(signedFile); - PDDocument doc = PDDocument.load(inputFile)) + PDDocument doc = PDFParser.load(inputFile)) { int accessPermissions = SigUtils.getMDPPermission(doc); if (accessPermissions == 1) diff --git a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature2.java b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature2.java index a5592fe515b..7d89fdd6829 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature2.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature2.java @@ -38,6 +38,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.io.IOUtils; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; @@ -163,7 +164,7 @@ public void signPDF(File inputFile, File signedFile, Rectangle2D humanRect, Stri // creating output document and prepare the IO streams. try (FileOutputStream fos = new FileOutputStream(signedFile); - PDDocument doc = PDDocument.load(inputFile)) + PDDocument doc = PDFParser.load(inputFile)) { int accessPermissions = SigUtils.getMDPPermission(doc); if (accessPermissions == 1) diff --git a/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java b/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java index 107248653b0..51d32d20b1f 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/signature/ShowSignature.java @@ -141,9 +141,7 @@ private void showSignature(String[] args) throws IOException, // with IOUtils.toByteArray() and pass a RandomAccessBuffer() object to the // PDFParser constructor. PDFParser parser = new PDFParser(raFile, password); - parser.setLenient(false); - parser.parse(); - try (PDDocument document = parser.getPDDocument()) + try (PDDocument document = parser.parse(false)) { for (PDSignature sig : document.getSignatureDictionaries()) { diff --git a/examples/src/main/java/org/apache/pdfbox/examples/signature/validation/AddValidationInformation.java b/examples/src/main/java/org/apache/pdfbox/examples/signature/validation/AddValidationInformation.java index 471b02e48db..21155c415ee 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/signature/validation/AddValidationInformation.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/signature/validation/AddValidationInformation.java @@ -47,6 +47,7 @@ import org.apache.pdfbox.examples.signature.cert.OcspHelper; import org.apache.pdfbox.examples.signature.cert.RevokedCertificateException; import org.apache.pdfbox.examples.signature.validation.CertInformationCollector.CertSignatureInformation; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.encryption.SecurityProvider; @@ -100,7 +101,7 @@ public void validateSignature(File inFile, File outFile) throws IOException throw new FileNotFoundException("Document for signing does not exist"); } - try (PDDocument doc = PDDocument.load(inFile); + try (PDDocument doc = PDFParser.load(inFile); FileOutputStream fos = new FileOutputStream(outFile)) { document = doc; diff --git a/examples/src/main/java/org/apache/pdfbox/examples/signature/validation/CertInformationHelper.java b/examples/src/main/java/org/apache/pdfbox/examples/signature/validation/CertInformationHelper.java index 112708a7210..73a7d7fb9eb 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/signature/validation/CertInformationHelper.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/signature/validation/CertInformationHelper.java @@ -27,6 +27,7 @@ import org.apache.pdfbox.util.Hex; import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1OctetString; +import org.bouncycastle.asn1.ASN1OctetString; import org.bouncycastle.asn1.ASN1Sequence; import org.bouncycastle.asn1.ASN1TaggedObject; import org.bouncycastle.asn1.x509.GeneralName; @@ -163,4 +164,4 @@ else if (taggedObject.getObject() instanceof ASN1Sequence) // else happens with http://blogs.adobe.com/security/SampleSignedPDFDocument.pdf return null; } -} \ No newline at end of file +} diff --git a/examples/src/main/java/org/apache/pdfbox/examples/util/AddWatermarkText.java b/examples/src/main/java/org/apache/pdfbox/examples/util/AddWatermarkText.java index 3d8a7d15701..d27692abe45 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/util/AddWatermarkText.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/util/AddWatermarkText.java @@ -19,7 +19,9 @@ import java.awt.Color; import java.io.File; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.font.PDFont; @@ -51,7 +53,7 @@ public static void main(String[] args) throws IOException File dstFile = new File(args[1]); String text = args[2]; - try (PDDocument doc = PDDocument.load(srcFile)) + try (PDDocument doc = PDFParser.load(srcFile)) { for (PDPage page : doc.getPages()) { diff --git a/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java b/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java index 8593c2c83ca..88addc97b84 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/util/DrawPrintTextLocations.java @@ -33,6 +33,7 @@ import javax.imageio.ImageIO; import org.apache.fontbox.util.BoundingBox; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.font.PDCIDFontType2; @@ -93,7 +94,7 @@ public static void main(String[] args) throws IOException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { DrawPrintTextLocations stripper = new DrawPrintTextLocations(document, args[0]); stripper.setSortByPosition(true); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/util/ExtractTextByArea.java b/examples/src/main/java/org/apache/pdfbox/examples/util/ExtractTextByArea.java index 7369bef060c..acaf18d0b55 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/util/ExtractTextByArea.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/util/ExtractTextByArea.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.text.PDFTextStripperByArea; @@ -52,7 +53,7 @@ public static void main( String[] args ) throws IOException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { PDFTextStripperByArea stripper = new PDFTextStripperByArea(); stripper.setSortByPosition( true ); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/util/ExtractTextSimple.java b/examples/src/main/java/org/apache/pdfbox/examples/util/ExtractTextSimple.java index 78a77de7679..d79f7ba9469 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/util/ExtractTextSimple.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/util/ExtractTextSimple.java @@ -18,7 +18,9 @@ import java.io.File; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.encryption.AccessPermission; import org.apache.pdfbox.text.PDFTextStripper; @@ -50,7 +52,7 @@ public static void main(String[] args) throws IOException usage(); } - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { AccessPermission ap = document.getCurrentAccessPermission(); if (!ap.canExtractContent()) diff --git a/examples/src/main/java/org/apache/pdfbox/examples/util/PDFHighlighter.java b/examples/src/main/java/org/apache/pdfbox/examples/util/PDFHighlighter.java index fe5001e2ecd..ac6811a09ec 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/util/PDFHighlighter.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/util/PDFHighlighter.java @@ -27,6 +27,7 @@ import java.util.regex.Pattern; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.text.PDFTextStripper; @@ -147,7 +148,7 @@ public static void main(String[] args) throws IOException } String[] highlightStrings = new String[args.length - 1]; System.arraycopy(args, 1, highlightStrings, 0, highlightStrings.length); - try (PDDocument doc = PDDocument.load(new File(args[0]))) + try (PDDocument doc = PDFParser.load(new File(args[0]))) { xmlExtractor.generateXMLHighlight( doc, diff --git a/examples/src/main/java/org/apache/pdfbox/examples/util/PrintImageLocations.java b/examples/src/main/java/org/apache/pdfbox/examples/util/PrintImageLocations.java index 4a520ba16e6..ad6dea66f87 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/util/PrintImageLocations.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/util/PrintImageLocations.java @@ -19,6 +19,7 @@ import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.graphics.PDXObject; import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject; @@ -76,7 +77,7 @@ public static void main( String[] args ) throws IOException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { PrintImageLocations printer = new PrintImageLocations(); int pageNum = 0; diff --git a/examples/src/main/java/org/apache/pdfbox/examples/util/PrintTextColors.java b/examples/src/main/java/org/apache/pdfbox/examples/util/PrintTextColors.java index e7ec6a2f628..fa177268b65 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/util/PrintTextColors.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/util/PrintTextColors.java @@ -34,6 +34,7 @@ import org.apache.pdfbox.contentstream.operator.color.SetStrokingDeviceGrayColor; import org.apache.pdfbox.contentstream.operator.color.SetStrokingDeviceRGBColor; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.graphics.color.PDColor; import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode; import org.apache.pdfbox.text.PDFTextStripper; @@ -87,7 +88,7 @@ public static void main(String[] args) throws IOException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { PDFTextStripper stripper = new PrintTextColors(); stripper.setSortByPosition(true); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/util/PrintTextLocations.java b/examples/src/main/java/org/apache/pdfbox/examples/util/PrintTextLocations.java index a1cd9be7455..08c4a5b181c 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/util/PrintTextLocations.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/util/PrintTextLocations.java @@ -22,7 +22,9 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.util.List; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.text.PDFTextStripper; import org.apache.pdfbox.text.TextPosition; @@ -57,7 +59,7 @@ public static void main( String[] args ) throws IOException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { PDFTextStripper stripper = new PrintTextLocations(); stripper.setSortByPosition( true ); diff --git a/examples/src/main/java/org/apache/pdfbox/examples/util/RemoveAllText.java b/examples/src/main/java/org/apache/pdfbox/examples/util/RemoveAllText.java index dcb6be20dad..c9a657a86d5 100644 --- a/examples/src/main/java/org/apache/pdfbox/examples/util/RemoveAllText.java +++ b/examples/src/main/java/org/apache/pdfbox/examples/util/RemoveAllText.java @@ -26,6 +26,7 @@ import org.apache.pdfbox.contentstream.operator.Operator; import org.apache.pdfbox.contentstream.operator.OperatorName; import org.apache.pdfbox.cos.COSName; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdfparser.PDFStreamParser; import org.apache.pdfbox.pdfwriter.ContentStreamWriter; import org.apache.pdfbox.pdmodel.PDDocument; @@ -67,7 +68,7 @@ public static void main(String[] args) throws IOException } else { - try (PDDocument document = PDDocument.load(new File(args[0]))) + try (PDDocument document = PDFParser.load(new File(args[0]))) { if (document.isEncrypted()) { diff --git a/examples/src/test/java/org/apache/pdfbox/examples/pdfa/CreatePDFATest.java b/examples/src/test/java/org/apache/pdfbox/examples/pdfa/CreatePDFATest.java index 2adaf0dc951..588fe88e929 100644 --- a/examples/src/test/java/org/apache/pdfbox/examples/pdfa/CreatePDFATest.java +++ b/examples/src/test/java/org/apache/pdfbox/examples/pdfa/CreatePDFATest.java @@ -23,9 +23,9 @@ import org.apache.pdfbox.examples.pdmodel.CreatePDFA; import org.apache.pdfbox.examples.signature.CreateSignature; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.common.PDMetadata; -import org.apache.pdfbox.preflight.PreflightDocument; import org.apache.pdfbox.preflight.ValidationResult; import org.apache.pdfbox.preflight.ValidationResult.ValidationError; import org.apache.pdfbox.preflight.parser.PreflightParser; @@ -69,21 +69,15 @@ public void testCreatePDFA() throws Exception signing.signDetached(new File(pdfaFilename), new File(signedPdfaFilename)); // Verify that it is PDF/A-1b - PreflightParser preflightParser = new PreflightParser(new File(signedPdfaFilename)); - preflightParser.parse(); - try (PreflightDocument preflightDocument = preflightParser.getPreflightDocument()) + ValidationResult result = PreflightParser.validate(new File(signedPdfaFilename)); + for (ValidationError ve : result.getErrorsList()) { - preflightDocument.validate(); - ValidationResult result = preflightDocument.getResult(); - for (ValidationError ve : result.getErrorsList()) - { - System.err.println(ve.getErrorCode() + ": " + ve.getDetails()); - } - assertTrue("PDF file created with CreatePDFA is not valid PDF/A-1b", result.isValid()); + System.err.println(ve.getErrorCode() + ": " + ve.getDetails()); } + assertTrue("PDF file created with CreatePDFA is not valid PDF/A-1b", result.isValid()); // check the XMP metadata - try (PDDocument document = PDDocument.load(new File(pdfaFilename))) + try (PDDocument document = PDFParser.load(new File(pdfaFilename))) { PDDocumentCatalog catalog = document.getDocumentCatalog(); PDMetadata meta = catalog.getMetadata(); diff --git a/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java b/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java index 19226af73ce..eed252fbd92 100644 --- a/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java +++ b/examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java @@ -45,6 +45,7 @@ import org.apache.pdfbox.examples.signature.CreateVisibleSignature; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary; @@ -91,7 +92,7 @@ public class TestCreateSignature * using externally signing scenario ({@code true}) or SignatureInterface ({@code false}). */ @Parameterized.Parameters - public static Collection signingTypes() + public static Collection signingTypes() { return Arrays.asList(false, true); } @@ -262,7 +263,7 @@ public void testPDFBox3978() throws IOException, NoSuchAlgorithmException, KeySt checkSignature(new File(filename), new File(filenameSigned1)); - try (PDDocument doc1 = PDDocument.load(new File(filenameSigned1))) + try (PDDocument doc1 = PDFParser.load(new File(filenameSigned1))) { List signatureDictionaries = doc1.getSignatureDictionaries(); Assert.assertEquals(1, signatureDictionaries.size()); @@ -280,7 +281,7 @@ public void testPDFBox3978() throws IOException, NoSuchAlgorithmException, KeySt checkSignature(new File(filenameSigned1), new File(filenameSigned2)); - try (PDDocument doc2 = PDDocument.load(new File(filenameSigned2))) + try (PDDocument doc2 = PDFParser.load(new File(filenameSigned2))) { List signatureDictionaries = doc2.getSignatureDictionaries(); Assert.assertEquals(2, signatureDictionaries.size()); @@ -297,12 +298,12 @@ private void checkSignature(File origFile, File signedFile) throws IOException, CMSException, OperatorCreationException, GeneralSecurityException { String origPageKey; - try (PDDocument document = PDDocument.load(origFile)) + try (PDDocument document = PDFParser.load(origFile)) { // get string representation of pages COSObject origPageKey = document.getDocumentCatalog().getCOSObject().getItem(COSName.PAGES).toString(); } - try (PDDocument document = PDDocument.load(signedFile)) + try (PDDocument document = PDFParser.load(signedFile)) { // PDFBOX-4261: check that object number stays the same Assert.assertEquals(origPageKey, document.getDocumentCatalog().getCOSObject().getItem(COSName.PAGES).toString()); @@ -343,8 +344,10 @@ private void checkSignature(File origFile, File signedFile) Collection signers = signedData.getSignerInfos().getSigners(); SignerInformation signerInformation = signers.iterator().next(); @SuppressWarnings("unchecked") - Collection matches = certificatesStore.getMatches((Selector) signerInformation.getSID()); + Collection matches = certificatesStore + .getMatches((Selector) signerInformation.getSID()); X509CertificateHolder certificateHolder = (X509CertificateHolder) matches.iterator().next(); + Assert.assertArrayEquals(certificate.getEncoded(), certificateHolder.getEncoded()); // CMSVerifierCertificateNotValidException means that the keystore wasn't valid at signing time if (!signerInformation.verify(new JcaSimpleSignerInfoVerifierBuilder().build(certificateHolder))) { @@ -384,7 +387,7 @@ public void testPDFBox3811() throws IOException, NoSuchAlgorithmException document.save(baos); document.close(); - document = PDDocument.load(baos.toByteArray()); + document = PDFParser.load(baos.toByteArray()); // for stable digest document.setDocumentId(12345L); @@ -419,7 +422,7 @@ public void testPDFBox3811() throws IOException, NoSuchAlgorithmException @Test public void testSaveIncrementalAfterSign() throws Exception { - BufferedImage oldImage, expectedImage1, actualImage1, expectedImage2, actualImage2; + BufferedImage oldImage, expectedImage1, actualImage1; CreateSimpleForm.main(new String[0]); // creates "target/SimpleForm.pdf" @@ -433,12 +436,11 @@ public void testSaveIncrementalAfterSign() throws Exception final String fileNameSigned = getOutputFileName("SimpleForm_signed{0}.pdf"); final String fileNameResaved1 = getOutputFileName("SimpleForm_signed{0}_incrementallyresaved1.pdf"); - final String fileNameResaved2 = getOutputFileName("SimpleForm_signed{0}_incrementallyresaved2.pdf"); signing.signDetached(new File("target/SimpleForm.pdf"), new File(outDir + fileNameSigned)); checkSignature(new File("target/SimpleForm.pdf"), new File(outDir, fileNameSigned)); - try (PDDocument doc = PDDocument.load(new File(outDir, fileNameSigned))) + try (PDDocument doc = PDFParser.load(new File(outDir, fileNameSigned))) { oldImage = new PDFRenderer(doc).renderImage(0); @@ -473,7 +475,7 @@ public void testSaveIncrementalAfterSign() throws Exception doc.saveIncremental(fileOutputStream); } checkSignature(new File("target/SimpleForm.pdf"), new File(outDir, fileNameResaved1)); - try (PDDocument doc = PDDocument.load(new File(outDir, fileNameResaved1))) + try (PDDocument doc = PDFParser.load(new File(outDir, fileNameResaved1))) { PDField field = doc.getDocumentCatalog().getAcroForm().getField("SampleField"); Assert.assertEquals("New Value 1", field.getValueAsString()); diff --git a/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java b/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java index 790826eb8be..99dec74e09c 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java @@ -1575,7 +1575,10 @@ private static String getDictionaryString(COSBase base, List objs) thro if (base instanceof COSObject) { COSObject obj = (COSObject) base; - return "COSObject{" + getDictionaryString(obj.getObject(), objs) + "}"; + return "COSObject{" + + getDictionaryString( + obj.isObjectNull() ? COSNull.NULL : obj.getObject(), objs) + + "}"; } return base.toString(); } diff --git a/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java b/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java index be4bde3b3f9..7e2f428c1b5 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java @@ -22,12 +22,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.io.ScratchFile; -import org.apache.pdfbox.pdfparser.PDFObjectStreamParser; /** * This is the in-memory representation of the PDF document. You need to call @@ -89,12 +90,24 @@ public class COSDocument extends COSBase implements Closeable */ private long highestXRefObjectNumber; + private ICOSParser parser; + /** * Constructor. Uses main memory to buffer PDF streams. */ public COSDocument() { - this(ScratchFile.getMainMemoryOnlyInstance()); + this(ScratchFile.getMainMemoryOnlyInstance(), null); + } + + /** + * Constructor. Uses main memory to buffer PDF streams. + * + * @param parser Parser to be used to parse the document on demand + */ + public COSDocument(ICOSParser parser) + { + this(ScratchFile.getMainMemoryOnlyInstance(), parser); } /** @@ -105,8 +118,21 @@ public COSDocument() * */ public COSDocument(ScratchFile scratchFile) + { + this(scratchFile, null); + } + + /** + * Constructor that will use the provide memory handler for storage of the PDF streams. + * + * @param scratchFile memory handler for buffering of PDF streams + * @param parser Parser to be used to parse the document on demand + * + */ + public COSDocument(ScratchFile scratchFile, ICOSParser parser) { this.scratchFile = scratchFile; + this.parser = parser; } /** @@ -142,39 +168,29 @@ public COSStream createCOSStream(COSDictionary dictionary) } /** - * This will get the first dictionary object by type. - * - * @param type The type of the object. - * - * @return This will return an object with the specified type. - */ - public COSObject getObjectByType(COSName type) - { - for( COSObject object : objectPool.values() ) + * Get the dictionary containing the linearization information if the pdf is linearized. + * + * @return the dictionary containing the linearization information + */ + public COSDictionary getLinearizedDictionary() + { + // get all keys with a positive offset in ascending order, as the linearization dictionary shall be the first + // within the pdf + List objectKeys = xrefTable.entrySet().stream() // + .filter(e -> e.getValue() > 0L) // + .sorted((e1, e2) -> e1.getValue().compareTo(e2.getValue())) // + .map(Entry::getKey) // + .collect(Collectors.toList()); + for (COSObjectKey objectKey : objectKeys) { - COSBase realObject = object.getObject(); - if( realObject instanceof COSDictionary ) + COSObject objectFromPool = getObjectFromPool(objectKey); + COSBase realObject = objectFromPool.getObject(); + if (realObject instanceof COSDictionary) { - try - { - COSDictionary dic = (COSDictionary)realObject; - COSBase typeItem = dic.getItem(COSName.TYPE); - if (typeItem instanceof COSName) - { - COSName objectType = (COSName) typeItem; - if (objectType.equals(type)) - { - return object; - } - } - else if (typeItem != null) - { - LOG.debug("Expected a /Name object after /Type, got '" + typeItem + "' instead"); - } - } - catch (ClassCastException e) + COSDictionary dic = (COSDictionary) realObject; + if (dic.getItem(COSName.LINEARIZED) != null) { - LOG.warn(e, e); + return dic; } } } @@ -182,88 +198,44 @@ else if (typeItem != null) } /** - * This will get all dictionary objects by type. + * This will get all dictionaries objects by type. * * @param type The type of the object. * - * @return This will return an object with the specified type. + * @return This will return all objects with the specified type. */ - public List getObjectsByType( String type ) + public List getObjectsByType(COSName type) { - return getObjectsByType( COSName.getPDFName( type ) ); + return getObjectsByType(type, null); } /** - * This will get a dictionary object by type. + * This will get all dictionaries objects by type. * - * @param type The type of the object. + * @param type1 The first possible type of the object, mandatory. + * @param type2 The second possible type of the object, usally an abreviation, optional. * - * @return This will return an object with the specified type. + * @return This will return all objects with the specified type(s). */ - public List getObjectsByType( COSName type ) + public List getObjectsByType(COSName type1, COSName type2) { List retval = new ArrayList<>(); - for( COSObject object : objectPool.values() ) + for (COSObjectKey objectKey : xrefTable.keySet()) { - COSBase realObject = object.getObject(); + COSObject objectFromPool = getObjectFromPool(objectKey); + COSBase realObject = objectFromPool.getObject(); if( realObject instanceof COSDictionary ) { - try + COSName dictType = ((COSDictionary) realObject).getCOSName(COSName.TYPE); + if (type1.equals(dictType) || (type2 != null && type2.equals(dictType))) { - COSDictionary dic = (COSDictionary)realObject; - COSBase typeItem = dic.getItem(COSName.TYPE); - if (typeItem instanceof COSName) - { - COSName objectType = (COSName) typeItem; - if (objectType.equals(type)) - { - retval.add( object ); - } - } - else if (typeItem != null) - { - LOG.debug("Expected a /Name object after /Type, got '" + typeItem + "' instead"); - } - } - catch (ClassCastException e) - { - LOG.warn(e, e); + retval.add(objectFromPool); } } } return retval; } - /** - * Returns the COSObjectKey for a given COS object, or null if there is none. - * This lookup iterates over all objects in a PDF, which may be slow for large files. - * - * @param object COS object - * @return key - */ - public COSObjectKey getKey(COSBase object) - { - for (Map.Entry entry : objectPool.entrySet()) - { - if (entry.getValue().getObject() == object) - { - return entry.getKey(); - } - } - return null; - } - - /** - * This will print contents to stdout. - */ - public void print() - { - for( COSObject object : objectPool.values() ) - { - System.out.println( object); - } - } - /** * This will set the header version of this PDF document. * @@ -359,16 +331,6 @@ public void setDocumentID( COSArray id ) getTrailer().setItem(COSName.ID, id); } - /** - * This will get a list of all available objects. - * - * @return A list of all objects, never null. - */ - public List getObjects() - { - return new ArrayList<>(objectPool.values()); - } - /** * This will get the document trailer. * @@ -444,12 +406,16 @@ public void close() throws IOException IOException firstException = null; // close all open I/O streams - for (COSObject object : getObjects()) + for (COSObject object : objectPool.values()) { - COSBase cosObject = object.getObject(); - if (cosObject instanceof COSStream) + if (!object.isObjectNull()) { - firstException = IOUtils.closeAndLogException((COSStream) cosObject, LOG, "COSStream", firstException); + COSBase cosObject = object.getObject(); + if (cosObject instanceof COSStream) + { + firstException = IOUtils.closeAndLogException((COSStream) cosObject, LOG, + "COSStream", firstException); + } } } @@ -511,33 +477,6 @@ public void setWarnMissingClose(boolean warn) this.warnMissingClose = warn; } - /** - * This method will search the list of objects for types of ObjStm. If it finds - * them then it will parse out all of the objects from the stream that is contains. - * - * @throws IOException If there is an error parsing the stream. - */ - public void dereferenceObjectStreams() throws IOException - { - for( COSObject objStream : getObjectsByType( COSName.OBJ_STM ) ) - { - COSStream stream = (COSStream)objStream.getObject(); - PDFObjectStreamParser parser = new PDFObjectStreamParser(stream, this); - for (COSObject next : parser.parse()) - { - COSObjectKey key = new COSObjectKey(next); - if (objectPool.get(key) == null || objectPool.get(key).getObject() == null - // xrefTable stores negated objNr of objStream for objects in objStreams - || (xrefTable.containsKey(key) - && xrefTable.get(key) == -objStream.getObjectNumber())) - { - COSObject obj = getObjectFromPool(key); - obj.setObject(next.getObject()); - } - } - } - } - /** * This will get an object from the pool. * @@ -555,7 +494,7 @@ public COSObject getObjectFromPool(COSObjectKey key) if (obj == null) { // this was a forward reference, make "proxy" object - obj = new COSObject(null); + obj = new COSObject(null, parser); if( key != null ) { obj.setObjectNumber(key.getNumber()); @@ -566,16 +505,6 @@ public COSObject getObjectFromPool(COSObjectKey key) return obj; } - /** - * Removes an object from the object pool. - * @param key the object key - * @return the object that was removed or null if the object was not found - */ - public COSObject removeObject(COSObjectKey key) - { - return objectPool.remove(key); - } - /** * Populate XRef HashMap with given values. * Each entry maps ObjectKeys to byte offsets in the file. diff --git a/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java b/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java index dee8784f28e..b2a762f5ace 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java @@ -335,8 +335,10 @@ public final class COSName extends COSBase implements Comparable public static final COSName LENGTH = new COSName("Length"); public static final COSName LENGTH1 = new COSName("Length1"); public static final COSName LENGTH2 = new COSName("Length2"); + public static final COSName LENGTH3 = new COSName("Length3"); public static final COSName LIGHTEN = new COSName("Lighten"); public static final COSName LIMITS = new COSName("Limits"); + public static final COSName LINEARIZED = new COSName("Linearized"); public static final COSName LJ = new COSName("LJ"); public static final COSName LL = new COSName("LL"); public static final COSName LLE = new COSName("LLE"); @@ -568,6 +570,7 @@ public final class COSName extends COSBase implements Comparable public static final COSName URI = new COSName("URI"); public static final COSName URL = new COSName("URL"); public static final COSName URL_TYPE = new COSName("URLType"); + public static final COSName USE_CMAP = new COSName("UseCMap"); public static final COSName USER_UNIT = new COSName("UserUnit"); // V public static final COSName V = new COSName("V"); @@ -590,6 +593,7 @@ public final class COSName extends COSBase implements Comparable public static final COSName WIDTH = new COSName("Width"); public static final COSName WIDTHS = new COSName("Widths"); public static final COSName WIN_ANSI_ENCODING = new COSName("WinAnsiEncoding"); + public static final COSName WMODE = new COSName("WMode"); // X public static final COSName XFA = new COSName("XFA"); public static final COSName X_STEP = new COSName("XStep"); diff --git a/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java b/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java index 3ddbe36a183..0dbb8dcf757 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java @@ -18,6 +18,9 @@ import java.io.IOException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * This class represents a PDF object. * @@ -30,6 +33,9 @@ public class COSObject extends COSBase implements COSUpdateInfo private long objectNumber; private int generationNumber; private boolean needToBeUpdated; + private ICOSParser parser; + + private static final Log LOG = LogFactory.getLog(COSObject.class); /** * Constructor. @@ -39,9 +45,21 @@ public class COSObject extends COSBase implements COSUpdateInfo */ public COSObject(COSBase object) { - setObject( object ); + this(object, null); } + /** + * Constructor. + * + * @param object The object that this encapsulates. + * @param parser The parser to be used to load the object on demand + * + */ + public COSObject(COSBase object, ICOSParser parser) + { + setObject( object ); + this.parser = parser; + } /** * This will get the dictionary object in this object that has the name key and * if it is a pdfobjref then it will dereference that and return it. @@ -77,6 +95,10 @@ public COSBase getItem( COSName key ) return retval; } + public boolean isObjectNull() + { + return baseObject == null; + } /** * This will get the object that this object encapsulates. * @@ -84,6 +106,23 @@ public COSBase getItem( COSName key ) */ public COSBase getObject() { + if ((baseObject == null || baseObject instanceof COSNull) && parser != null) + { + try + { + if (!parser.dereferenceCOSObject(this)) + { + // remove parser to avoid endless recursions + parser = null; + } + } + catch (IOException e) + { + // remove parser to avoid endless recursions + parser = null; + LOG.error("Can't dereference " + this, e); + } + } return baseObject; } @@ -97,6 +136,12 @@ public final void setObject(COSBase object) baseObject = object; } + public final void setToNull() + { + baseObject = COSNull.NULL; + parser = null; + } + /** * {@inheritDoc} */ diff --git a/pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSParser.java b/pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSParser.java new file mode 100644 index 00000000000..8c5068c42ad --- /dev/null +++ b/pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSParser.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pdfbox.cos; + +import java.io.IOException; + +public interface ICOSParser +{ + + /** + * Dereference the COSBase object which is referenced by the given COSObject. + * + * @param obj the COSObject which references the COSBase object to be dereferenced. + * + * @return true if the referenced object was read successfully + * + * @throws IOException if something went wrong when dereferencing the COSBase object + */ + public boolean dereferenceCOSObject(COSObject obj) throws IOException; + +} diff --git a/pdfbox/src/main/java/org/apache/pdfbox/io/SequentialRead.java b/pdfbox/src/main/java/org/apache/pdfbox/io/SequentialRead.java deleted file mode 100644 index f856a901d90..00000000000 --- a/pdfbox/src/main/java/org/apache/pdfbox/io/SequentialRead.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.pdfbox.io; - -import java.io.Closeable; -import java.io.IOException; - -/** - * An interface allowing sequential read operations. - */ -public interface SequentialRead extends Closeable -{ - - /** - * Read a single byte of data. - * - * @return The byte of data that is being read. - * - * @throws IOException If there is an error while reading the data. - */ - int read() throws IOException; - - /** - * Read a buffer of data. - * - * @param b The buffer to write the data to. - * @return The number of bytes that were actually read. - * @throws IOException If there was an error while reading the data. - */ - int read(byte[] b) throws IOException; - - /** - * Read a buffer of data. - * - * @param b The buffer to write the data to. - * @param offset Offset into the buffer to start writing. - * @param length The amount of data to attempt to read. - * @return The number of bytes that were actually read. - * @throws IOException If there was an error while reading the data. - */ - int read(byte[] b, int offset, int length) throws IOException; - -} diff --git a/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java b/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java index 7e534958a4b..cae56efd06b 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java @@ -37,6 +37,7 @@ import org.apache.pdfbox.cos.COSObject; import org.apache.pdfbox.cos.COSStream; import org.apache.pdfbox.io.IOUtils; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDResources; @@ -262,7 +263,7 @@ private void loadPDFs() throws IOException private PDDocument loadPDF(String pdfName) throws IOException { - return PDDocument.load(new File(pdfName)); + return PDFParser.load(new File(pdfName)); } /** diff --git a/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java b/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java index 9c2fc563846..9b6d7329577 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java @@ -45,6 +45,7 @@ import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.io.MemoryUsageSetting; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDDocumentInformation; import org.apache.pdfbox.pdmodel.PDDocumentNameDestinationDictionary; @@ -357,11 +358,11 @@ private void optimizedMergeDocuments(MemoryUsageSetting memUsageSetting) throws { if (sourceObject instanceof File) { - sourceDoc = PDDocument.load((File) sourceObject, memUsageSetting); + sourceDoc = PDFParser.load((File) sourceObject, memUsageSetting); } else { - sourceDoc = PDDocument.load((InputStream) sourceObject, memUsageSetting); + sourceDoc = PDFParser.load((InputStream) sourceObject, memUsageSetting); } for (PDPage page : sourceDoc.getPages()) { @@ -433,11 +434,11 @@ private void legacyMergeDocuments(MemoryUsageSetting memUsageSetting) throws IOE PDDocument sourceDoc = null; if (sourceObject instanceof File) { - sourceDoc = PDDocument.load((File) sourceObject, partitionedMemSetting); + sourceDoc = PDFParser.load((File) sourceObject, partitionedMemSetting); } else { - sourceDoc = PDDocument.load((InputStream) sourceObject, + sourceDoc = PDFParser.load((InputStream) sourceObject, partitionedMemSetting); } tobeclosed.add(sourceDoc); diff --git a/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PageExtractor.java b/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PageExtractor.java index 8ad64262435..e6eeff0fb53 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PageExtractor.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PageExtractor.java @@ -18,6 +18,7 @@ package org.apache.pdfbox.multipdf; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java index 926e2c7704b..d14a10538be 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java @@ -1155,6 +1155,17 @@ protected boolean isEOL() throws IOException return isEOL(seqSource.peek()); } + /** + * This will tell if the end of the data is reached. + * + * @return true if the end of the data is reached. + * @throws IOException If there is an error reading from the stream. + */ + protected boolean isEOF() throws IOException + { + return seqSource.isEOF(); + } + /** * This will tell if the next byte to be read is an end of line byte. * diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java index e974b7c7318..f98ef53764a 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java @@ -24,17 +24,12 @@ import java.security.KeyStore; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Queue; import java.util.Set; -import java.util.TreeMap; import java.util.stream.Collectors; import org.apache.commons.logging.Log; @@ -43,13 +38,13 @@ import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSDocument; -import org.apache.pdfbox.cos.COSInputStream; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSNull; import org.apache.pdfbox.cos.COSNumber; import org.apache.pdfbox.cos.COSObject; import org.apache.pdfbox.cos.COSObjectKey; import org.apache.pdfbox.cos.COSStream; +import org.apache.pdfbox.cos.ICOSParser; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.io.RandomAccessRead; import org.apache.pdfbox.pdfparser.XrefTrailerResolver.XRefType; @@ -62,15 +57,12 @@ import org.apache.pdfbox.pdmodel.encryption.StandardDecryptionMaterial; /** - * PDF-Parser which first reads startxref and xref tables in order to know valid objects and parse only these objects. + * COS-Parser which first reads startxref and xref tables in order to know valid objects and parse only these objects. * - * First {@link PDFParser#parse()} or {@link FDFParser#parse()} must be called before page objects - * can be retrieved, e.g. {@link PDFParser#getPDDocument()}. - * - * This class is a much enhanced version of QuickParser presented in PDFBOX-1104 by Jeremy Villalobos. + * This class is a much enhanced version of QuickParser presented in + * PDFBOX-1104 by Jeremy Villalobos. */ -public class COSParser extends BaseParser +public class COSParser extends BaseParser implements ICOSParser { private static final String PDF_HEADER = "%PDF-"; private static final String FDF_HEADER = "%FDF-"; @@ -101,12 +93,6 @@ public class COSParser extends BaseParser private String password = ""; private String keyAlias = null; - /** - * Only parse the PDF file minimally allowing access to basic information. - */ - public static final String SYSPROP_PARSEMINIMAL = - "org.apache.pdfbox.pdfparser.nonSequentialPDFParser.parseMinimal"; - /** * The range within the %%EOF marker will be searched. * Useful if there are additional characters after %%EOF within the PDF. @@ -568,7 +554,7 @@ public boolean isLenient() * @param lenient try to handle malformed PDFs. * */ - public void setLenient(boolean lenient) + protected void setLenient(boolean lenient) { if (initialParseDone) { @@ -577,234 +563,21 @@ public void setLenient(boolean lenient) this.isLenient = lenient; } - /** - * Creates a unique object id using object number and object generation - * number. (requires object number < 2^31)) - */ - private long getObjectId(final COSObject obj) - { - return obj.getObjectNumber() << 32 | obj.getGenerationNumber(); - } - - /** - * Adds all from newObjects to toBeParsedList if it is not an COSObject or - * we didn't add this COSObject already (checked via addedObjects). - */ - private void addNewToList(final Queue toBeParsedList, - final Collection newObjects, final Set addedObjects) - { - for (COSBase newObject : newObjects) - { - addNewToList(toBeParsedList, newObject, addedObjects); - } - } - - /** - * Adds newObject to toBeParsedList if it is not an COSObject or we didn't - * add this COSObject already (checked via addedObjects). Simple objects are - * not added because nothing is done with them when toBeParsedList is - * processed. - */ - private void addNewToList(final Queue toBeParsedList, final COSBase newObject, - final Set addedObjects) - { - if (newObject instanceof COSObject) - { - final long objId = getObjectId((COSObject) newObject); - if (!addedObjects.add(objId)) - { - return; - } - toBeParsedList.add(newObject); - } - else if (newObject instanceof COSDictionary || newObject instanceof COSArray) - { - toBeParsedList.add(newObject); - } - } - - /** - * Will parse every object necessary to load a single page from the pdf document. We try our - * best to order objects according to offset in file before reading to minimize seek operations. - * - * @param dict the COSObject from the parent pages. - * @param excludeObjects dictionary object reference entries with these names will not be parsed - * - * @throws IOException if something went wrong - */ - protected void parseDictObjects(COSDictionary dict, COSName... excludeObjects) throws IOException - { - // ---- create queue for objects waiting for further parsing - final Queue toBeParsedList = new LinkedList<>(); - // offset ordered object map - final TreeMap> objToBeParsed = new TreeMap<>(); - // in case of compressed objects offset points to stmObj - final Set parsedObjects = new HashSet<>(); - final Set addedObjects = new HashSet<>(); - - addExcludedToList(excludeObjects, dict, parsedObjects); - addNewToList(toBeParsedList, dict.getValues(), addedObjects); - - // ---- go through objects to be parsed - while (!(toBeParsedList.isEmpty() && objToBeParsed.isEmpty())) - { - // -- first get all COSObject from other kind of objects and - // put them in objToBeParsed; afterwards toBeParsedList is empty - COSBase baseObj; - while ((baseObj = toBeParsedList.poll()) != null) - { - if (baseObj instanceof COSDictionary) - { - addNewToList(toBeParsedList, ((COSDictionary) baseObj).getValues(), addedObjects); - } - else if (baseObj instanceof COSArray) - { - for (COSBase cosBase : (COSArray) baseObj) - { - addNewToList(toBeParsedList, cosBase, addedObjects); - } - } - else if (baseObj instanceof COSObject) - { - COSObject obj = (COSObject) baseObj; - long objId = getObjectId(obj); - COSObjectKey objKey = new COSObjectKey(obj.getObjectNumber(), obj.getGenerationNumber()); - - if (!parsedObjects.contains(objId)) - { - Long fileOffset = document.getXrefTable().get(objKey); - if (fileOffset == null && isLenient) - { - Map bfCOSObjectKeyOffsets = getBFCOSObjectOffsets(); - fileOffset = bfCOSObjectKeyOffsets.get(objKey); - if (fileOffset != null) - { - LOG.debug("Set missing " + fileOffset + " for object " + objKey); - document.getXrefTable().put(objKey, fileOffset); - } - } - - // it is allowed that object references point to null, thus we have to test - if (fileOffset != null && fileOffset != 0) - { - if (fileOffset > 0) - { - objToBeParsed.put(fileOffset, Collections.singletonList(obj)); - } - else - { - // negative offset means we have a compressed - // object within object stream => get offset of object stream - COSObjectKey key = new COSObjectKey((int) -fileOffset, 0); - fileOffset = document.getXrefTable().get(key); - if ((fileOffset == null) || (fileOffset <= 0)) - { - if (isLenient) - { - Map bfCOSObjectKeyOffsets = getBFCOSObjectOffsets(); - fileOffset = bfCOSObjectKeyOffsets.get(key); - if (fileOffset != null) - { - LOG.debug("Set missing " + fileOffset + " for object " - + key); - document.getXrefTable().put(key, fileOffset); - } - else - { - LOG.warn("Invalid object stream xref object reference for key '" - + objKey + "': " + fileOffset); - continue; - } - } - else - { - throw new IOException( - "Invalid object stream xref object reference for key '" - + objKey + "': " + fileOffset); - } - } - - List stmObjects = objToBeParsed.get(fileOffset); - if (stmObjects == null) - { - stmObjects = new ArrayList<>(); - objToBeParsed.put(fileOffset, stmObjects); - } - // java does not have a test for immutable - else if (!(stmObjects instanceof ArrayList)) - { - throw new IOException(obj + " cannot be assigned to offset " + - fileOffset + ", this belongs to " + stmObjects.get(0)); - } - stmObjects.add(obj); - } - } - else - { - // NULL object - COSObject pdfObject = document.getObjectFromPool(objKey); - pdfObject.setObject(COSNull.NULL); - } - } - } - } - - // ---- read first COSObject with smallest offset - // resulting object will be added to toBeParsedList - if (objToBeParsed.isEmpty()) - { - break; - } - - for (COSObject obj : objToBeParsed.remove(objToBeParsed.firstKey())) - { - COSBase parsedObj = parseObjectDynamically(obj, false); - if (parsedObj != null) - { - obj.setObject(parsedObj); - addNewToList(toBeParsedList, parsedObj, addedObjects); - parsedObjects.add(getObjectId(obj)); - } - } - } - } - - // add objects not to be parsed to list of already parsed objects - private void addExcludedToList(COSName[] excludeObjects, COSDictionary dict, final Set parsedObjects) + @Override + public boolean dereferenceCOSObject(COSObject obj) throws IOException { - if (excludeObjects != null) + long currentPos = source.getPosition(); + COSBase parsedObj = parseObjectDynamically(obj.getObjectNumber(), obj.getGenerationNumber(), + false); + if (currentPos > 0) { - for (COSName objName : excludeObjects) - { - COSBase baseObj = dict.getItem(objName); - if (baseObj instanceof COSObject) - { - parsedObjects.add(getObjectId((COSObject) baseObj)); - } - } + source.seek(currentPos); } + return parsedObj != null; } /** - * This will parse the next object from the stream and add it to the local state. - * - * @param obj object to be parsed (we only take object number and generation number for lookup start offset) - * @param requireExistingNotCompressedObj if true object to be parsed must not be contained within - * compressed stream - * @return the parsed object (which is also added to document object) - * - * @throws IOException If an IO error occurs. - */ - protected final COSBase parseObjectDynamically(COSObject obj, - boolean requireExistingNotCompressedObj) throws IOException - { - return parseObjectDynamically(obj.getObjectNumber(), - obj.getGenerationNumber(), requireExistingNotCompressedObj); - } - - /** - * This will parse the next object from the stream and add it to the local state. - * It's reduced to parsing an indirect object. + * Parse the object for the given object number. * * @param objNr object number of object to be parsed * @param objGenNr object generation number of object to be parsed @@ -816,17 +589,18 @@ protected final COSBase parseObjectDynamically(COSObject obj, * * @throws IOException If an IO error occurs. */ - protected COSBase parseObjectDynamically(long objNr, int objGenNr, + protected synchronized COSBase parseObjectDynamically(long objNr, int objGenNr, boolean requireExistingNotCompressedObj) throws IOException { // ---- create object key and get object (container) from pool final COSObjectKey objKey = new COSObjectKey(objNr, objGenNr); final COSObject pdfObject = document.getObjectFromPool(objKey); + COSBase referencedObject = !pdfObject.isObjectNull() ? pdfObject.getObject() : null; - if (pdfObject.getObject() == null) + // not previously parsed + if (referencedObject == null) { - // not previously parsed - // ---- read offset or object stream object number from xref table + // read offset or object stream object number from xref table Long offsetOrObjstmObNr = document.getXrefTable().get(objKey); // maybe something is wrong with the xref table -> perform brute force search for all objects @@ -852,24 +626,34 @@ protected COSBase parseObjectDynamically(long objNr, int objGenNr, if (offsetOrObjstmObNr == null) { // not defined object -> NULL object (Spec. 1.7, chap. 3.2.9) - pdfObject.setObject(COSNull.NULL); + // remove parser to avoid endless recursion + pdfObject.setToNull(); } else if (offsetOrObjstmObNr > 0) { // offset of indirect object in file - parseFileObject(offsetOrObjstmObNr, objKey, pdfObject); + referencedObject = parseFileObject(offsetOrObjstmObNr, objKey); } else { // xref value is object nr of object stream containing object to be parsed // since our object was not found it means object stream was not parsed so far - parseObjectStream((int) -offsetOrObjstmObNr); + referencedObject = parseObjectStreamObject((int) -offsetOrObjstmObNr, objKey); + } + if (referencedObject != null && referencedObject != COSNull.NULL) + { + pdfObject.setObject(referencedObject); + } + else + { + pdfObject.setToNull(); } } - return pdfObject.getObject(); + return referencedObject; } - private void parseFileObject(Long offsetOrObjstmObNr, final COSObjectKey objKey, final COSObject pdfObject) throws IOException + private COSBase parseFileObject(Long offsetOrObjstmObNr, final COSObjectKey objKey) + throws IOException { // ---- go to object start source.seek(offsetOrObjstmObNr); @@ -888,21 +672,21 @@ private void parseFileObject(Long offsetOrObjstmObNr, final COSObjectKey objKey, } skipSpaces(); - COSBase pb = parseDirObject(); + COSBase parsedObject = parseDirObject(); String endObjectKey = readString(); if (endObjectKey.equals(STREAM_STRING)) { source.rewind(endObjectKey.getBytes(StandardCharsets.ISO_8859_1).length); - if (pb instanceof COSDictionary) + if (parsedObject instanceof COSDictionary) { - COSStream stream = parseCOSStream((COSDictionary) pb); + COSStream stream = parseCOSStream((COSDictionary) parsedObject); if (securityHandler != null) { securityHandler.decryptStream(stream, objKey.getNumber(), objKey.getGeneration()); } - pb = stream; + parsedObject = stream; } else { @@ -929,11 +713,9 @@ private void parseFileObject(Long offsetOrObjstmObNr, final COSObjectKey objKey, } else if (securityHandler != null) { - securityHandler.decrypt(pb, objKey.getNumber(), objKey.getGeneration()); + securityHandler.decrypt(parsedObject, objKey.getNumber(), objKey.getGeneration()); } - pdfObject.setObject(pb); - if (!endObjectKey.startsWith(ENDOBJ_STRING)) { if (isLenient) @@ -949,11 +731,21 @@ else if (securityHandler != null) + " does not end with 'endobj' but with '" + endObjectKey + "'"); } } + return parsedObject; } - private void parseObjectStream(int objstmObjNr) throws IOException + /** + * Parse the object with the given key from the object stream with the given number. + * + * @param objstmObjNr the number of the offset stream + * @param key the key of the object to be parsed + * @return the parsed object + * @throws IOException if something went wrong when parsing the object + */ + protected COSBase parseObjectStreamObject(int objstmObjNr, COSObjectKey key) throws IOException { final COSBase objstmBaseObj = parseObjectDynamically(objstmObjNr, 0, true); + COSBase objectStreamObject = null; if (objstmBaseObj instanceof COSStream) { // parse object stream @@ -961,32 +753,14 @@ private void parseObjectStream(int objstmObjNr) throws IOException try { parser = new PDFObjectStreamParser((COSStream) objstmBaseObj, document); - // register all objects which are referenced to be contained in object stream - parser.parse().stream().forEach(next -> { - COSObjectKey stmObjKey = new COSObjectKey(next); - Long offset = xrefTrailerResolver.getXrefTable().get(stmObjKey); - if (offset != null && offset == -objstmObjNr) - { - COSObject stmObj = document.getObjectFromPool(stmObjKey); - stmObj.setObject(next.getObject()); - } - }); + objectStreamObject = parser.parseObject(key.getNumber()); } catch (IOException ex) { if (isLenient) { - if (parser == null) - { - LOG.error("object stream " + objstmObjNr - + " could not be parsed due to an exception", ex); - } - else - { - LOG.debug("Stop reading object stream " + objstmObjNr - + " due to an exception", ex); - } - // the error is handled in parseDictObjects + LOG.error("object stream " + objstmObjNr + + " could not be parsed due to an exception", ex); } else { @@ -994,39 +768,29 @@ private void parseObjectStream(int objstmObjNr) throws IOException } } } + return objectStreamObject; } /** * Returns length value referred to or defined in given object. */ - private COSNumber getLength(final COSBase lengthBaseObj, final COSName streamType) throws IOException + private COSNumber getLength(final COSBase lengthBaseObj) throws IOException { if (lengthBaseObj == null) { return null; } - COSNumber retVal; // maybe length was given directly if (lengthBaseObj instanceof COSNumber) { - retVal = (COSNumber) lengthBaseObj; + return (COSNumber) lengthBaseObj; } // length in referenced object - else if (lengthBaseObj instanceof COSObject) + if (lengthBaseObj instanceof COSObject) { COSObject lengthObj = (COSObject) lengthBaseObj; COSBase length = lengthObj.getObject(); if (length == null) - { - // not read so far, keep current stream position - final long curFileOffset = source.getPosition(); - boolean isObjectStream = COSName.OBJ_STM.equals(streamType); - parseObjectDynamically(lengthObj, isObjectStream); - // reset current stream position - source.seek(curFileOffset); - length = lengthObj.getObject(); - } - if (length == null) { throw new IOException("Length object content was not read."); } @@ -1036,19 +800,15 @@ else if (lengthBaseObj instanceof COSObject) + lengthObj.getGenerationNumber() + ") not found"); return null; } - if (!(length instanceof COSNumber)) + if (length instanceof COSNumber) { - throw new IOException("Wrong type of referenced length object " + lengthObj - + ": " + length.getClass().getSimpleName()); + return (COSNumber) length; } - retVal = (COSNumber) length; + throw new IOException("Wrong type of referenced length object " + lengthObj + ": " + + length.getClass().getSimpleName()); } - else - { - throw new IOException("Wrong type of length object: " - + lengthBaseObj.getClass().getSimpleName()); - } - return retVal; + throw new IOException( + "Wrong type of length object: " + lengthBaseObj.getClass().getSimpleName()); } private static final int STREAMCOPYBUFLEN = 8192; @@ -1080,7 +840,7 @@ protected COSStream parseCOSStream(COSDictionary dic) throws IOException /* * This needs to be dic.getItem because when we are parsing, the underlying object might still be null. */ - COSNumber streamLengthObj = getLength(dic.getItem(COSName.LENGTH), dic.getCOSName(COSName.TYPE)); + COSNumber streamLengthObj = getLength(dic.getItem(COSName.LENGTH)); if (streamLengthObj == null) { if (isLenient) @@ -1749,8 +1509,8 @@ private boolean bfSearchForTrailer(COSDictionary trailer) throws IOException if (rootObj instanceof COSObject) { // check if the dictionary can be dereferenced and is the one we are looking for - COSDictionary rootDict = retrieveCOSDictionary((COSObject) rootObj); - if (rootDict != null && isCatalog(rootDict)) + COSBase rootDict = ((COSObject) rootObj).getObject(); + if (rootDict instanceof COSDictionary && isCatalog((COSDictionary) rootDict)) { rootFound = true; } @@ -1759,8 +1519,8 @@ private boolean bfSearchForTrailer(COSDictionary trailer) throws IOException if (infoObj instanceof COSObject) { // check if the dictionary can be dereferenced and is the one we are looking for - COSDictionary infoDict = retrieveCOSDictionary((COSObject) infoObj); - if (infoDict != null && isInfo(infoDict)) + COSBase infoDict = ((COSObject) infoObj).getObject(); + if (infoDict instanceof COSDictionary && isInfo((COSDictionary) infoDict)) { infoFound = true; } @@ -1776,8 +1536,8 @@ private boolean bfSearchForTrailer(COSDictionary trailer) throws IOException { // check if the dictionary can be dereferenced // TODO check if the dictionary is an encryption dictionary? - COSDictionary encDict = retrieveCOSDictionary((COSObject) encObj); - if (encDict != null) + COSBase encDict = ((COSObject) encObj).getObject(); + if (encDict instanceof COSDictionary) { trailer.setItem(COSName.ENCRYPT, encObj); } @@ -1861,7 +1621,7 @@ private void bfSearchForObjStreams() throws IOException .forEach(o -> LOG.warn( "Skipped incomplete object stream:" + o.getValue() + " at " + o.getKey())); - // collect all stream offset + // collect all stream offsets List objStreamOffsets = bfSearchForObjStreamOffsets().entrySet().stream() // .filter(o -> bfSearchCOSObjectKeyOffsets.get(o.getValue()) != null) // .filter(o -> o.getKey().equals(bfSearchCOSObjectKeyOffsets.get(o.getValue()))) // @@ -1874,31 +1634,32 @@ private void bfSearchForObjStreams() throws IOException long stmObjNumber = readObjectNumber(); int stmGenNumber = readGenerationNumber(); readExpectedString(OBJ_MARKER, true); - int nrOfObjects = 0; - byte[] numbersBytes = null; COSStream stream = null; - COSInputStream is = null; try { COSDictionary dict = parseCOSDictionary(); - int offsetFirstStream = dict.getInt(COSName.FIRST); - nrOfObjects = dict.getInt(COSName.N); - // skip the stream if required values are missing - if (offsetFirstStream != -1 && nrOfObjects != -1) + stream = parseCOSStream(dict); + if (securityHandler != null) { - stream = parseCOSStream(dict); - if (securityHandler != null) + securityHandler.decryptStream(stream, stmObjNumber, stmGenNumber); + } + PDFObjectStreamParser objStreamParser = new PDFObjectStreamParser(stream, document); + Map objectNumbers = objStreamParser.readObjectNumbers(); + Map xrefOffset = xrefTrailerResolver.getXrefTable(); + for (Long objNumber : objectNumbers.keySet()) + { + COSObjectKey objKey = new COSObjectKey(objNumber, 0); + Long existingOffset = bfSearchCOSObjectKeyOffsets.get(objKey); + if (existingOffset != null && existingOffset < 0) { - securityHandler.decryptStream(stream, stmObjNumber, stmGenNumber); + // translate stream object key to its offset + COSObjectKey objStmKey = new COSObjectKey(Math.abs(existingOffset), 0); + existingOffset = bfSearchCOSObjectKeyOffsets.get(objStmKey); } - is = stream.createInputStream(); - numbersBytes = new byte[offsetFirstStream]; - long isResult = is.read(numbersBytes); - - if (Long.compare(isResult, numbersBytes.length) != 0) + if (existingOffset == null || offset > existingOffset) { - LOG.debug("Tried reading " + numbersBytes.length + " bytes but only " - + isResult + " bytes read"); + bfSearchCOSObjectKeyOffsets.put(objKey, -stmObjNumber); + xrefOffset.put(objKey, -stmObjNumber); } } } @@ -1909,55 +1670,11 @@ private void bfSearchForObjStreams() throws IOException } finally { - if (is != null) - { - is.close(); - } if (stream != null) { stream.close(); } } - if (numbersBytes != null) - { - // convert byte array to string, skip leading/trailing spaces, replace LF\double spaces - String[] numbers = new String(numbersBytes, StandardCharsets.ISO_8859_1) // - .trim() // - .replaceAll("\n", " ") // - .replace(" ", " ") // - .split(" "); - if (numbers.length < nrOfObjects * 2) - { - LOG.debug( - "Skipped corrupt stream: (" + stmObjNumber + " 0 at offset " + offset); - continue; - } - Map xrefOffset = xrefTrailerResolver.getXrefTable(); - for (int i = 0; i < nrOfObjects; i++) - { - try - { - long objNumber = Long.parseLong(numbers[i * 2]); - COSObjectKey objKey = new COSObjectKey(objNumber, 0); - Long existingOffset = bfSearchCOSObjectKeyOffsets.get(objKey); - if (existingOffset != null && existingOffset < 0) - { - // translate stream object key to its offset - COSObjectKey objStmKey = new COSObjectKey(Math.abs(existingOffset), 0); - existingOffset = bfSearchCOSObjectKeyOffsets.get(objStmKey); - } - if (existingOffset == null || offset > existingOffset) - { - bfSearchCOSObjectKeyOffsets.put(objKey, -stmObjNumber); - xrefOffset.put(objKey, -stmObjNumber); - } - } - catch (NumberFormatException exception) - { - LOG.debug("Skipped corrupt object key in stream: " + stmObjNumber); - } - } - } } // restore origin offset source.seek(originOffset); @@ -2211,23 +1928,26 @@ private COSDictionary rebuildTrailer() throws IOException private boolean searchForTrailerItems(COSDictionary trailer) throws IOException { boolean rootFound = false; - for (Entry entry : bfSearchCOSObjectKeyOffsets.entrySet()) + for (COSObjectKey key : bfSearchCOSObjectKeyOffsets.keySet()) { - COSDictionary dictionary = retrieveCOSDictionary(entry.getKey(), entry.getValue()); - if (dictionary == null) + COSObject cosObject = document.getObjectFromPool(key); + COSBase baseObject = cosObject.getObject(); + + if (!(baseObject instanceof COSDictionary)) { continue; } + COSDictionary dictionary = (COSDictionary) baseObject; // document catalog if (isCatalog(dictionary)) { - trailer.setItem(COSName.ROOT, document.getObjectFromPool(entry.getKey())); + trailer.setItem(COSName.ROOT, cosObject); rootFound = true; } // info dictionary else if (isInfo(dictionary)) { - trailer.setItem(COSName.INFO, document.getObjectFromPool(entry.getKey())); + trailer.setItem(COSName.INFO, cosObject); } // encryption dictionary, if existing, is lost // We can't run "Algorithm 2" from PDF specification because of missing ID @@ -2235,56 +1955,6 @@ else if (isInfo(dictionary)) return rootFound; } - private COSDictionary retrieveCOSDictionary(COSObject object) throws IOException - { - COSObjectKey key = new COSObjectKey(object); - Long offset = bfSearchCOSObjectKeyOffsets.get(key); - if (offset != null) - { - return retrieveCOSDictionary(key, offset); - } - return null; - } - - private COSDictionary retrieveCOSDictionary(COSObjectKey key, long offset) throws IOException - { - COSDictionary dictionary = null; - // handle compressed objects - if (offset < 0) - { - COSObject compressedObject = document.getObjectFromPool(key); - if (compressedObject.getObject() == null) - { - parseObjectStream((int) -offset); - } - COSBase baseObject = compressedObject.getObject(); - if (baseObject instanceof COSDictionary) - { - dictionary = (COSDictionary) baseObject; - } - } - else - { - source.seek(offset); - readObjectNumber(); - readGenerationNumber(); - readExpectedString(OBJ_MARKER, true); - if (source.peek() != '<') - { - return null; - } - try - { - dictionary = parseCOSDictionary(); - } - catch (IOException exception) - { - LOG.debug("Skipped object " + key + ", either it's corrupt or not a dictionary", exception); - } - } - return dictionary; - } - /** * Check if all entries of the pages dictionary are present. Those which can't be dereferenced are removed. * @@ -2768,7 +2438,7 @@ private void parseXrefStream(COSStream stream, long objByteOffset, boolean isSta xrefTrailerResolver.nextXrefObj( objByteOffset, XRefType.STREAM ); xrefTrailerResolver.setTrailer( stream ); } - PDFXrefStreamParser parser = new PDFXrefStreamParser( stream, document, xrefTrailerResolver ); + PDFXrefStreamParser parser = new PDFXrefStreamParser(stream, document, xrefTrailerResolver); parser.parse(); } @@ -2823,34 +2493,6 @@ public AccessPermission getAccessPermission() throws IOException return accessPermission; } - /** - * Parse the values of the trailer dictionary and return the root object. - * - * @param trailer The trailer dictionary. - * @return The parsed root object. - * @throws IOException If an IO error occurs or if the root object is missing in the trailer dictionary. - */ - protected COSBase parseTrailerValuesDynamically(COSDictionary trailer) throws IOException - { - // PDFBOX-1557 - ensure that all COSObject are loaded in the trailer - // PDFBOX-1606 - after securityHandler has been instantiated - for (COSBase trailerEntry : trailer.getValues()) - { - if (trailerEntry instanceof COSObject) - { - COSObject tmpObj = (COSObject) trailerEntry; - parseObjectDynamically(tmpObj, false); - } - } - // parse catalog or root object - COSObject root = trailer.getCOSObject(COSName.ROOT); - if (root == null) - { - throw new IOException("Missing root object specification in trailer."); - } - return root.getObject(); - } - /** * Prepare for decryption. * @@ -2869,12 +2511,6 @@ private void prepareDecryption() throws IOException return; } - if (trailerEncryptItem instanceof COSObject) - { - COSObject trailerEncryptObj = (COSObject) trailerEncryptItem; - parseDictionaryRecursive(trailerEncryptObj); - } - try { encryption = new PDEncryption(document.getEncryptionDictionary()); @@ -2913,34 +2549,4 @@ private void prepareDecryption() throws IOException } } - /** - * Resolves all not already parsed objects of a dictionary recursively. - * - * @param dictionaryObject dictionary to be parsed - * @throws IOException if something went wrong - * - */ - private void parseDictionaryRecursive(COSObject dictionaryObject) throws IOException - { - parseObjectDynamically(dictionaryObject, true); - if (!(dictionaryObject.getObject() instanceof COSDictionary)) - { - // we can't be lenient here, this is called by prepareDecryption() - // to get the encryption directory - throw new IOException("Dictionary object expected at offset " + source.getPosition()); - } - COSDictionary dictionary = (COSDictionary) dictionaryObject.getObject(); - for (COSBase value : dictionary.getValues()) - { - if (value instanceof COSObject) - { - COSObject object = (COSObject) value; - if (object.getObject() == null) - { - parseDictionaryRecursive(object); - } - } - } - } - } diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java index 835a33c446c..33d37b07821 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java @@ -16,19 +16,22 @@ */ package org.apache.pdfbox.pdfparser; +import java.io.BufferedInputStream; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.io.RandomAccessBuffer; import org.apache.pdfbox.io.RandomAccessFile; +import org.apache.pdfbox.pdmodel.fdf.FDFDocument; +import org.apache.pdfbox.util.XMLUtil; public class FDFParser extends COSParser { @@ -74,6 +77,96 @@ public FDFParser(InputStream input) throws IOException init(); } + /** + * This will load a document from a file. + * + * @param filename The name of the file to load. + * + * @return The document that was loaded. + * + * @throws IOException If there is an error reading from the stream. + */ + public static FDFDocument load(String filename) throws IOException + { + FDFParser parser = new FDFParser(filename); + parser.parse(); + return new FDFDocument(parser.getDocument()); + } + + /** + * This will load a document from a file. + * + * @param file The name of the file to load. + * + * @return The document that was loaded. + * + * @throws IOException If there is an error reading from the stream. + */ + public static FDFDocument load(File file) throws IOException + { + FDFParser parser = new FDFParser(file); + parser.parse(); + return new FDFDocument(parser.getDocument()); + } + + /** + * This will load a document from an input stream. + * + * @param input The stream that contains the document. + * + * @return The document that was loaded. + * + * @throws IOException If there is an error reading from the stream. + */ + public static FDFDocument load(InputStream input) throws IOException + { + FDFParser parser = new FDFParser(input); + parser.parse(); + return new FDFDocument(parser.getDocument()); + } + + /** + * This will load a document from a file. + * + * @param filename The name of the file to load. + * + * @return The document that was loaded. + * + * @throws IOException If there is an error reading from the stream. + */ + public static FDFDocument loadXFDF(String filename) throws IOException + { + return loadXFDF(new BufferedInputStream(new FileInputStream(filename))); + } + + /** + * This will load a document from a file. + * + * @param file The name of the file to load. + * + * @return The document that was loaded. + * + * @throws IOException If there is an error reading from the stream. + */ + public static FDFDocument loadXFDF(File file) throws IOException + { + return loadXFDF(new BufferedInputStream(new FileInputStream(file))); + } + + /** + * This will load a document from an input stream. + * + * @param input The stream that contains the document. + * + * @return The document that was loaded. + * + * @throws IOException If there is an error reading from the stream. + */ + public static FDFDocument loadXFDF(InputStream input) throws IOException + { + return new FDFDocument(XMLUtil.parse(input)); + } + /** * Tell if the dictionary is a FDF catalog. * @@ -101,7 +194,7 @@ private void init() + " does not contain an integer value, but: '" + eofLookupRangeStr + "'"); } } - document = new COSDocument(); + document = new COSDocument(this); } /** @@ -115,13 +208,10 @@ private void initialParse() throws IOException { COSDictionary trailer = retrieveTrailer(); - COSBase rootObject = parseTrailerValuesDynamically(trailer); - - // resolve all objects - // A FDF doesn't have a catalog, all FDF fields are within the root object - if (rootObject instanceof COSDictionary) + COSDictionary root = trailer.getCOSDictionary(COSName.ROOT); + if (root == null) { - parseDictObjects((COSDictionary) rootObject, (COSName[]) null); + throw new IOException("Missing root object specification in trailer."); } initialParseDone = true; } diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFObjectStreamParser.java b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFObjectStreamParser.java index c919a502205..01c6ecf7f35 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFObjectStreamParser.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFObjectStreamParser.java @@ -17,31 +17,24 @@ package org.apache.pdfbox.pdfparser; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +import java.util.HashMap; +import java.util.Map; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.cos.COSName; -import org.apache.pdfbox.cos.COSObject; import org.apache.pdfbox.cos.COSStream; /** - * This will parse a PDF 1.5 object stream and extract all of the objects from the stream. + * This will parse a PDF 1.5 object stream and extract the object with given object number from the stream. * * @author Ben Litchfield * */ public class PDFObjectStreamParser extends BaseParser { - /** - * Log instance. - */ - private static final Log LOG = LogFactory.getLog(PDFObjectStreamParser.class); - - private final COSStream stream; + private final int numberOfObjects; + private final int firstObject; /** * Constructor. @@ -53,64 +46,71 @@ public class PDFObjectStreamParser extends BaseParser public PDFObjectStreamParser(COSStream stream, COSDocument document) throws IOException { super(new InputStreamSource(stream.createInputStream())); - this.stream = stream; this.document = document; + // get mandatory number of objects + numberOfObjects = stream.getInt(COSName.N); + if (numberOfObjects == -1) + { + throw new IOException("/N entry missing in object stream"); + } + // get mandatory stream offset of the first object + firstObject = stream.getInt(COSName.FIRST); + if (firstObject == -1) + { + throw new IOException("/First entry missing in object stream"); + } } /** - * This will parse the tokens in the stream. This will close the stream when it is finished parsing. - * - * @return All of the objects in the stream. - * @throws IOException If there is an error while parsing the stream. + * Search for/parse the object with the given object number. This will close the stream when it is finished parsing. + * The stream is closed after parsing the object with the given number. + * + * @param objectNumber the number of the object to b e parsed + * @return the parsed object or null if the object with the given number can't be found + * @throws IOException if there is an error while parsing the stream */ - public List parse() throws IOException + public COSBase parseObject(long objectNumber) throws IOException { - List streamObjects = new ArrayList<>(); + COSBase streamObject = null; try { - //need to first parse the header. - int numberOfObjects = stream.getInt(COSName.N); - if (numberOfObjects == -1) - { - throw new IOException("/N entry missing in object stream"); - } - List objectNumbers = new ArrayList<>( numberOfObjects ); - for( int i=0; i= objectNumbers.size()) + // jump to the offset of the first object + long currentPosition = seqSource.getPosition(); + if (firstObject > 0 && currentPosition < firstObject) { - LOG.error("/ObjStm (object stream) has more objects than /N " + numberOfObjects); - break; + seqSource.readFully(firstObject - (int) currentPosition); } - object = new COSObject(cosObject); - object.setGenerationNumber(0); - object.setObjectNumber( objectNumbers.get( objectCounter) ); - streamObjects.add( object ); - // According to the spec objects within an object stream shall not be enclosed - // by obj/endobj tags, but there are some pdfs in the wild using those tags - // skip endobject marker if present - if (!seqSource.isEOF() && seqSource.peek() == 'e') - { - readLine(); - } - objectCounter++; + // jump to the offset of the object to be parsed + seqSource.readFully(objectOffset); + streamObject = parseDirObject(); } } finally { seqSource.close(); } - return streamObjects; + return streamObject; } + /** + * Read all object numbers from the compressed object stream. The stream is not closed after reading the object + * numbers. + * + * @return a map off all object numbers and the corresponding offset within the object stream. + * @throws IOException if there is an error while parsing the stream + */ + public Map readObjectNumbers() throws IOException + { + Map objectNumbers = new HashMap<>(numberOfObjects); + for (int i = 0; i < numberOfObjects; i++) + { + long objectNumber = readObjectNumber(); + int offset = (int) readLong(); + objectNumbers.put(objectNumber, offset); + } + return objectNumbers; + } } diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java index a843ce2e38c..aaefcf9556f 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java @@ -16,16 +16,19 @@ */ package org.apache.pdfbox.pdfparser; +import java.io.File; import java.io.IOException; import java.io.InputStream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.io.IOUtils; +import org.apache.pdfbox.io.MemoryUsageSetting; +import org.apache.pdfbox.io.RandomAccessBuffer; +import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream; import org.apache.pdfbox.io.RandomAccessRead; import org.apache.pdfbox.io.ScratchFile; import org.apache.pdfbox.pdmodel.PDDocument; @@ -125,6 +128,79 @@ public PDFParser(RandomAccessRead source, String decryptionPassword, InputStream init(scratchFile); } + /** + * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. + * + * @param input byte array that contains the document. + * + * @return loaded document + * + * @throws InvalidPasswordException If the PDF required a non-empty password. + * @throws IOException In case of a reading or parsing error. + */ + public static PDDocument load(byte[] input) throws IOException + { + return load(input, ""); + } + + /** + * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. + * + * @param input byte array that contains the document. + * @param password password to be used for decryption + * + * @return loaded document + * + * @throws InvalidPasswordException If the password is incorrect. + * @throws IOException In case of a reading or parsing error. + */ + public static PDDocument load(byte[] input, String password) throws IOException + { + return load(input, password, null, null); + } + + /** + * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. + * + * @param input byte array that contains the document. + * @param password password to be used for decryption + * @param keyStore key store to be used for decryption when using public key security + * @param alias alias to be used for decryption when using public key security + * + * @return loaded document + * + * @throws InvalidPasswordException If the password is incorrect. + * @throws IOException In case of a reading or parsing error. + */ + public static PDDocument load(byte[] input, String password, InputStream keyStore, String alias) + throws IOException + { + return load(input, password, keyStore, alias, MemoryUsageSetting.setupMainMemoryOnly()); + } + + /** + * Parses a PDF. + * + * @param input byte array that contains the document. + * @param password password to be used for decryption + * @param keyStore key store to be used for decryption when using public key security + * @param alias alias to be used for decryption when using public key security + * @param memUsageSetting defines how memory is used for buffering input stream and PDF streams + * + * @return loaded document + * + * @throws InvalidPasswordException If the password is incorrect. + * @throws IOException In case of a reading or parsing error. + */ + public static PDDocument load(byte[] input, String password, InputStream keyStore, String alias, + MemoryUsageSetting memUsageSetting) throws IOException + { + ScratchFile scratchFile = new ScratchFile(memUsageSetting); + RandomAccessRead source = new RandomAccessBuffer(input); + PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile); + return parser.parse(); + } + private void init(ScratchFile scratchFile) { String eofLookupRangeStr = System.getProperty(SYSPROP_EOFLOOKUPRANGE); @@ -140,22 +216,257 @@ private void init(ScratchFile scratchFile) + " does not contain an integer value, but: '" + eofLookupRangeStr + "'"); } } - document = new COSDocument(scratchFile); + document = new COSDocument(scratchFile, this); } /** - * This will get the PD document that was parsed. When you are done with - * this document you must call close() on it to release resources. + * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. + * + * @param file file to be loaded + * + * @return loaded document + * + * @throws InvalidPasswordException If the file required a non-empty password. + * @throws IOException in case of a file reading or parsing error + */ + public static PDDocument load(File file) throws IOException + { + return load(file, "", MemoryUsageSetting.setupMainMemoryOnly()); + } + + /** + * Parses a PDF. + * + * @param file file to be loaded + * @param memUsageSetting defines how memory is used for buffering PDF streams + * + * @return loaded document + * + * @throws InvalidPasswordException If the file required a non-empty password. + * @throws IOException in case of a file reading or parsing error + */ + public static PDDocument load(File file, MemoryUsageSetting memUsageSetting) throws IOException + { + return load(file, "", null, null, memUsageSetting); + } + + /** + * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. + * + * @param file file to be loaded + * @param password password to be used for decryption + * + * @return loaded document + * + * @throws InvalidPasswordException If the password is incorrect. + * @throws IOException in case of a file reading or parsing error + */ + public static PDDocument load(File file, String password) throws IOException + { + return load(file, password, null, null, MemoryUsageSetting.setupMainMemoryOnly()); + } + + /** + * Parses a PDF. + * + * @param file file to be loaded + * @param password password to be used for decryption + * @param memUsageSetting defines how memory is used for buffering PDF streams + * + * @return loaded document + * + * @throws InvalidPasswordException If the password is incorrect. + * @throws IOException in case of a file reading or parsing error + */ + public static PDDocument load(File file, String password, MemoryUsageSetting memUsageSetting) + throws IOException + { + return load(file, password, null, null, memUsageSetting); + } + + /** + * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. + * + * @param file file to be loaded + * @param password password to be used for decryption + * @param keyStore key store to be used for decryption when using public key security + * @param alias alias to be used for decryption when using public key security + * + * @return loaded document + * + * @throws IOException in case of a file reading or parsing error + */ + public static PDDocument load(File file, String password, InputStream keyStore, String alias) + throws IOException + { + return load(file, password, keyStore, alias, MemoryUsageSetting.setupMainMemoryOnly()); + } + + /** + * Parses a PDF. + * + * @param file file to be loaded + * @param password password to be used for decryption + * @param keyStore key store to be used for decryption when using public key security + * @param alias alias to be used for decryption when using public key security + * @param memUsageSetting defines how memory is used for buffering PDF streams + * + * @return loaded document + * + * @throws IOException in case of a file reading or parsing error + */ + public static PDDocument load(File file, String password, InputStream keyStore, String alias, + MemoryUsageSetting memUsageSetting) throws IOException + { + @SuppressWarnings({ "squid:S2095" }) // raFile not closed here, may be needed for signing + RandomAccessBufferedFileInputStream raFile = new RandomAccessBufferedFileInputStream(file); + try + { + return load(raFile, password, keyStore, alias, memUsageSetting); + } + catch (IOException ioe) + { + IOUtils.closeQuietly(raFile); + throw ioe; + } + } + + private static PDDocument load(RandomAccessBufferedFileInputStream raFile, String password, + InputStream keyStore, String alias, MemoryUsageSetting memUsageSetting) + throws IOException + { + ScratchFile scratchFile = new ScratchFile(memUsageSetting); + try + { + PDFParser parser = new PDFParser(raFile, password, keyStore, alias, scratchFile); + return parser.parse(); + } + catch (IOException ioe) + { + IOUtils.closeQuietly(scratchFile); + throw ioe; + } + } + + /** + * Parses a PDF. The given input stream is copied to the memory to enable random access to the pdf. Unrestricted + * main memory will be used for buffering PDF streams. + * + * @param input stream that contains the document. Don't forget to close it after loading. + * + * @return loaded document + * + * @throws InvalidPasswordException If the PDF required a non-empty password. + * @throws IOException In case of a reading or parsing error. + */ + public static PDDocument load(InputStream input) throws IOException + { + return load(input, "", null, null, MemoryUsageSetting.setupMainMemoryOnly()); + } + + /** + * Parses a PDF. Depending on the memory settings parameter the given input stream is either copied to main memory + * or to a temporary file to enable random access to the pdf. + * + * @param input stream that contains the document. Don't forget to close it after loading. + * @param memUsageSetting defines how memory is used for buffering input stream and PDF streams + * + * @return loaded document + * + * @throws InvalidPasswordException If the PDF required a non-empty password. + * @throws IOException In case of a reading or parsing error. + */ + public static PDDocument load(InputStream input, MemoryUsageSetting memUsageSetting) + throws IOException + { + return load(input, "", null, null, memUsageSetting); + } + + /** + * Parses a PDF. The given input stream is copied to the memory to enable random access to the pdf. Unrestricted + * main memory will be used for buffering PDF streams. * - * @return The document at the PD layer. + * @param input stream that contains the document. Don't forget to close it after loading. + * @param password password to be used for decryption * - * @throws IOException If there is an error getting the document. + * @return loaded document + * + * @throws InvalidPasswordException If the password is incorrect. + * @throws IOException In case of a reading or parsing error. */ - public PDDocument getPDDocument() throws IOException + public static PDDocument load(InputStream input, String password) throws IOException { - PDDocument doc = new PDDocument(getDocument(), source, getAccessPermission()); - doc.setEncryptionDictionary(getEncryption()); - return doc; + return load(input, password, null, null, MemoryUsageSetting.setupMainMemoryOnly()); + } + + /** + * Parses a PDF. The given input stream is copied to the memory to enable random access to the pdf. Unrestricted + * main memory will be used for buffering PDF streams. + * + * @param input stream that contains the document. Don't forget to close it after loading. + * @param password password to be used for decryption + * @param keyStore key store to be used for decryption when using public key security + * @param alias alias to be used for decryption when using public key security + * + * @return loaded document + * + * @throws IOException In case of a reading or parsing error. + */ + public static PDDocument load(InputStream input, String password, InputStream keyStore, + String alias) throws IOException + { + return load(input, password, keyStore, alias, MemoryUsageSetting.setupMainMemoryOnly()); + } + + /** + * Parses a PDF. Depending on the memory settings parameter the given input stream is either copied to main memory + * or to a temporary file to enable random access to the pdf. + * + * @param input stream that contains the document. Don't forget to close it after loading. + * @param password password to be used for decryption + * @param memUsageSetting defines how memory is used for buffering input stream and PDF streams + * + * @return loaded document + * + * @throws InvalidPasswordException If the password is incorrect. + * @throws IOException In case of a reading or parsing error. + */ + public static PDDocument load(InputStream input, String password, + MemoryUsageSetting memUsageSetting) throws IOException + { + return load(input, password, null, null, memUsageSetting); + } + + /** + * Parses a PDF. Depending on the memory settings parameter the given input stream is either copied to memory or to + * a temporary file to enable random access to the pdf. + * + * @param input stream that contains the document. Don't forget to close it after loading. + * @param password password to be used for decryption + * @param keyStore key store to be used for decryption when using public key security + * @param alias alias to be used for decryption when using public key security + * @param memUsageSetting defines how memory is used for buffering input stream and PDF streams + * + * @return loaded document + * + * @throws InvalidPasswordException If the password is incorrect. + * @throws IOException In case of a reading or parsing error. + */ + public static PDDocument load(InputStream input, String password, InputStream keyStore, + String alias, MemoryUsageSetting memUsageSetting) throws IOException + { + ScratchFile scratchFile = new ScratchFile(memUsageSetting); + try + { + RandomAccessRead source = scratchFile.createBuffer(input); + PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile); + return parser.parse(); + } + catch (IOException ioe) + { + IOUtils.closeQuietly(scratchFile); + throw ioe; + } } /** @@ -170,25 +481,16 @@ protected void initialParse() throws IOException { COSDictionary trailer = retrieveTrailer(); - COSBase base = parseTrailerValuesDynamically(trailer); - if (!(base instanceof COSDictionary)) + COSDictionary root = trailer.getCOSDictionary(COSName.ROOT); + if (root == null) { - throw new IOException("Expected root dictionary, but got this: " + base); + throw new IOException("Missing root object specification in trailer."); } - COSDictionary root = (COSDictionary) base; // in some pdfs the type value "Catalog" is missing in the root object if (isLenient() && !root.containsKey(COSName.TYPE)) { root.setItem(COSName.TYPE, COSName.CATALOG); } - // parse all objects, starting at the root dictionary - parseDictObjects(root, (COSName[]) null); - // parse all objects of the info dictionary - COSBase infoBase = trailer.getDictionaryObject(COSName.INFO); - if (infoBase instanceof COSDictionary) - { - parseDictObjects((COSDictionary) infoBase, (COSName[]) null); - } // check pages dictionaries checkPages(root); document.setDecrypted(); @@ -196,19 +498,32 @@ protected void initialParse() throws IOException } /** - * This will parse the stream and populate the COSDocument object. This will close - * the keystore stream when it is done parsing. + * This will parse the stream and populate the PDDocument object. This will close the keystore stream when it is + * done parsing. Lenient mode is active by default. * * @throws InvalidPasswordException If the password is incorrect. - * @throws IOException If there is an error reading from the stream or corrupt data - * is found. + * @throws IOException If there is an error reading from the stream or corrupt data is found. */ - public void parse() throws IOException + public PDDocument parse() throws IOException { - // set to false if all is processed - boolean exceptionOccurred = true; - try - { + return parse(true); + } + + /** + * This will parse the stream and populate the PDDocument object. This will close the keystore stream when it is + * done parsing. + * + * @param lenient activate leniency if set to true + * @throws InvalidPasswordException If the password is incorrect. + * @throws IOException If there is an error reading from the stream or corrupt data is found. + */ + public PDDocument parse(boolean lenient) throws IOException + { + setLenient(lenient); + // set to false if all is processed + boolean exceptionOccurred = true; + try + { // PDFBOX-1922 read the version header and rewind if (!parsePDFHeader() && !parseFDFHeader()) { @@ -220,6 +535,9 @@ public void parse() throws IOException initialParse(); } exceptionOccurred = false; + PDDocument pdDocument = createDocument(); + pdDocument.setEncryptionDictionary(getEncryption()); + return pdDocument; } finally { @@ -231,4 +549,14 @@ public void parse() throws IOException } } + /** + * Create the resulting document. Maybe overwritten if the parser uses another class as document. + * + * @return the resulting document + * @throws IOException if the method is called before parsing the document + */ + protected PDDocument createDocument() throws IOException + { + return new PDDocument(getDocument(), source, getAccessPermission()); + } } diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java index 6647b635e51..1c206174051 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java @@ -191,7 +191,7 @@ else if( next.equals( "false" ) ) String line = readString(); if( line.equals( "R" ) ) { - retval = new COSObject( null ); + retval = new COSObject(null); } else { @@ -295,8 +295,8 @@ else if( next.equals( "false" ) ) while( !(lastByte == 'E' && currentByte == 'I' && hasNextSpaceOrReturn() && - hasNoFollowingBinData(seqSource)) && - !seqSource.isEOF() ) + hasNoFollowingBinData()) && + !isEOF()) { imageData.write( lastByte ); lastByte = currentByte; @@ -344,10 +344,10 @@ else if( next.equals( "false" ) ) * @return true if next bytes are probably printable ASCII * characters starting with a PDF operator, otherwise false */ - private boolean hasNoFollowingBinData(SequentialSource pdfSource) throws IOException + private boolean hasNoFollowingBinData() throws IOException { // as suggested in PDFBOX-1164 - final int readBytes = pdfSource.read(binCharTestArr, 0, MAX_BIN_CHAR_TEST_LENGTH); + final int readBytes = seqSource.read(binCharTestArr, 0, MAX_BIN_CHAR_TEST_LENGTH); boolean noBinData = true; int startOpIdx = -1; int endOpIdx = -1; @@ -399,12 +399,12 @@ else if (startOpIdx != -1 && endOpIdx == -1 && noBinData = false; } } - pdfSource.unread(binCharTestArr, 0, readBytes); + seqSource.unread(binCharTestArr, 0, readBytes); } if (!noBinData) { LOG.warn("ignoring 'EI' assumed to be in the middle of inline image at stream offset " + - pdfSource.getPosition()); + seqSource.getPosition()); } return noBinData; } diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFXrefStreamParser.java b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFXrefStreamParser.java index 3c383e1fa36..bff5ede8731 100755 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFXrefStreamParser.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFXrefStreamParser.java @@ -118,7 +118,7 @@ public void parse() throws IOException int w2 = wArray.getInt(2, 0); int lineSize = w0 + w1 + w2; - while (!seqSource.isEOF() && objIter.hasNext()) + while (!isEOF() && objIter.hasNext()) { byte[] currLine = new byte[lineSize]; seqSource.read(currLine); diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java b/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java index 4ac07b8611d..ba19e6f56c7 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java @@ -60,8 +60,8 @@ import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.io.RandomAccessInputStream; import org.apache.pdfbox.io.RandomAccessRead; -import org.apache.pdfbox.pdfparser.PDFXRefStream; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFXRefStream; import org.apache.pdfbox.pdmodel.encryption.SecurityHandler; import org.apache.pdfbox.pdmodel.fdf.FDFDocument; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.COSFilterInputStream; diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java index c95b3aba34c..d1661266fd8 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java @@ -25,7 +25,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; @@ -33,6 +32,8 @@ import java.util.Iterator; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.fontbox.ttf.TrueTypeFont; @@ -46,17 +47,13 @@ import org.apache.pdfbox.cos.COSUpdateInfo; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.io.MemoryUsageSetting; -import org.apache.pdfbox.io.RandomAccessBuffer; -import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream; import org.apache.pdfbox.io.RandomAccessRead; import org.apache.pdfbox.io.ScratchFile; -import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdfwriter.COSWriter; import org.apache.pdfbox.pdmodel.common.COSArrayList; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.common.PDStream; import org.apache.pdfbox.pdmodel.encryption.AccessPermission; -import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException; import org.apache.pdfbox.pdmodel.encryption.PDEncryption; import org.apache.pdfbox.pdmodel.encryption.ProtectionPolicy; import org.apache.pdfbox.pdmodel.encryption.SecurityHandler; @@ -535,41 +532,40 @@ private void prepareVisibleSignature(PDSignatureField signatureField, PDAcroForm COSDocument visualSignature) { // Obtain visual signature object - boolean annotNotFound = true; - boolean sigFieldNotFound = true; - for (COSObject cosObject : visualSignature.getObjects()) + boolean annotFound = false; + boolean sigFieldFound = false; + // get all objects + List cosObjects = visualSignature.getXrefTable().keySet().stream() // + .map(visualSignature::getObjectFromPool) // + .collect(Collectors.toList()); + for (COSObject cosObject : cosObjects) { - if (!annotNotFound && !sigFieldNotFound) - { - break; - } - COSBase base = cosObject.getObject(); if (base instanceof COSDictionary) { COSDictionary cosBaseDict = (COSDictionary) base; - // Search for signature annotation - COSBase type = cosBaseDict.getDictionaryObject(COSName.TYPE); - if (annotNotFound && COSName.ANNOT.equals(type)) + if (!annotFound && COSName.ANNOT.equals(cosBaseDict.getCOSName(COSName.TYPE))) { assignSignatureRectangle(signatureField, cosBaseDict); - annotNotFound = false; + annotFound = true; } - // Search for signature field - COSBase fieldType = cosBaseDict.getDictionaryObject(COSName.FT); - COSBase apDict = cosBaseDict.getDictionaryObject(COSName.AP); - if (sigFieldNotFound && COSName.SIG.equals(fieldType) && apDict instanceof COSDictionary) + COSDictionary apDict = cosBaseDict.getCOSDictionary(COSName.AP); + if (apDict != null && !sigFieldFound + && COSName.SIG.equals(cosBaseDict.getCOSName(COSName.FT))) { - assignAppearanceDictionary(signatureField, (COSDictionary) apDict); + assignAppearanceDictionary(signatureField, apDict); assignAcroFormDefaultResource(acroForm, cosBaseDict); - sigFieldNotFound = false; + sigFieldFound = true; + } + if (annotFound && sigFieldFound) + { + break; } } } - - if (annotNotFound || sigFieldNotFound) + if (!annotFound || !sigFieldFound) { throw new IllegalArgumentException("Template is missing required objects"); } @@ -891,337 +887,6 @@ Set getFontsToSubset() { return fontsToSubset; } - - /** - * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. - * - * @param file file to be loaded - * - * @return loaded document - * - * @throws InvalidPasswordException If the file required a non-empty password. - * @throws IOException in case of a file reading or parsing error - */ - public static PDDocument load(File file) throws IOException - { - return load(file, "", MemoryUsageSetting.setupMainMemoryOnly()); - } - - /** - * Parses a PDF. - * - * @param file file to be loaded - * @param memUsageSetting defines how memory is used for buffering PDF streams - * - * @return loaded document - * - * @throws InvalidPasswordException If the file required a non-empty password. - * @throws IOException in case of a file reading or parsing error - */ - public static PDDocument load(File file, MemoryUsageSetting memUsageSetting) - throws IOException - { - return load(file, "", null, null, memUsageSetting); - } - - /** - * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. - * - * @param file file to be loaded - * @param password password to be used for decryption - * - * @return loaded document - * - * @throws InvalidPasswordException If the password is incorrect. - * @throws IOException in case of a file reading or parsing error - */ - public static PDDocument load(File file, String password) - throws IOException - { - return load(file, password, null, null, MemoryUsageSetting.setupMainMemoryOnly()); - } - - /** - * Parses a PDF. - * - * @param file file to be loaded - * @param password password to be used for decryption - * @param memUsageSetting defines how memory is used for buffering PDF streams - * - * @return loaded document - * - * @throws InvalidPasswordException If the password is incorrect. - * @throws IOException in case of a file reading or parsing error - */ - public static PDDocument load(File file, String password, MemoryUsageSetting memUsageSetting) - throws IOException - { - return load(file, password, null, null, memUsageSetting); - } - - /** - * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. - * - * @param file file to be loaded - * @param password password to be used for decryption - * @param keyStore key store to be used for decryption when using public key security - * @param alias alias to be used for decryption when using public key security - * - * @return loaded document - * - * @throws IOException in case of a file reading or parsing error - */ - public static PDDocument load(File file, String password, InputStream keyStore, String alias) - throws IOException - { - return load(file, password, keyStore, alias, MemoryUsageSetting.setupMainMemoryOnly()); - } - - /** - * Parses a PDF. - * - * @param file file to be loaded - * @param password password to be used for decryption - * @param keyStore key store to be used for decryption when using public key security - * @param alias alias to be used for decryption when using public key security - * @param memUsageSetting defines how memory is used for buffering PDF streams - * - * @return loaded document - * - * @throws IOException in case of a file reading or parsing error - */ - public static PDDocument load(File file, String password, InputStream keyStore, String alias, - MemoryUsageSetting memUsageSetting) throws IOException - { - @SuppressWarnings({"squid:S2095"}) // raFile not closed here, may be needed for signing - RandomAccessBufferedFileInputStream raFile = new RandomAccessBufferedFileInputStream(file); - try - { - return load(raFile, password, keyStore, alias, memUsageSetting); - } - catch (IOException ioe) - { - IOUtils.closeQuietly(raFile); - throw ioe; - } - } - - private static PDDocument load(RandomAccessBufferedFileInputStream raFile, String password, - InputStream keyStore, String alias, - MemoryUsageSetting memUsageSetting) throws IOException - { - ScratchFile scratchFile = new ScratchFile(memUsageSetting); - try - { - PDFParser parser = new PDFParser(raFile, password, keyStore, alias, scratchFile); - parser.parse(); - return parser.getPDDocument(); - } - catch (IOException ioe) - { - IOUtils.closeQuietly(scratchFile); - throw ioe; - } - } - - /** - * Parses a PDF. The given input stream is copied to the memory to enable random access to the - * pdf. Unrestricted main memory will be used for buffering PDF streams. - * - * @param input stream that contains the document. Don't forget to close it after loading. - * - * @return loaded document - * - * @throws InvalidPasswordException If the PDF required a non-empty password. - * @throws IOException In case of a reading or parsing error. - */ - public static PDDocument load(InputStream input) throws IOException - { - return load(input, "", null, null, MemoryUsageSetting.setupMainMemoryOnly()); - } - - /** - * Parses a PDF. Depending on the memory settings parameter the given input stream is either - * copied to main memory or to a temporary file to enable random access to the pdf. - * - * @param input stream that contains the document. Don't forget to close it after loading. - * @param memUsageSetting defines how memory is used for buffering input stream and PDF streams - * - * @return loaded document - * - * @throws InvalidPasswordException If the PDF required a non-empty password. - * @throws IOException In case of a reading or parsing error. - */ - public static PDDocument load(InputStream input, MemoryUsageSetting memUsageSetting) - throws IOException - { - return load(input, "", null, null, memUsageSetting); - } - - /** - * Parses a PDF. The given input stream is copied to the memory to enable random access to the - * pdf. Unrestricted main memory will be used for buffering PDF streams. - * - * @param input stream that contains the document. Don't forget to close it after loading. - * @param password password to be used for decryption - * - * @return loaded document - * - * @throws InvalidPasswordException If the password is incorrect. - * @throws IOException In case of a reading or parsing error. - */ - public static PDDocument load(InputStream input, String password) - throws IOException - { - return load(input, password, null, null, MemoryUsageSetting.setupMainMemoryOnly()); - } - - /** - * Parses a PDF. The given input stream is copied to the memory to enable random access to the - * pdf. Unrestricted main memory will be used for buffering PDF streams. - * - * @param input stream that contains the document. Don't forget to close it after loading. - * @param password password to be used for decryption - * @param keyStore key store to be used for decryption when using public key security - * @param alias alias to be used for decryption when using public key security - * - * @return loaded document - * - * @throws IOException In case of a reading or parsing error. - */ - public static PDDocument load(InputStream input, String password, InputStream keyStore, String alias) - throws IOException - { - return load(input, password, keyStore, alias, MemoryUsageSetting.setupMainMemoryOnly()); - } - - /** - * Parses a PDF. Depending on the memory settings parameter the given input stream is either - * copied to main memory or to a temporary file to enable random access to the pdf. - * - * @param input stream that contains the document. Don't forget to close it after loading. - * @param password password to be used for decryption - * @param memUsageSetting defines how memory is used for buffering input stream and PDF streams - * - * @return loaded document - * - * @throws InvalidPasswordException If the password is incorrect. - * @throws IOException In case of a reading or parsing error. - */ - public static PDDocument load(InputStream input, String password, MemoryUsageSetting memUsageSetting) - throws IOException - { - return load(input, password, null, null, memUsageSetting); - } - - /** - * Parses a PDF. Depending on the memory settings parameter the given input stream is either - * copied to memory or to a temporary file to enable random access to the pdf. - * - * @param input stream that contains the document. Don't forget to close it after loading. - * @param password password to be used for decryption - * @param keyStore key store to be used for decryption when using public key security - * @param alias alias to be used for decryption when using public key security - * @param memUsageSetting defines how memory is used for buffering input stream and PDF streams - * - * @return loaded document - * - * @throws InvalidPasswordException If the password is incorrect. - * @throws IOException In case of a reading or parsing error. - */ - public static PDDocument load(InputStream input, String password, InputStream keyStore, - String alias, MemoryUsageSetting memUsageSetting) throws IOException - { - ScratchFile scratchFile = new ScratchFile(memUsageSetting); - try - { - RandomAccessRead source = scratchFile.createBuffer(input); - PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile); - parser.parse(); - return parser.getPDDocument(); - } - catch (IOException ioe) - { - IOUtils.closeQuietly(scratchFile); - throw ioe; - } - } - - /** - * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. - * - * @param input byte array that contains the document. - * - * @return loaded document - * - * @throws InvalidPasswordException If the PDF required a non-empty password. - * @throws IOException In case of a reading or parsing error. - */ - public static PDDocument load(byte[] input) throws IOException - { - return load(input, ""); - } - - /** - * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. - * - * @param input byte array that contains the document. - * @param password password to be used for decryption - * - * @return loaded document - * - * @throws InvalidPasswordException If the password is incorrect. - * @throws IOException In case of a reading or parsing error. - */ - public static PDDocument load(byte[] input, String password) - throws IOException - { - return load(input, password, null, null); - } - - /** - * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams. - * - * @param input byte array that contains the document. - * @param password password to be used for decryption - * @param keyStore key store to be used for decryption when using public key security - * @param alias alias to be used for decryption when using public key security - * - * @return loaded document - * - * @throws InvalidPasswordException If the password is incorrect. - * @throws IOException In case of a reading or parsing error. - */ - public static PDDocument load(byte[] input, String password, InputStream keyStore, - String alias) throws IOException - { - return load(input, password, keyStore, alias, MemoryUsageSetting.setupMainMemoryOnly()); - } - - /** - * Parses a PDF. - * - * @param input byte array that contains the document. - * @param password password to be used for decryption - * @param keyStore key store to be used for decryption when using public key security - * @param alias alias to be used for decryption when using public key security - * @param memUsageSetting defines how memory is used for buffering input stream and PDF streams - * - * @return loaded document - * - * @throws InvalidPasswordException If the password is incorrect. - * @throws IOException In case of a reading or parsing error. - */ - public static PDDocument load(byte[] input, String password, InputStream keyStore, - String alias, MemoryUsageSetting memUsageSetting) throws IOException - { - ScratchFile scratchFile = new ScratchFile(memUsageSetting); - RandomAccessRead source = new RandomAccessBuffer(input); - PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile); - parser.parse(); - return parser.getPDDocument(); - } - /** * Save the document to a file. * diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunction.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunction.java index e22341a4296..1661b14096a 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunction.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunction.java @@ -244,7 +244,7 @@ public void setDomainValues(COSArray domainValues) * @return The of outputs the function returns based on those inputs. * In many cases will be an array of a single value, but not always. * - * @throws IOException if something went wrong processing the function. + * @throws IOException is thrown if something went wrong processing the function. */ public abstract float[] eval(float[] input) throws IOException; diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDMarkedContentReference.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDMarkedContentReference.java index 718248377ee..14687fef901 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDMarkedContentReference.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDMarkedContentReference.java @@ -31,7 +31,7 @@ public class PDMarkedContentReference implements COSObjectable public static final String TYPE = "MCR"; private final COSDictionary dictionary; - + /** * Default constructor */ diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java index 2494a60f84c..b3d3c110297 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java @@ -16,13 +16,10 @@ */ package org.apache.pdfbox.pdmodel.fdf; -import java.io.BufferedInputStream; import java.io.BufferedWriter; import java.io.Closeable; import java.io.File; -import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; @@ -32,9 +29,7 @@ import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.cos.COSName; -import org.apache.pdfbox.pdfparser.FDFParser; import org.apache.pdfbox.pdfwriter.COSWriter; -import org.apache.pdfbox.util.XMLUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -154,96 +149,6 @@ public final void setCatalog(FDFCatalog cat) trailer.setItem(COSName.ROOT, cat); } - /** - * This will load a document from a file. - * - * @param filename The name of the file to load. - * - * @return The document that was loaded. - * - * @throws IOException If there is an error reading from the stream. - */ - public static FDFDocument load(String filename) throws IOException - { - FDFParser parser = new FDFParser(filename); - parser.parse(); - return new FDFDocument(parser.getDocument()); - } - - /** - * This will load a document from a file. - * - * @param file The name of the file to load. - * - * @return The document that was loaded. - * - * @throws IOException If there is an error reading from the stream. - */ - public static FDFDocument load(File file) throws IOException - { - FDFParser parser = new FDFParser(file); - parser.parse(); - return new FDFDocument(parser.getDocument()); - } - - /** - * This will load a document from an input stream. - * - * @param input The stream that contains the document. - * - * @return The document that was loaded. - * - * @throws IOException If there is an error reading from the stream. - */ - public static FDFDocument load(InputStream input) throws IOException - { - FDFParser parser = new FDFParser(input); - parser.parse(); - return new FDFDocument(parser.getDocument()); - } - - /** - * This will load a document from a file. - * - * @param filename The name of the file to load. - * - * @return The document that was loaded. - * - * @throws IOException If there is an error reading from the stream. - */ - public static FDFDocument loadXFDF(String filename) throws IOException - { - return loadXFDF(new BufferedInputStream(new FileInputStream(filename))); - } - - /** - * This will load a document from a file. - * - * @param file The name of the file to load. - * - * @return The document that was loaded. - * - * @throws IOException If there is an error reading from the stream. - */ - public static FDFDocument loadXFDF(File file) throws IOException - { - return loadXFDF(new BufferedInputStream(new FileInputStream(file))); - } - - /** - * This will load a document from an input stream. - * - * @param input The stream that contains the document. - * - * @return The document that was loaded. - * - * @throws IOException If there is an error reading from the stream. - */ - public static FDFDocument loadXFDF(InputStream input) throws IOException - { - return new FDFDocument(XMLUtil.parse(input)); - } - /** * This will save this document to the filesystem. * diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java index f933a8706f1..349534768cc 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java @@ -374,7 +374,6 @@ private void saveDiskCache() try { File file = getDiskCacheFile(); - try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { for (FSFontInfo fontInfo : fontInfoList) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDAbstractAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDAbstractAppearanceHandler.java index dc24d8352d8..cf70f648536 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDAbstractAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDAbstractAppearanceHandler.java @@ -24,13 +24,13 @@ import java.util.Set; import org.apache.pdfbox.cos.COSStream; +import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.graphics.color.PDColor; import org.apache.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; -import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLine; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary; diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java index efb0f30ee63..ae7528b7e1a 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCaretAppearanceHandler.java @@ -19,11 +19,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.cos.COSName; +import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationCaret; import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; -import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.util.Matrix; /** @@ -117,4 +117,4 @@ public void generateDownAppearance() { // TODO to be implemented } -} \ No newline at end of file +} diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java index 2c6abcb16af..56f6c4593df 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDCircleAppearanceHandler.java @@ -23,11 +23,11 @@ import org.apache.pdfbox.cos.COSArray; import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSNumber; +import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationCircle; import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; -import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationMarkup; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream; import org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary; diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDFreeTextAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDFreeTextAppearanceHandler.java index a59fd611585..d5c3f9fd186 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDFreeTextAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDFreeTextAppearanceHandler.java @@ -28,9 +28,9 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSNumber; import org.apache.pdfbox.cos.COSObject; +import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdfparser.PDFStreamParser; import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; -import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.font.PDFont; @@ -44,6 +44,7 @@ import static org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLine.LE_NONE; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream; import org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary; +import static org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDAbstractAppearanceHandler.SHORT_STYLES; import org.apache.pdfbox.pdmodel.interactive.annotation.layout.AppearanceStyle; import org.apache.pdfbox.pdmodel.interactive.annotation.layout.PlainText; import org.apache.pdfbox.pdmodel.interactive.annotation.layout.PlainTextFormatter; diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDHighlightAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDHighlightAppearanceHandler.java index c17c1247630..39edc4368bb 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDHighlightAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDHighlightAppearanceHandler.java @@ -22,6 +22,7 @@ import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSStream; +import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDFormContentStream; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.common.PDRectangle; @@ -32,7 +33,6 @@ import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationHighlight; import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; -import org.apache.pdfbox.pdmodel.PDDocument; /** * diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDInkAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDInkAppearanceHandler.java index 0fc2658b9ba..a3f31cd13bb 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDInkAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDInkAppearanceHandler.java @@ -22,8 +22,8 @@ import org.apache.pdfbox.pdmodel.graphics.color.PDColor; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationInk; -import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; /** * Handler to generate the ink annotations appearance. @@ -114,4 +114,4 @@ public void generateDownAppearance() { // No down appearance generated } -} \ No newline at end of file +} diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLineAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLineAppearanceHandler.java index 9ed54dc22bf..52d36d471dd 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLineAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLineAppearanceHandler.java @@ -24,9 +24,11 @@ import org.apache.pdfbox.pdmodel.graphics.color.PDColor; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLine; -import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; + import static org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLine.LE_NONE; +import static org.apache.pdfbox.pdmodel.interactive.annotation.handlers.PDAbstractAppearanceHandler.ANGLED_STYLES; import org.apache.pdfbox.util.Matrix; /** diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLinkAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLinkAppearanceHandler.java index 35e4908af47..99cc361eb0c 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLinkAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDLinkAppearanceHandler.java @@ -24,13 +24,13 @@ import org.apache.pdfbox.cos.COSArray; import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSNumber; +import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.graphics.color.PDColor; import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink; import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; -import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary; /** diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolygonAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolygonAppearanceHandler.java index 9f137843392..b2f33a8607e 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolygonAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolygonAppearanceHandler.java @@ -24,11 +24,11 @@ import org.apache.pdfbox.cos.COSArray; import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSNumber; +import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationPolygon; import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; -import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationMarkup; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream; import org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary; diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java index 35b8be91713..b573d3ee585 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDPolylineAppearanceHandler.java @@ -23,12 +23,13 @@ import org.apache.pdfbox.cos.COSArray; import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSNumber; +import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.graphics.color.PDColor; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationPolyline; import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; -import org.apache.pdfbox.pdmodel.PDDocument; + import static org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLine.LE_NONE; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationMarkup; import org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary; diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSoundAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSoundAppearanceHandler.java index 09c0439a2b4..2c877dabbfd 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSoundAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSoundAppearanceHandler.java @@ -15,11 +15,15 @@ */ package org.apache.pdfbox.pdmodel.interactive.annotation.handlers; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; public class PDSoundAppearanceHandler extends PDAbstractAppearanceHandler { + private static final Log LOG = LogFactory.getLog(PDSoundAppearanceHandler.class); + public PDSoundAppearanceHandler(PDAnnotation annotation) { super(annotation); diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java index c76e6ec5c6c..f89cc28265d 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquareAppearanceHandler.java @@ -24,11 +24,11 @@ import org.apache.pdfbox.cos.COSArray; import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSNumber; +import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquare; import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; -import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationMarkup; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream; import org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderEffectDictionary; diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquigglyAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquigglyAppearanceHandler.java index a8deeea1e70..db80e1c4768 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquigglyAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDSquigglyAppearanceHandler.java @@ -21,8 +21,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.cos.COSName; -import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; import org.apache.pdfbox.pdmodel.PDFormContentStream; import org.apache.pdfbox.pdmodel.PDPatternContentStream; import org.apache.pdfbox.pdmodel.PDResources; diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDStrikeoutAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDStrikeoutAppearanceHandler.java index 8b4a21f2ac5..0c16d543bad 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDStrikeoutAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDStrikeoutAppearanceHandler.java @@ -23,8 +23,8 @@ import org.apache.pdfbox.pdmodel.graphics.color.PDColor; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationStrikeout; -import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; /** * diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDTextAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDTextAppearanceHandler.java index 80053c9ff2b..9ff4c99de84 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDTextAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDTextAppearanceHandler.java @@ -24,8 +24,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.cos.COSName; -import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.font.PDType1Font; import org.apache.pdfbox.pdmodel.graphics.blend.BlendMode; diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDUnderlineAppearanceHandler.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDUnderlineAppearanceHandler.java index e91bf602d69..aae4d250a13 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDUnderlineAppearanceHandler.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDUnderlineAppearanceHandler.java @@ -23,8 +23,8 @@ import org.apache.pdfbox.pdmodel.graphics.color.PDColor; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationUnderline; -import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDAppearanceContentStream; /** * diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java index d7671c68ddd..45e78521cb7 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java @@ -97,8 +97,7 @@ private void initFromRandomAccessRead(RandomAccessRead rar) throws IOException { pdfSource = rar; PDFParser parser = new PDFParser(pdfSource); - parser.parse(); - visualSignature = parser.getDocument(); + visualSignature = parser.parse().getDocument(); } /** diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateCreator.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateCreator.java index c309c08bb56..05800b13fe4 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateCreator.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateCreator.java @@ -26,8 +26,8 @@ import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.cos.COSName; -import org.apache.pdfbox.pdfwriter.COSWriter; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfwriter.COSWriter; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.common.PDRectangle; diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSignDesigner.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSignDesigner.java index 75b749ddd59..edda0fc0eb8 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSignDesigner.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSignDesigner.java @@ -28,6 +28,7 @@ import javax.imageio.ImageIO; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; @@ -165,7 +166,7 @@ public PDVisibleSignDesigner(InputStream imageStream) throws IOException private void calculatePageSizeFromFile(String filename, int page) throws IOException { - try (PDDocument document = PDDocument.load(new File(filename))) + try (PDDocument document = PDFParser.load(new File(filename))) { // calculate height and width of document page calculatePageSize(document, page); @@ -174,7 +175,7 @@ private void calculatePageSizeFromFile(String filename, int page) throws IOExcep private void calculatePageSizeFromStream(InputStream documentStream, int page) throws IOException { - try (PDDocument document = PDDocument.load(documentStream)) + try (PDDocument document = PDFParser.load(documentStream)) { // calculate height and width of document page calculatePageSize(document, page); diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java index 594cd901f54..bc5693aaeff 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java @@ -322,7 +322,7 @@ else if (!annotation.isInvisible() && !annotation.isHidden() && { contentStream = new PDPageContentStream(document, page, AppendMode.APPEND, true, !isContentStreamWrapped); isContentStreamWrapped = true; - + PDAppearanceStream appearanceStream = annotation.getNormalAppearanceStream(); PDFormXObject fieldObject = new PDFormXObject(appearanceStream.getCOSObject()); @@ -754,7 +754,7 @@ private boolean resolveNeedsTranslation(PDAppearanceStream appearanceStream) PDResources resources = appearanceStream.getResources(); if (resources != null && resources.getXObjectNames().iterator().hasNext()) - { + { Iterator xObjectNames = resources.getXObjectNames().iterator(); while (xObjectNames.hasNext()) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java b/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java index 5a56b29b301..4d212b3daee 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPageable.java @@ -22,6 +22,7 @@ import java.awt.print.PageFormat; import java.awt.print.Paper; import java.awt.print.Printable; + import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; diff --git a/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java b/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java index bf4983c61cf..bdd500250e1 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java @@ -29,6 +29,7 @@ import java.awt.print.PrinterException; import java.awt.print.PrinterIOException; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; diff --git a/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java b/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java index 36792042b4b..e4387130b00 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java @@ -1456,7 +1456,7 @@ private TransparencyGroup(PDTransparencyGroup form, boolean isSoftMask, Matrix c PDColor backdropColor) throws IOException { Graphics2D savedGraphics = graphics; - Area savedLastClip= lastClip; + Area savedLastClip = lastClip; Shape savedInitialClip = initialClip; // get the CTM x Form Matrix transform diff --git a/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSName.java b/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSName.java index 07aa762ad20..25c2c3ba90f 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSName.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSName.java @@ -18,7 +18,9 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.junit.Assert; import org.junit.Test; @@ -44,7 +46,7 @@ public void PDFBox4076() throws IOException document.save(baos); } - try (PDDocument document = PDDocument.load(baos.toByteArray())) + try (PDDocument document = PDFParser.load(baos.toByteArray())) { COSDictionary catalogDict = document.getDocumentCatalog().getCOSObject(); Assert.assertTrue(catalogDict.containsKey(special)); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java b/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java index 0cbd9a75c98..0a16baf7ad4 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java @@ -29,6 +29,7 @@ import org.apache.pdfbox.io.MemoryUsageSetting; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.encryption.AccessPermission; import org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy; import org.apache.pdfbox.pdmodel.encryption.PublicKeyRecipient; @@ -83,7 +84,7 @@ public class TestPublicKeyEncryption * @return */ @Parameterized.Parameters - public static Collection keyLengths() + public static Collection keyLengths() { return Arrays.asList(40, 128, 256); } @@ -134,7 +135,7 @@ public void setUp() throws Exception keyStore1 = "test1.pfx"; keyStore2 = "test2.pfx"; - document = PDDocument.load(new File(this.getClass().getResource("test.pdf").toURI())); + document = PDFParser.load(new File(this.getClass().getResource("test.pdf").toURI())); text = new PDFTextStripper().getText(document); producer = document.getDocumentInformation().getProducer(); document.setVersion(1.7f); @@ -275,7 +276,7 @@ public void testMultipleRecipients() throws Exception private PDDocument reload(File file, String decryptionPassword, InputStream keyStore) throws IOException, NoSuchAlgorithmException { - PDDocument doc2 = PDDocument.load(file, decryptionPassword, + PDDocument doc2 = PDFParser.load(file, decryptionPassword, keyStore, null, MemoryUsageSetting.setupMainMemoryOnly()); Assert.assertEquals("Extracted text is different", text, diff --git a/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java b/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java index a177a261249..b5d2a4b7629 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java @@ -36,6 +36,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary; import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode; @@ -168,7 +169,7 @@ public void testPermissions() throws IOException private void checkPerms(byte[] inputFileAsByteArray, String password, AccessPermission expectedPermissions) throws IOException { - try (PDDocument doc = PDDocument.load(inputFileAsByteArray, password)) + try (PDDocument doc = PDFParser.load(inputFileAsByteArray, password)) { AccessPermission currentAccessPermission = doc.getCurrentAccessPermission(); @@ -300,7 +301,7 @@ public void testPDFBox4453() throws IOException doc.save(file); } - try (PDDocument doc = PDDocument.load(file)) + try (PDDocument doc = PDFParser.load(file)) { Assert.assertTrue(doc.isEncrypted()); for (int i = 0; i < TESTCOUNT; ++i) @@ -318,7 +319,7 @@ private void testSymmEncrForKeySize(int keyLength, boolean preferAES, String userpassword, String ownerpassword, AccessPermission permission) throws IOException { - PDDocument document = PDDocument.load(inputFileAsByteArray); + PDDocument document = PDFParser.load(inputFileAsByteArray); String prefix = "Simple-"; int numSrcPages = document.getNumberOfPages(); PDFRenderer pdfRenderer = new PDFRenderer(document); @@ -386,7 +387,7 @@ private PDDocument encrypt(int keyLength, boolean preferAES, int sizePriorToEncr sizeEncrypted != sizePriorToEncr); // test with owner password => full permissions - PDDocument encryptedDoc = PDDocument.load(pdfFile, ownerpassword); + PDDocument encryptedDoc = PDFParser.load(pdfFile, ownerpassword); Assert.assertTrue(encryptedDoc.isEncrypted()); Assert.assertTrue(encryptedDoc.getCurrentAccessPermission().isOwnerPermission()); @@ -408,7 +409,7 @@ private PDDocument encrypt(int keyLength, boolean preferAES, int sizePriorToEncr encryptedDoc.close(); // test with user password => restricted permissions - encryptedDoc = PDDocument.load(pdfFile, userpassword); + encryptedDoc = PDFParser.load(pdfFile, userpassword); Assert.assertTrue(encryptedDoc.isEncrypted()); Assert.assertFalse(encryptedDoc.getCurrentAccessPermission().isOwnerPermission()); @@ -420,8 +421,7 @@ private PDDocument encrypt(int keyLength, boolean preferAES, int sizePriorToEncr // extract the embedded file, saves it, and return the extracted saved file private File extractEmbeddedFile(InputStream pdfInputStream, String name) throws IOException { - PDDocument docWithEmbeddedFile; - docWithEmbeddedFile = PDDocument.load(pdfInputStream); + PDDocument docWithEmbeddedFile = PDFParser.load(pdfInputStream); PDDocumentCatalog catalog = docWithEmbeddedFile.getDocumentCatalog(); PDDocumentNameDictionary names = catalog.getNames(); PDEmbeddedFilesNameTreeNode embeddedFiles = names.getEmbeddedFiles(); @@ -450,7 +450,7 @@ private void testSymmEncrForKeySizeInner(int keyLength, boolean preferAES, File embeddedFilePriorToEncryption, String userpassword, String ownerpassword) throws IOException { - PDDocument document = PDDocument.load(inputFileWithEmbeddedFileAsByteArray); + PDDocument document = PDFParser.load(inputFileWithEmbeddedFileAsByteArray); try (PDDocument encryptedDoc = encrypt(keyLength, preferAES, sizePriorToEncr, document, "ContainsEmbedded-", permission, userpassword, ownerpassword)) { File decryptedFile = new File(testResultsDir, "DecryptedContainsEmbedded-" + keyLength + "-bit-" + (preferAES ? "AES" : "RC4") + ".pdf"); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java b/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java index 6fdb57f410e..5db7af92c8d 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java @@ -28,7 +28,7 @@ import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.io.IOUtils; -import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; /** * This will test all of the filters in the PDFBox system. @@ -125,7 +125,7 @@ public void testFilters() throws IOException */ public void testPDFBOX4517() throws IOException { - PDDocument.load(new File("target/pdfs/PDFBOX-4517-cryptfilter.pdf"), + PDFParser.load(new File("target/pdfs/PDFBOX-4517-cryptfilter.pdf"), "userpassword1234"); } diff --git a/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java b/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java index 805cfc01b64..1ef1f3055f2 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java @@ -31,6 +31,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.multipdf.PDFMergerUtility.AcroFormMergeMode; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; import org.apache.pdfbox.pdmodel.interactive.form.PDField; import org.junit.Before; @@ -68,8 +69,10 @@ public void testLegacyModeMerge() throws IOException merger.mergeDocuments(null); merger.setAcroFormMergeMode(AcroFormMergeMode.PDFBOX_LEGACY_MODE); - try (PDDocument compliantDocument = PDDocument.load(new File(IN_DIR,"PDFBoxLegacyMerge-SameMerged.pdf")); - PDDocument toBeCompared = PDDocument.load(new File(OUT_DIR,"PDFBoxLegacyMerge-SameMerged.pdf"))) + try (PDDocument compliantDocument = PDFParser + .load(new File(IN_DIR, "PDFBoxLegacyMerge-SameMerged.pdf")); + PDDocument toBeCompared = PDFParser + .load(new File(OUT_DIR, "PDFBoxLegacyMerge-SameMerged.pdf"))) { PDAcroForm compliantAcroForm = compliantDocument.getDocumentCatalog().getAcroForm(); PDAcroForm toBeComparedAcroForm = toBeCompared.getDocumentCatalog().getAcroForm(); @@ -145,7 +148,7 @@ public void testAnnotsEntry() throws IOException { } // Test merge result - try (PDDocument mergedPDF = PDDocument.load(pdfOutput)) + try (PDDocument mergedPDF = PDFParser.load(pdfOutput)) { assertEquals("There shall be 2 pages", 2, mergedPDF.getNumberOfPages()); @@ -180,7 +183,7 @@ public void testAPEntry() throws IOException { } // Test merge result - try (PDDocument mergedPDF = PDDocument.load(pdfOutput)) + try (PDDocument mergedPDF = PDFParser.load(pdfOutput)) { assertEquals("There shall be 2 pages", 2, mergedPDF.getNumberOfPages()); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java b/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java index 958700e64df..7dc6ed1164a 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java @@ -29,6 +29,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentNameDestinationDictionary; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; import org.junit.Before; @@ -70,7 +71,7 @@ public void testLinkAnnotations() throws IOException { merger.mergeDocuments(null); // Test merge result - PDDocument mergedPDF = PDDocument.load(pdfOutput); + PDDocument mergedPDF = PDFParser.load(pdfOutput); assertEquals("There shall be 6 pages", 6, mergedPDF.getNumberOfPages()); PDDocumentNameDestinationDictionary destinations = mergedPDF.getDocumentCatalog().getDests(); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFCloneUtilityTest.java b/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFCloneUtilityTest.java index d4440ae277d..3c1a54a62cc 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFCloneUtilityTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFCloneUtilityTest.java @@ -19,7 +19,9 @@ import java.io.File; import java.io.IOException; import junit.framework.TestCase; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream.AppendMode; @@ -96,9 +98,9 @@ public void testClonePDFWithCosArrayStream2() throws IOException // save and reload PDF, so that one can see that the files are legit dstDoc.save(TESTDIR + CLONEDST); - PDDocument.load(new File(TESTDIR + CLONESRC)).close(); - PDDocument.load(new File(TESTDIR + CLONESRC), (String)null).close(); - PDDocument.load(new File(TESTDIR + CLONEDST)).close(); - PDDocument.load(new File(TESTDIR + CLONEDST), (String)null).close(); + PDFParser.load(new File(TESTDIR + CLONESRC)).close(); + PDFParser.load(new File(TESTDIR + CLONESRC), (String) null).close(); + PDFParser.load(new File(TESTDIR + CLONEDST)).close(); + PDFParser.load(new File(TESTDIR + CLONEDST), (String) null).close(); } } diff --git a/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java b/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java index 0333c762fbb..532ae1fb306 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java @@ -30,8 +30,6 @@ import java.util.Set; import junit.framework.TestCase; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.fail; import org.apache.pdfbox.cos.COSArray; import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDictionary; @@ -40,6 +38,7 @@ import org.apache.pdfbox.io.MemoryUsageSetting; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageTree; @@ -176,7 +175,8 @@ public void testPDFMergerOpenAction() throws IOException pdfMergerUtility.setDestinationFileName(TARGETTESTDIR + "MergerOpenActionTestResult.pdf"); pdfMergerUtility.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly()); - try (PDDocument mergedDoc = PDDocument.load(new File(TARGETTESTDIR, "MergerOpenActionTestResult.pdf"))) + try (PDDocument mergedDoc = PDFParser + .load(new File(TARGETTESTDIR, "MergerOpenActionTestResult.pdf"))) { PDDocumentCatalog documentCatalog = mergedDoc.getDocumentCatalog(); dest = (PDPageDestination) documentCatalog.getOpenAction(); @@ -193,7 +193,8 @@ public void testPDFMergerOpenAction() throws IOException public void testStructureTreeMerge() throws IOException { PDFMergerUtility pdfMergerUtility = new PDFMergerUtility(); - PDDocument src = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3999-GeneralForbearance.pdf")); + PDDocument src = PDFParser + .load(new File(TARGETPDFDIR, "PDFBOX-3999-GeneralForbearance.pdf")); ElementCounter elementCounter = new ElementCounter(); elementCounter.walk(src.getDocumentCatalog().getStructureTreeRoot().getK()); @@ -202,13 +203,15 @@ public void testStructureTreeMerge() throws IOException assertEquals(134, singleCnt); assertEquals(134, singleSetSize); - PDDocument dst = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3999-GeneralForbearance.pdf")); + PDDocument dst = PDFParser + .load(new File(TARGETPDFDIR, "PDFBOX-3999-GeneralForbearance.pdf")); pdfMergerUtility.appendDocument(dst, src); src.close(); dst.save(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-merged.pdf")); dst.close(); - PDDocument doc = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-merged.pdf")); + PDDocument doc = PDFParser + .load(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-merged.pdf")); // Assume that the merged tree has double element count elementCounter = new ElementCounter(); @@ -229,7 +232,8 @@ public void testStructureTreeMerge() throws IOException public void testStructureTreeMerge2() throws IOException { PDFMergerUtility pdfMergerUtility = new PDFMergerUtility(); - PDDocument doc = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3999-GeneralForbearance.pdf")); + PDDocument doc = PDFParser + .load(new File(TARGETPDFDIR, "PDFBOX-3999-GeneralForbearance.pdf")); doc.getDocumentCatalog().getAcroForm().flatten(); doc.save(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-flattened.pdf")); @@ -242,8 +246,10 @@ public void testStructureTreeMerge2() throws IOException doc.close(); - PDDocument src = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-flattened.pdf")); - PDDocument dst = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-flattened.pdf")); + PDDocument src = PDFParser + .load(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-flattened.pdf")); + PDDocument dst = PDFParser + .load(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-flattened.pdf")); pdfMergerUtility.appendDocument(dst, src); // before solving PDFBOX-3999, the close() below brought // IOException: COSStream has been closed and cannot be read. @@ -251,7 +257,8 @@ public void testStructureTreeMerge2() throws IOException dst.save(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-flattened-merged.pdf")); dst.close(); - doc = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-flattened-merged.pdf")); + doc = PDFParser.load( + new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-flattened-merged.pdf")); checkForPageOrphans(doc); @@ -273,7 +280,7 @@ public void testStructureTreeMerge2() throws IOException public void testStructureTreeMerge3() throws IOException { PDFMergerUtility pdfMergerUtility = new PDFMergerUtility(); - PDDocument src = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf")); + PDDocument src = PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf")); ElementCounter elementCounter = new ElementCounter(); elementCounter.walk(src.getDocumentCatalog().getStructureTreeRoot().getK()); @@ -282,13 +289,13 @@ public void testStructureTreeMerge3() throws IOException assertEquals(25, singleCnt); assertEquals(25, singleSetSize); - PDDocument dst = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf")); + PDDocument dst = PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf")); pdfMergerUtility.appendDocument(dst, src); src.close(); dst.save(new File(TARGETTESTDIR, "PDFBOX-4408-merged.pdf")); dst.close(); - dst = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-4408-merged.pdf")); + dst = PDFParser.load(new File(TARGETTESTDIR, "PDFBOX-4408-merged.pdf")); // Assume that the merged tree has double element count elementCounter = new ElementCounter(); @@ -311,7 +318,7 @@ public void testStructureTreeMerge3() throws IOException public void testStructureTreeMerge4() throws IOException { PDFMergerUtility pdfMergerUtility = new PDFMergerUtility(); - PDDocument src = PDDocument.load(new File(SRCDIR, "PDFBOX-4417-001031.pdf")); + PDDocument src = PDFParser.load(new File(SRCDIR, "PDFBOX-4417-001031.pdf")); ElementCounter elementCounter = new ElementCounter(); elementCounter.walk(src.getDocumentCatalog().getStructureTreeRoot().getK()); @@ -320,12 +327,12 @@ public void testStructureTreeMerge4() throws IOException assertEquals(104, singleCnt); assertEquals(104, singleSetSize); - PDDocument dst = PDDocument.load(new File(SRCDIR, "PDFBOX-4417-001031.pdf")); + PDDocument dst = PDFParser.load(new File(SRCDIR, "PDFBOX-4417-001031.pdf")); pdfMergerUtility.appendDocument(dst, src); src.close(); dst.save(new File(TARGETTESTDIR, "PDFBOX-4417-001031-merged.pdf")); dst.close(); - dst = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-4417-001031-merged.pdf")); + dst = PDFParser.load(new File(TARGETTESTDIR, "PDFBOX-4417-001031-merged.pdf")); // Assume that the merged tree has double element count elementCounter = new ElementCounter(); @@ -348,19 +355,19 @@ public void testStructureTreeMerge4() throws IOException public void testStructureTreeMerge5() throws IOException { PDFMergerUtility pdfMergerUtility = new PDFMergerUtility(); - PDDocument src = PDDocument.load(new File(SRCDIR, "PDFBOX-4417-054080.pdf")); + PDDocument src = PDFParser.load(new File(SRCDIR, "PDFBOX-4417-054080.pdf")); ElementCounter elementCounter = new ElementCounter(); elementCounter.walk(src.getDocumentCatalog().getStructureTreeRoot().getK()); int singleCnt = elementCounter.cnt; int singleSetSize = elementCounter.set.size(); - PDDocument dst = PDDocument.load(new File(SRCDIR, "PDFBOX-4417-054080.pdf")); + PDDocument dst = PDFParser.load(new File(SRCDIR, "PDFBOX-4417-054080.pdf")); pdfMergerUtility.appendDocument(dst, src); src.close(); dst.save(new File(TARGETTESTDIR, "PDFBOX-4417-054080-merged.pdf")); dst.close(); - dst = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-4417-054080-merged.pdf")); + dst = PDFParser.load(new File(TARGETTESTDIR, "PDFBOX-4417-054080-merged.pdf")); checkWithNumberTree(dst); checkForPageOrphans(dst); @@ -383,7 +390,7 @@ public void testStructureTreeMerge5() throws IOException public void testStructureTreeMerge6() throws IOException { PDFMergerUtility pdfMergerUtility = new PDFMergerUtility(); - PDDocument src = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4418-000671.pdf")); + PDDocument src = PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-4418-000671.pdf")); PDStructureTreeRoot structureTreeRoot = src.getDocumentCatalog().getStructureTreeRoot(); PDNumberTreeNode parentTree = structureTreeRoot.getParentTree(); @@ -393,7 +400,7 @@ public void testStructureTreeMerge6() throws IOException assertEquals(0, (int) Collections.min(numberTreeAsMap.keySet())); assertEquals(743, structureTreeRoot.getParentTreeNextKey()); - PDDocument dst = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4418-000314.pdf")); + PDDocument dst = PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-4418-000314.pdf")); structureTreeRoot = dst.getDocumentCatalog().getStructureTreeRoot(); parentTree = structureTreeRoot.getParentTree(); @@ -409,7 +416,7 @@ public void testStructureTreeMerge6() throws IOException dst.save(new File(TARGETTESTDIR, "PDFBOX-4418-merged.pdf")); dst.close(); - dst = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-4418-merged.pdf")); + dst = PDFParser.load(new File(TARGETTESTDIR, "PDFBOX-4418-merged.pdf")); checkWithNumberTree(dst); checkForPageOrphans(dst); @@ -433,7 +440,7 @@ public void testStructureTreeMerge6() throws IOException public void testStructureTreeMerge7() throws IOException { PDFMergerUtility pdfMergerUtility = new PDFMergerUtility(); - PDDocument src = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4423-000746.pdf")); + PDDocument src = PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-4423-000746.pdf")); PDStructureTreeRoot structureTreeRoot = src.getDocumentCatalog().getStructureTreeRoot(); PDNumberTreeNode parentTree = structureTreeRoot.getParentTree(); @@ -450,7 +457,7 @@ public void testStructureTreeMerge7() throws IOException dst.save(new File(TARGETTESTDIR, "PDFBOX-4423-merged.pdf")); dst.close(); - dst = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-4423-merged.pdf")); + dst = PDFParser.load(new File(TARGETTESTDIR, "PDFBOX-4423-merged.pdf")); checkWithNumberTree(dst); checkForPageOrphans(dst); @@ -472,8 +479,8 @@ public void testStructureTreeMerge7() throws IOException public void testMissingParentTreeNextKey() throws IOException { PDFMergerUtility pdfMergerUtility = new PDFMergerUtility(); - PDDocument src = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4418-000314.pdf")); - PDDocument dst = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4418-000314.pdf")); + PDDocument src = PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-4418-000314.pdf")); + PDDocument dst = PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-4418-000314.pdf")); // existing numbers are 321..327; ParentTreeNextKey is 408. // After deletion, it is recalculated in the merge 328. // That value is added to all numbers of the destination, @@ -484,7 +491,7 @@ public void testMissingParentTreeNextKey() throws IOException src.close(); dst.save(new File(TARGETTESTDIR, "PDFBOX-4418-000314-merged.pdf")); dst.close(); - dst = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-4418-000314-merged.pdf")); + dst = PDFParser.load(new File(TARGETTESTDIR, "PDFBOX-4418-000314-merged.pdf")); assertEquals(656, dst.getDocumentCatalog().getStructureTreeRoot().getParentTreeNextKey()); dst.close(); } @@ -499,8 +506,8 @@ public void testMissingParentTreeNextKey() throws IOException public void testStructureTreeMergeIDTree() throws IOException { PDFMergerUtility pdfMergerUtility = new PDFMergerUtility(); - PDDocument src = PDDocument.load(new File(SRCDIR, "PDFBOX-4417-001031.pdf")); - PDDocument dst = PDDocument.load(new File(SRCDIR, "PDFBOX-4417-054080.pdf")); + PDDocument src = PDFParser.load(new File(SRCDIR, "PDFBOX-4417-001031.pdf")); + PDDocument dst = PDFParser.load(new File(SRCDIR, "PDFBOX-4417-054080.pdf")); PDNameTreeNode srcIDTree = src.getDocumentCatalog().getStructureTreeRoot().getIDTree(); Map srcIDTreeMap = PDFMergerUtility.getIDTreeAsMap(srcIDTree); @@ -521,7 +528,7 @@ public void testStructureTreeMergeIDTree() throws IOException src.close(); dst.save(new File(TARGETTESTDIR, "PDFBOX-4416-IDTree-merged.pdf")); dst.close(); - dst = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-4416-IDTree-merged.pdf")); + dst = PDFParser.load(new File(TARGETTESTDIR, "PDFBOX-4416-IDTree-merged.pdf")); checkWithNumberTree(dst); checkForPageOrphans(dst); @@ -542,8 +549,8 @@ public void testStructureTreeMergeIDTree() throws IOException public void testMergeBogusStructParents1() throws IOException { PDFMergerUtility pdfMergerUtility = new PDFMergerUtility(); - PDDocument src = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf")); - PDDocument dst = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf")); + PDDocument src = PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf")); + PDDocument dst = PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf")); dst.getDocumentCatalog().setStructureTreeRoot(null); dst.getPage(0).setStructParents(9999); dst.getPage(0).getAnnotations().get(0).setStructParent(9998); @@ -563,8 +570,8 @@ public void testMergeBogusStructParents1() throws IOException public void testMergeBogusStructParents2() throws IOException { PDFMergerUtility pdfMergerUtility = new PDFMergerUtility(); - PDDocument src = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf")); - PDDocument dst = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf")); + PDDocument src = PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf")); + PDDocument dst = PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf")); src.getDocumentCatalog().setStructureTreeRoot(null); src.getPage(0).setStructParents(9999); src.getPage(0).getAnnotations().get(0).setStructParent(9998); @@ -583,7 +590,8 @@ public void testMergeBogusStructParents2() throws IOException */ public void testParentTree() throws IOException { - PDDocument doc = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3999-GeneralForbearance.pdf")); + PDDocument doc = PDFParser + .load(new File(TARGETPDFDIR, "PDFBOX-3999-GeneralForbearance.pdf")); PDStructureTreeRoot structureTreeRoot = doc.getDocumentCatalog().getStructureTreeRoot(); PDNumberTreeNode parentTree = structureTreeRoot.getParentTree(); parentTree.getValue(0); @@ -855,7 +863,7 @@ private void checkMergeIdentical(String filename1, String filename2, String merg { int src1PageCount; BufferedImage[] src1ImageTab; - try (PDDocument srcDoc1 = PDDocument.load(new File(SRCDIR, filename1), (String) null)) + try (PDDocument srcDoc1 = PDFParser.load(new File(SRCDIR, filename1), (String) null)) { src1PageCount = srcDoc1.getNumberOfPages(); PDFRenderer src1PdfRenderer = new PDFRenderer(srcDoc1); @@ -868,7 +876,7 @@ private void checkMergeIdentical(String filename1, String filename2, String merg int src2PageCount; BufferedImage[] src2ImageTab; - try (PDDocument srcDoc2 = PDDocument.load(new File(SRCDIR, filename2), (String) null)) + try (PDDocument srcDoc2 = PDFParser.load(new File(SRCDIR, filename2), (String) null)) { src2PageCount = srcDoc2.getNumberOfPages(); PDFRenderer src2PdfRenderer = new PDFRenderer(srcDoc2); @@ -885,7 +893,8 @@ private void checkMergeIdentical(String filename1, String filename2, String merg pdfMergerUtility.setDestinationFileName(TARGETTESTDIR + mergeFilename); pdfMergerUtility.mergeDocuments(memUsageSetting); - try (PDDocument mergedDoc = PDDocument.load(new File(TARGETTESTDIR, mergeFilename), (String) null)) + try (PDDocument mergedDoc = PDFParser.load(new File(TARGETTESTDIR, mergeFilename), + (String) null)) { PDFRenderer mergePdfRenderer = new PDFRenderer(mergedDoc); int mergePageCount = mergedDoc.getNumberOfPages(); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PageExtractorTest.java b/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PageExtractorTest.java index 9f14381031d..4190da608c4 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PageExtractorTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PageExtractorTest.java @@ -18,7 +18,9 @@ import java.io.File; import junit.framework.TestCase; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; /** * Test suite for PageExtractor. @@ -72,7 +74,7 @@ public void testExtract() throws Exception try { // this should work for most users - sourcePdf = PDDocument.load(new File("src/test/resources/input/cweb.pdf")); + sourcePdf = PDFParser.load(new File("src/test/resources/input/cweb.pdf")); PageExtractor instance = new PageExtractor(sourcePdf); result = instance.extract(); assertEquals(sourcePdf.getNumberOfPages(), result.getNumberOfPages()); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/multipdf/TestLayerUtility.java b/pdfbox/src/test/java/org/apache/pdfbox/multipdf/TestLayerUtility.java index ee5fb7cc850..31f4550454d 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/multipdf/TestLayerUtility.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/multipdf/TestLayerUtility.java @@ -25,6 +25,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDResources; @@ -65,8 +66,8 @@ public void testLayerImport() throws Exception File overlay1 = createOverlay1(); File targetFile = new File(testResultsDir, "text-with-form-overlay.pdf"); - try (PDDocument targetDoc = PDDocument.load(mainPDF); - PDDocument overlay1Doc = PDDocument.load(overlay1)) + try (PDDocument targetDoc = PDFParser.load(mainPDF); + PDDocument overlay1Doc = PDFParser.load(overlay1)) { LayerUtility layerUtil = new LayerUtility(targetDoc); PDFormXObject form = layerUtil.importPageAsForm(overlay1Doc, 0); @@ -78,7 +79,7 @@ public void testLayerImport() throws Exception targetDoc.save(targetFile.getAbsolutePath()); } - try (PDDocument doc = PDDocument.load(targetFile)) + try (PDDocument doc = PDFParser.load(targetFile)) { PDDocumentCatalog catalog = doc.getDocumentCatalog(); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/EndstreamOutputStreamTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/EndstreamOutputStreamTest.java index 52a69438424..6f0938a1061 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/EndstreamOutputStreamTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/EndstreamOutputStreamTest.java @@ -116,7 +116,7 @@ public void testPDFBox2079EmbeddedFile() throws IOException // Modification of embedded_zip.pdf for 2.0: // /Length entry removed to force usage of EndstreamOutputStream - try (PDDocument doc = PDDocument.load( + try (PDDocument doc = PDFParser.load( new File("src/test/resources/org/apache/pdfbox/pdfparser", "embedded_zip.pdf"))) { PDDocumentCatalog catalog = doc.getDocumentCatalog(); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java b/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java index fa7047d7e4f..25b4365d264 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java @@ -30,7 +30,6 @@ import java.io.IOException; import java.net.URISyntaxException; -import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.io.MemoryUsageSetting; import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream; import org.apache.pdfbox.io.RandomAccessRead; @@ -115,7 +114,8 @@ public void testPDFParserInputStreamScratchFile() throws IOException public void testPDFParserMissingCatalog() throws IOException, URISyntaxException { // PDFBOX-3060 - PDDocument.load(new File(TestPDFParser.class.getResource("MissingCatalog.pdf").toURI())).close(); + PDFParser.load(new File(TestPDFParser.class.getResource("MissingCatalog.pdf").toURI())) + .close(); } /** @@ -128,7 +128,8 @@ public void testPDFParserMissingCatalog() throws IOException, URISyntaxException @Test public void testPDFBox3208() throws IOException { - try (PDDocument doc = PDDocument.load(new File(TARGETPDFDIR,"PDFBOX-3208-L33MUTT2SVCWGCS6UIYL5TH3PNPXHIS6.pdf"))) + try (PDDocument doc = PDFParser + .load(new File(TARGETPDFDIR, "PDFBOX-3208-L33MUTT2SVCWGCS6UIYL5TH3PNPXHIS6.pdf"))) { PDDocumentInformation di = doc.getDocumentInformation(); assertEquals("Liquent Enterprise Services", di.getAuthor()); @@ -151,7 +152,7 @@ public void testPDFBox3208() throws IOException @Test public void testPDFBox3940() throws IOException { - try (PDDocument doc = PDDocument.load(new File(TARGETPDFDIR,"PDFBOX-3940-079977.pdf"))) + try (PDDocument doc = PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-3940-079977.pdf"))) { PDDocumentInformation di = doc.getDocumentInformation(); assertEquals("Unknown", di.getAuthor()); @@ -172,7 +173,8 @@ public void testPDFBox3940() throws IOException @Test public void testPDFBox3783() throws IOException { - PDDocument.load(new File(TARGETPDFDIR,"PDFBOX-3783-72GLBIGUC6LB46ELZFBARRJTLN4RBSQM.pdf")).close(); + PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-3783-72GLBIGUC6LB46ELZFBARRJTLN4RBSQM.pdf")) + .close(); } /** @@ -184,7 +186,7 @@ public void testPDFBox3783() throws IOException @Test public void testPDFBox3785() throws IOException { - try (PDDocument doc = PDDocument.load(new File(TARGETPDFDIR,"PDFBOX-3785-202097.pdf"))) + try (PDDocument doc = PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-3785-202097.pdf"))) { assertEquals(11, doc.getNumberOfPages()); } @@ -198,7 +200,7 @@ public void testPDFBox3785() throws IOException @Test public void testPDFBox3947() throws IOException { - PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3947-670064.pdf")).close(); + PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-3947-670064.pdf")).close(); } /** @@ -209,7 +211,8 @@ public void testPDFBox3947() throws IOException @Test public void testPDFBox3948() throws IOException { - PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3948-EUWO6SQS5TM4VGOMRD3FLXZHU35V2CP2.pdf")).close(); + PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-3948-EUWO6SQS5TM4VGOMRD3FLXZHU35V2CP2.pdf")) + .close(); } /** @@ -220,7 +223,8 @@ public void testPDFBox3948() throws IOException @Test public void testPDFBox3949() throws IOException { - PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3949-MKFYUGZWS3OPXLLVU2Z4LWCTVA5WNOGF.pdf")).close(); + PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-3949-MKFYUGZWS3OPXLLVU2Z4LWCTVA5WNOGF.pdf")) + .close(); } /** @@ -231,7 +235,8 @@ public void testPDFBox3949() throws IOException @Test public void testPDFBox3950() throws IOException { - try (PDDocument doc = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3950-23EGDHXSBBYQLKYOKGZUOVYVNE675PRD.pdf"))) + try (PDDocument doc = PDFParser + .load(new File(TARGETPDFDIR, "PDFBOX-3950-23EGDHXSBBYQLKYOKGZUOVYVNE675PRD.pdf"))) { assertEquals(4, doc.getNumberOfPages()); PDFRenderer renderer = new PDFRenderer(doc); @@ -261,7 +266,8 @@ public void testPDFBox3950() throws IOException @Test public void testPDFBox3951() throws IOException { - try (PDDocument doc = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3951-FIHUZWDDL2VGPOE34N6YHWSIGSH5LVGZ.pdf"))) + try (PDDocument doc = PDFParser + .load(new File(TARGETPDFDIR, "PDFBOX-3951-FIHUZWDDL2VGPOE34N6YHWSIGSH5LVGZ.pdf"))) { assertEquals(143, doc.getNumberOfPages()); } @@ -275,7 +281,8 @@ public void testPDFBox3951() throws IOException @Test public void testPDFBox3964() throws IOException { - try (PDDocument doc = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3964-c687766d68ac766be3f02aaec5e0d713_2.pdf"))) + try (PDDocument doc = PDFParser + .load(new File(TARGETPDFDIR, "PDFBOX-3964-c687766d68ac766be3f02aaec5e0d713_2.pdf"))) { assertEquals(10, doc.getNumberOfPages()); } @@ -290,7 +297,8 @@ public void testPDFBox3964() throws IOException @Test public void testPDFBox3977() throws IOException { - try (PDDocument doc = PDDocument.load(new File(TARGETPDFDIR,"PDFBOX-3977-63NGFQRI44HQNPIPEJH5W2TBM6DJZWMI.pdf"))) + try (PDDocument doc = PDFParser + .load(new File(TARGETPDFDIR, "PDFBOX-3977-63NGFQRI44HQNPIPEJH5W2TBM6DJZWMI.pdf"))) { PDDocumentInformation di = doc.getDocumentInformation(); assertEquals("QuarkXPress(tm) 6.52", di.getCreator()); @@ -309,7 +317,7 @@ public void testPDFBox3977() throws IOException @Test public void testParseGenko() throws IOException { - PDDocument.load(new File(TARGETPDFDIR, "genko_oc_shiryo1.pdf")).close(); + PDFParser.load(new File(TARGETPDFDIR, "genko_oc_shiryo1.pdf")).close(); } /** @@ -321,7 +329,7 @@ public void testParseGenko() throws IOException @Test public void testPDFBox4338() throws IOException { - PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4338.pdf")).close(); + PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-4338.pdf")).close(); } /** @@ -333,15 +341,14 @@ public void testPDFBox4338() throws IOException @Test public void testPDFBox4339() throws IOException { - PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4339.pdf")).close(); + PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-4339.pdf")).close(); } private void executeParserTest(RandomAccessRead source, MemoryUsageSetting memUsageSetting) throws IOException { ScratchFile scratchFile = new ScratchFile(memUsageSetting); PDFParser pdfParser = new PDFParser(source, scratchFile); - pdfParser.parse(); - try (COSDocument doc = pdfParser.getDocument()) + try (PDDocument doc = pdfParser.parse()) { assertNotNull(doc); } diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdfwriter/COSWriterTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdfwriter/COSWriterTest.java index 004a2b79927..e1b80c40831 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdfwriter/COSWriterTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdfwriter/COSWriterTest.java @@ -19,6 +19,7 @@ import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.junit.Test; diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java index 7d87af912f4..e7edb75e552 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java @@ -23,6 +23,10 @@ import java.net.URISyntaxException; import java.util.List; import junit.framework.TestCase; + +import org.apache.pdfbox.pdfparser.FDFParser; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.fdf.FDFDocument; import org.apache.pdfbox.pdmodel.fdf.FDFField; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; @@ -51,7 +55,7 @@ public void testLoad2() throws URISyntaxException, IOException private void checkFields(String name) throws IOException, URISyntaxException { - try (FDFDocument fdf = FDFDocument.load(new File(TestFDF.class.getResource(name).toURI()))) + try (FDFDocument fdf = FDFParser.load(new File(TestFDF.class.getResource(name).toURI()))) { fdf.saveXFDF(new PrintWriter(new ByteArrayOutputStream())); @@ -63,7 +67,8 @@ private void checkFields(String name) throws IOException, URISyntaxException assertEquals("Test1", fields.get(0).getValue()); assertEquals("Test2", fields.get(1).getValue()); - try (PDDocument pdf = PDDocument.load(new File(TestFDF.class.getResource("/org/apache/pdfbox/pdfparser/SimpleForm2Fields.pdf").toURI()))) + try (PDDocument pdf = PDFParser.load(new File(TestFDF.class + .getResource("/org/apache/pdfbox/pdfparser/SimpleForm2Fields.pdf").toURI()))) { PDAcroForm acroForm = pdf.getDocumentCatalog().getAcroForm(); acroForm.importFDF(fdf); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocument.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocument.java index 3055ffeefdb..00f0f339843 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocument.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocument.java @@ -30,6 +30,7 @@ import java.util.Locale; import org.apache.pdfbox.io.IOUtils; +import org.apache.pdfbox.pdfparser.PDFParser; import junit.framework.TestCase; @@ -70,7 +71,7 @@ public void testSaveLoadStream() throws IOException assertEquals("%%EOF\n", new String(Arrays.copyOfRange(pdf, pdf.length - 6, pdf.length), StandardCharsets.UTF_8)); // Load - PDDocument loadDoc = PDDocument.load(new ByteArrayInputStream(pdf)); + PDDocument loadDoc = PDFParser.load(new ByteArrayInputStream(pdf)); assertEquals(1, loadDoc.getNumberOfPages()); loadDoc.close(); } @@ -100,7 +101,7 @@ public void testSaveLoadFile() throws IOException assertEquals("%%EOF\n", new String(Arrays.copyOfRange(pdf, pdf.length - 6, pdf.length), StandardCharsets.UTF_8)); // Load - PDDocument loadDoc = PDDocument.load(targetFile); + PDDocument loadDoc = PDFParser.load(targetFile); assertEquals(1, loadDoc.getNumberOfPages()); loadDoc.close(); } @@ -158,7 +159,7 @@ public void testDeleteBadFile() throws FileNotFoundException PDDocument doc = null; try { - doc = PDDocument.load(f); + doc = PDFParser.load(f); fail("parsing should fail"); } catch (IOException ex) @@ -187,7 +188,7 @@ public void testDeleteGoodFile() throws IOException doc.save(f); doc.close(); - PDDocument.load(f).close(); + PDFParser.load(f).close(); boolean deleted = f.delete(); assertTrue("delete good file failed after successful load() and close()", deleted); @@ -210,7 +211,7 @@ public void testSaveArabicLocale() throws IOException doc.save(baos); doc.close(); - PDDocument.load(new ByteArrayInputStream(baos.toByteArray())).close(); + PDFParser.load(new ByteArrayInputStream(baos.toByteArray())).close(); Locale.setDefault(defaultLocale); } diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentCatalog.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentCatalog.java index 9e5dffba157..8da239c302d 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentCatalog.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentCatalog.java @@ -21,6 +21,8 @@ import java.util.List; import org.apache.pdfbox.cos.COSName; +import org.apache.pdfbox.pdfparser.PDFParser; +import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.graphics.color.PDOutputIntent; import static org.junit.Assert.assertEquals; @@ -51,7 +53,8 @@ public void retrievePageLabels() throws IOException PDDocument doc = null; try { - doc = PDDocument.load(TestPDDocumentCatalog.class.getResourceAsStream("test_pagelabels.pdf")); + doc = PDFParser + .load(TestPDDocumentCatalog.class.getResourceAsStream("test_pagelabels.pdf")); PDDocumentCatalog cat = doc.getDocumentCatalog(); String[] labels = cat.getPageLabels().getLabelsByPageIndices(); assertEquals(12, labels.length); @@ -92,7 +95,8 @@ public void retrievePageLabelsOnMalformedPdf() throws IOException PDDocument doc = null; try { - doc = PDDocument.load(TestPDDocumentCatalog.class.getResourceAsStream("badpagelabels.pdf")); + doc = PDFParser + .load(TestPDDocumentCatalog.class.getResourceAsStream("badpagelabels.pdf")); PDDocumentCatalog cat = doc.getDocumentCatalog(); // getLabelsByPageIndices() should not throw an exception cat.getPageLabels().getLabelsByPageIndices(); @@ -122,7 +126,7 @@ public void retrieveNumberOfPages() throws IOException PDDocument doc = null; try { - doc = PDDocument.load(TestPDDocumentCatalog.class.getResourceAsStream("test.unc.pdf")); + doc = PDFParser.load(TestPDDocumentCatalog.class.getResourceAsStream("test.unc.pdf")); assertEquals(4, doc.getNumberOfPages()); } finally @@ -151,7 +155,7 @@ public void handleOutputIntents() throws IOException try { - doc = PDDocument.load(TestPDDocumentCatalog.class.getResourceAsStream("test.unc.pdf")); + doc = PDFParser.load(TestPDDocumentCatalog.class.getResourceAsStream("test.unc.pdf")); PDDocumentCatalog catalog = doc.getDocumentCatalog(); // retrieve OutputIntents diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java index 4b4c236dade..45b9c751061 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDDocumentInformation.java @@ -20,6 +20,9 @@ import java.util.Arrays; import java.util.List; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; + import junit.framework.TestCase; /** @@ -33,7 +36,7 @@ public class TestPDDocumentInformation extends TestCase public void testMetadataExtraction() throws Exception { // This document has been selected for this test as it contains custom metadata. - try (PDDocument doc = PDDocument.load( new File("src/test/resources/input/hello3.pdf"))) + try (PDDocument doc = PDFParser.load(new File("src/test/resources/input/hello3.pdf"))) { PDDocumentInformation info = doc.getDocumentInformation(); @@ -69,7 +72,8 @@ public void testMetadataExtraction() throws Exception */ public void testPDFBox3068() throws Exception { - try (PDDocument doc = PDDocument.load(TestPDDocumentInformation.class.getResourceAsStream("PDFBOX-3068.pdf"))) + try (PDDocument doc = PDFParser + .load(TestPDDocumentInformation.class.getResourceAsStream("PDFBOX-3068.pdf"))) { PDDocumentInformation documentInformation = doc.getDocumentInformation(); assertEquals("Title", documentInformation.getTitle()); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java index 6ffe7b895e2..6b1f114f550 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.util.List; import junit.framework.TestCase; +import static junit.framework.TestCase.assertEquals; import org.apache.pdfbox.contentstream.operator.Operator; import org.apache.pdfbox.contentstream.operator.OperatorName; import org.apache.pdfbox.cos.COSNumber; diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageTransitions.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageTransitions.java index 88235226385..e616af5c9c7 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageTransitions.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageTransitions.java @@ -24,6 +24,8 @@ import java.net.URISyntaxException; import org.apache.pdfbox.cos.COSName; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.interactive.pagenavigation.PDTransition; import org.apache.pdfbox.pdmodel.interactive.pagenavigation.PDTransitionDirection; import org.apache.pdfbox.pdmodel.interactive.pagenavigation.PDTransitionStyle; @@ -39,7 +41,7 @@ public class TestPDPageTransitions @Test public void readTransitions() throws IOException, URISyntaxException { - try (PDDocument doc = PDDocument.load(new File(this.getClass().getResource( + try (PDDocument doc = PDFParser.load(new File(this.getClass().getResource( "/org/apache/pdfbox/pdmodel/interactive/pagenavigation/transitions_test.pdf").toURI()))) { PDTransition firstTransition = doc.getPages().get(0).getTransition(); @@ -68,7 +70,7 @@ public void saveAndReadTransitions() throws IOException } // read - try (PDDocument doc = PDDocument.load(baos.toByteArray())) + try (PDDocument doc = PDFParser.load(baos.toByteArray())) { PDPage page = doc.getPages().get(0); PDTransition loadedTransition = page.getTransition(); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageTree.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageTree.java index 0ab58c6aef4..aa2e1621d5d 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageTree.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageTree.java @@ -20,6 +20,8 @@ import java.io.IOException; +import org.apache.pdfbox.pdfparser.PDFParser; +import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline; import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem; @@ -46,7 +48,7 @@ public void tearDown() throws IOException @Test public void indexOfPageFromOutlineDestination() throws IOException { - doc = PDDocument.load(TestPDPageTree.class.getResourceAsStream("with_outline.pdf")); + doc = PDFParser.load(TestPDPageTree.class.getResourceAsStream("with_outline.pdf")); PDDocumentOutline outline = doc.getDocumentCatalog().getDocumentOutline(); for (PDOutlineItem current : outline.children()) { @@ -60,7 +62,7 @@ public void indexOfPageFromOutlineDestination() throws IOException @Test public void positiveSingleLevel() throws IOException { - doc = PDDocument.load(TestPDPageTree.class.getResourceAsStream("with_outline.pdf")); + doc = PDFParser.load(TestPDPageTree.class.getResourceAsStream("with_outline.pdf")); for (int i = 0; i < doc.getNumberOfPages(); i++) { assertEquals(i, doc.getPages().indexOf(doc.getPage(i))); @@ -70,7 +72,8 @@ public void positiveSingleLevel() throws IOException @Test public void positiveMultipleLevel() throws IOException { - doc = PDDocument.load(TestPDPageTree.class.getResourceAsStream("page_tree_multiple_levels.pdf")); + doc = PDFParser + .load(TestPDPageTree.class.getResourceAsStream("page_tree_multiple_levels.pdf")); for (int i = 0; i < doc.getNumberOfPages(); i++) { assertEquals(i, doc.getPages().indexOf(doc.getPage(i))); @@ -80,7 +83,7 @@ public void positiveMultipleLevel() throws IOException @Test public void negative() throws IOException { - doc = PDDocument.load(TestPDPageTree.class.getResourceAsStream("with_outline.pdf")); + doc = PDFParser.load(TestPDPageTree.class.getResourceAsStream("with_outline.pdf")); assertEquals(-1, doc.getPages().indexOf(new PDPage())); } } diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java index a00a499fb08..161ab8580c1 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java @@ -28,6 +28,7 @@ import org.apache.pdfbox.cos.COSArray; import org.apache.pdfbox.cos.COSBase; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.interactive.annotation.AnnotationFilter; @@ -326,7 +327,7 @@ public void removeSingleDirectObject() throws IOException { pdf.close(); } - try (PDDocument pdf = PDDocument.load(new File(OUT_DIR + "/removeSingleDirectObjectTest.pdf"))) { + try (PDDocument pdf = PDFParser.load(new File(OUT_DIR + "/removeSingleDirectObjectTest.pdf"))) { PDPage page = pdf.getPage(0); COSArrayList annotations = (COSArrayList) page.getAnnotations(); @@ -366,7 +367,7 @@ public void removeSingleIndirectObject() throws IOException { pdf.close(); } - try (PDDocument pdf = PDDocument.load(new File(OUT_DIR + "/removeSingleIndirectObjectTest.pdf"))) { + try (PDDocument pdf = PDFParser.load(new File(OUT_DIR + "/removeSingleIndirectObjectTest.pdf"))) { PDPage page = pdf.getPage(0); COSArrayList annotations = (COSArrayList) page.getAnnotations(); @@ -411,7 +412,7 @@ public void removeDirectObject() throws IOException { pdf.close(); } - try (PDDocument pdf = PDDocument.load(new File(OUT_DIR + "/removeDirectObjectTest.pdf"))) { + try (PDDocument pdf = PDFParser.load(new File(OUT_DIR + "/removeDirectObjectTest.pdf"))) { PDPage page = pdf.getPage(0); COSArrayList annotations = (COSArrayList) page.getAnnotations(); @@ -453,7 +454,7 @@ public void removeIndirectObject() throws IOException { pdf.close(); } - try (PDDocument pdf = PDDocument.load(new File(OUT_DIR + "/removeIndirectObjectTest.pdf"))) { + try (PDDocument pdf = PDFParser.load(new File(OUT_DIR + "/removeIndirectObjectTest.pdf"))) { PDPage page = pdf.getPage(0); COSArrayList annotations = (COSArrayList) page.getAnnotations(); @@ -499,7 +500,7 @@ public void retainDirectObject() throws IOException { pdf.close(); } - try (PDDocument pdf = PDDocument.load(new File(OUT_DIR + "/retainDirectObjectTest.pdf"))) { + try (PDDocument pdf = PDFParser.load(new File(OUT_DIR + "/retainDirectObjectTest.pdf"))) { PDPage page = pdf.getPage(0); COSArrayList annotations = (COSArrayList) page.getAnnotations(); @@ -541,7 +542,7 @@ public void retainIndirectObject() throws IOException { pdf.close(); } - try (PDDocument pdf = PDDocument.load(new File(OUT_DIR + "/removeIndirectObjectTest.pdf"))) { + try (PDDocument pdf = PDFParser.load(new File(OUT_DIR + "/removeIndirectObjectTest.pdf"))) { PDPage page = pdf.getPage(0); COSArrayList annotations = (COSArrayList) page.getAnnotations(); @@ -558,4 +559,4 @@ public void retainIndirectObject() throws IOException { assertTrue("The size of the internal COSArray shall be 3", annotations.toList().size() == 3); } } -} \ No newline at end of file +} diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/TestEmbeddedFiles.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/TestEmbeddedFiles.java index aca92e34680..44e01f3dda5 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/TestEmbeddedFiles.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/TestEmbeddedFiles.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary; @@ -40,7 +41,8 @@ public void testNullEmbeddedFile() throws IOException boolean ok = false; try { - PDDocument doc = PDDocument.load(TestEmbeddedFiles.class.getResourceAsStream( + PDDocument doc = PDFParser.load(TestEmbeddedFiles.class + .getResourceAsStream( "null_PDComplexFileSpecification.pdf")); PDDocumentCatalog catalog = doc.getDocumentCatalog(); @@ -77,7 +79,8 @@ public void testOSSpecificAttachments() throws IOException PDEmbeddedFile dosFile = null; PDEmbeddedFile unixFile = null; - PDDocument doc = PDDocument.load(TestEmbeddedFiles.class + PDDocument doc = PDFParser.load( + TestEmbeddedFiles.class .getResourceAsStream("testPDF_multiFormatEmbFiles.pdf")); PDDocumentCatalog catalog = doc.getDocumentCatalog(); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElementTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElementTest.java index 62adc4534be..5c0d45c2a3b 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElementTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElementTest.java @@ -26,6 +26,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSObject; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.junit.Assert; import org.junit.Test; @@ -46,7 +47,7 @@ public class PDStructureElementTest public void testPDFBox4197() throws IOException { Set> attributeSet = new HashSet<>(); - try (PDDocument doc = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4197.pdf"))) + try (PDDocument doc = PDFParser.load(new File(TARGETPDFDIR, "PDFBOX-4197.pdf"))) { PDStructureTreeRoot structureTreeRoot = doc.getDocumentCatalog().getStructureTreeRoot(); checkElement(structureTreeRoot.getK(), attributeSet); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationTest.java index 8ce032ec923..332d6ae41c9 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationTest.java @@ -22,6 +22,8 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.List; + +import org.apache.pdfbox.pdfparser.FDFParser; import org.junit.Assert; import org.junit.Test; @@ -38,7 +40,7 @@ public class FDFAnnotationTest public void loadXFDFAnnotations() throws IOException, URISyntaxException { File f = new File(FDFAnnotationTest.class.getResource("xfdf-test-document-annotations.xml").toURI()); - try (FDFDocument fdfDoc = FDFDocument.loadXFDF(f)) + try (FDFDocument fdfDoc = FDFParser.loadXFDF(f)) { List fdfAnnots = fdfDoc.getCatalog().getFDF().getAnnotations(); assertEquals(18, fdfAnnots.size()); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java index 5a11f8a6136..c0b10ef5b0f 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/PDFontTest.java @@ -27,6 +27,7 @@ import org.apache.fontbox.ttf.TrueTypeFont; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.font.encoding.WinAnsiEncoding; @@ -61,7 +62,7 @@ public void setUp() throws Exception public void testPDFBox988() throws IOException, URISyntaxException { try (PDDocument doc = - PDDocument.load(new File(PDFontTest.class.getResource("F001u_3_7j.pdf").toURI()))) + PDFParser.load(new File(PDFontTest.class.getResource("F001u_3_7j.pdf").toURI()))) { PDFRenderer renderer = new PDFRenderer(doc); renderer.renderImage(0); @@ -101,7 +102,7 @@ public void testPDFBox3747() throws IOException doc.save(baos); } - try (PDDocument doc = PDDocument.load(baos.toByteArray())) + try (PDDocument doc = PDFParser.load(baos.toByteArray())) { PDFTextStripper stripper = new PDFTextStripper(); String text = stripper.getText(doc); @@ -166,7 +167,7 @@ public void testPDFBOX4115() throws IOException doc.save(outputFile); } - try (PDDocument doc = PDDocument.load(outputFile)) + try (PDDocument doc = PDFParser.load(outputFile)) { PDType1Font font = (PDType1Font) doc.getPage(0).getResources().getFont(COSName.getPDFName("F1")); Assert.assertEquals(font.getEncoding(), WinAnsiEncoding.INSTANCE); @@ -211,7 +212,7 @@ public void testPDFox4318() throws IOException private void testPDFBox3826checkFonts(byte[] byteArray, File fontFile) throws IOException { - try (PDDocument doc = PDDocument.load(byteArray)) + try (PDDocument doc = PDFParser.load(byteArray)) { PDPage page2 = doc.getPage(0); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java index 2e7b2f2bb7e..7b0cd49d1a8 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java @@ -27,6 +27,7 @@ import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.PDPageContentStream; @@ -295,7 +296,7 @@ private void validateCIDFontType2(boolean useSubset) throws IOException private String getUnicodeText(File file) throws IOException { - PDDocument document = PDDocument.load(file); + PDDocument document = PDFParser.load(file); PDFTextStripper stripper = new PDFTextStripper(); return stripper.getText(document); } diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEncoding.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEncoding.java index 985a6a07236..8cdeb11b132 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEncoding.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEncoding.java @@ -27,6 +27,7 @@ import org.apache.pdfbox.cos.COSInteger; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.font.encoding.DictionaryEncoding; @@ -93,7 +94,7 @@ public void testPDFBox3884() throws IOException doc.close(); // verify - doc = PDDocument.load(baos.toByteArray()); + doc = PDFParser.load(baos.toByteArray()); PDFTextStripper stripper = new PDFTextStripper(); String text = stripper.getText(doc); assertEquals("~˜", text.trim()); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBasedTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBasedTest.java index bb419e5aa86..7da349b26ba 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBasedTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBasedTest.java @@ -15,9 +15,10 @@ */ package org.apache.pdfbox.pdmodel.graphics.color; -import org.apache.pdfbox.pdmodel.PDDocument; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; + +import org.apache.pdfbox.pdmodel.PDDocument; import org.junit.Test; /** diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java index e1ee5fc1b9c..c627fd6efbb 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java @@ -25,7 +25,9 @@ import javax.imageio.ImageReader; import javax.imageio.stream.ImageInputStream; import junit.framework.TestCase; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.PDPageContentStream; @@ -84,7 +86,7 @@ public void testCreateFromRandomAccessSingle() throws IOException document.save(testResultsDir + "/singletiff.pdf"); document.close(); - document = PDDocument.load(new File(testResultsDir, "singletiff.pdf")); + document = PDFParser.load(new File(testResultsDir, "singletiff.pdf")); assertEquals(2, document.getNumberOfPages()); document.close(); @@ -133,7 +135,7 @@ public void testCreateFromRandomAccessMulti() throws IOException document.save(testResultsDir + "/multitiff.pdf"); document.close(); - document = PDDocument.load(new File(testResultsDir, "multitiff.pdf"), (String)null); + document = PDFParser.load(new File(testResultsDir, "multitiff.pdf"), (String) null); assertEquals(countTiffImages, document.getNumberOfPages()); document.close(); @@ -159,7 +161,7 @@ public void testCreateFromBufferedImage() throws IOException document.save(testResultsDir + "/singletifffrombi.pdf"); document.close(); - document = PDDocument.load(new File(testResultsDir, "singletifffrombi.pdf")); + document = PDFParser.load(new File(testResultsDir, "singletifffrombi.pdf")); assertEquals(1, document.getNumberOfPages()); document.close(); @@ -193,7 +195,7 @@ public void testCreateFromBufferedChessImage() throws IOException document.save(testResultsDir + "/singletifffromchessbi.pdf"); document.close(); - document = PDDocument.load(new File(testResultsDir, "singletifffromchessbi.pdf")); + document = PDFParser.load(new File(testResultsDir, "singletifffromchessbi.pdf")); assertEquals(1, document.getNumberOfPages()); document.close(); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactoryTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactoryTest.java index de48c118888..968fa0eeef5 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactoryTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/JPEGFactoryTest.java @@ -27,6 +27,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK; import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray; import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB; @@ -263,7 +264,7 @@ public void testCreateFromImageUSHORT_555_RGB() throws IOException private void checkJpegStream(File testResultsDir, String filename, InputStream resourceStream) throws IOException { - PDDocument doc = PDDocument.load(new File(testResultsDir, filename)); + PDDocument doc = PDFParser.load(new File(testResultsDir, filename)); PDImageXObject img = (PDImageXObject) doc.getPage(0).getResources().getXObject(COSName.getPDFName("Im1")); InputStream dctStream = img.createInputStream(Arrays.asList(COSName.DCT_DECODE.getName())); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java index b1e9b34281e..90af3339437 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/LosslessFactoryTest.java @@ -37,15 +37,12 @@ import java.util.Random; import javax.imageio.ImageIO; import junit.framework.TestCase; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertFalse; -import static junit.framework.TestCase.assertNotNull; -import static junit.framework.TestCase.assertTrue; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream.AppendMode; -import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK; import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray; import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB; import static org.apache.pdfbox.pdmodel.graphics.image.ValidateXImage.checkIdent; @@ -122,7 +119,7 @@ public void testCreateLosslessFromImageRGB() throws IOException document.save(pdfFile); document.close(); - document = PDDocument.load(pdfFile, (String)null); + document = PDFParser.load(pdfFile, (String) null); new PDFRenderer(document).renderImage(0); document.close(); } @@ -481,7 +478,7 @@ private void doBitmaskTransparencyTest(int imageType, String pdfFilename) throws File pdfFile = new File(testResultsDir, pdfFilename); document.save(pdfFile); document.close(); - document = PDDocument.load(pdfFile, (String)null); + document = PDFParser.load(pdfFile, (String) null); new PDFRenderer(document).renderImage(0); document.close(); } @@ -519,7 +516,8 @@ public void testCreateLosslessFrom16Bit() throws IOException ColorModel.OPAQUE, dataBufferType); WritableRaster targetRaster = Raster.createInterleavedRaster(dataBufferType, image.getWidth(), image.getHeight(), targetCS.getNumComponents(), new Point(0, 0)); - BufferedImage img16Bit = new BufferedImage(colorModel, targetRaster, false, new Hashtable()); + BufferedImage img16Bit = new BufferedImage(colorModel, targetRaster, false, + new Hashtable<>()); ColorConvertOp op = new ColorConvertOp(image.getColorModel().getColorSpace(), targetCS, null); op.filter(image, img16Bit); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PDInlineImageTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PDInlineImageTest.java index 53525cc4ff4..3b69f9ddc18 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PDInlineImageTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PDInlineImageTest.java @@ -28,6 +28,7 @@ import org.apache.pdfbox.cos.COSInteger; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream.AppendMode; @@ -178,7 +179,7 @@ public void testInlineImage() throws IOException document.save(pdfFile); document.close(); - document = PDDocument.load(pdfFile); + document = PDFParser.load(pdfFile); new PDFRenderer(document).renderImage(0); document.close(); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/ValidateXImage.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/ValidateXImage.java index 014efb35fd0..22110e134d4 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/ValidateXImage.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/ValidateXImage.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import javax.imageio.ImageIO; import javax.imageio.ImageWriter; @@ -27,6 +28,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSStream; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.rendering.PDFRenderer; @@ -130,7 +132,7 @@ static void doWritePDF(PDDocument document, PDImageXObject ximage, File testResu document.save(pdfFile); document.close(); - document = PDDocument.load(pdfFile); + document = PDFParser.load(pdfFile); assertEquals(1, count(document.getPage(0).getResources().getXObjectNames())); new PDFRenderer(document).renderImage(0); document.close(); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/TestOptionalContentGroups.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/TestOptionalContentGroups.java index af6b29abfa9..3c5466d10a1 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/TestOptionalContentGroups.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/TestOptionalContentGroups.java @@ -31,6 +31,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDResources; @@ -162,7 +163,7 @@ public void testOCGConsumption() throws Exception testOCGGeneration(); } - PDDocument doc = PDDocument.load(pdfFile); + PDDocument doc = PDFParser.load(pdfFile); try { assertEquals(1.5f, doc.getVersion()); @@ -417,7 +418,8 @@ public void testOCGGenerationSameNameCanHaveSameVisibilityOff() throws IOExcepti } // render PDF with science disabled and alternatives with same name enabled - try (PDDocument doc = PDDocument.load(new File(testResultsDir, "ocg-generation-same-name-off.pdf"))) + try (PDDocument doc = PDFParser + .load(new File(testResultsDir, "ocg-generation-same-name-off.pdf"))) { doc.getDocumentCatalog().getOCProperties().setGroupEnabled("background", false); doc.getDocumentCatalog().getOCProperties().setGroupEnabled("science", false); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/AppearanceGenerationTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/AppearanceGenerationTest.java index c85d3a358cb..6739cf4d4e8 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/AppearanceGenerationTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/AppearanceGenerationTest.java @@ -27,8 +27,9 @@ import org.apache.pdfbox.contentstream.operator.Operator; import org.apache.pdfbox.cos.COSFloat; import org.apache.pdfbox.cos.COSName; -import org.apache.pdfbox.pdfparser.PDFStreamParser; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; +import org.apache.pdfbox.pdfparser.PDFStreamParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.rendering.TestPDFToImage; @@ -73,7 +74,7 @@ public class AppearanceGenerationTest @Before public void setUp() throws IOException { - document = PDDocument.load(new File(IN_DIR, NAME_OF_PDF)); + document = PDFParser.load(new File(IN_DIR, NAME_OF_PDF)); OUT_DIR.mkdirs(); } diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java index b97ec3e52a1..1cbc1c0d2fe 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDSquareAnnotationTest.java @@ -20,8 +20,9 @@ import org.apache.pdfbox.cos.COSFloat; import org.apache.pdfbox.cos.COSInteger; import org.apache.pdfbox.cos.COSName; -import org.apache.pdfbox.pdfparser.PDFStreamParser; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; +import org.apache.pdfbox.pdfparser.PDFStreamParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.common.PDStream; @@ -110,7 +111,7 @@ public void validateAppearance() throws IOException final int borderWidth = 1; File file = new File(IN_DIR, NAME_OF_PDF); - try (PDDocument document = PDDocument.load(file)) + try (PDDocument document = PDFParser.load(file)) { PDPage page = document.getPage(0); List annotations = page.getAnnotations(); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/AcroFormsRotationTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/AcroFormsRotationTest.java index 52a0eb31f24..ebf0598d9e7 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/AcroFormsRotationTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/AcroFormsRotationTest.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.rendering.TestPDFToImage; import org.junit.After; import org.junit.Before; @@ -41,7 +42,7 @@ public class AcroFormsRotationTest @Before public void setUp() throws IOException { - document = PDDocument.load(new File(IN_DIR, NAME_OF_PDF)); + document = PDFParser.load(new File(IN_DIR, NAME_OF_PDF)); acroForm = document.getDocumentCatalog().getAcroForm(); OUT_DIR.mkdirs(); } diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/AlignmentTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/AlignmentTest.java index a3105813620..d9cc9dc993a 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/AlignmentTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/AlignmentTest.java @@ -20,6 +20,7 @@ import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.rendering.TestPDFToImage; import org.junit.After; import org.junit.Before; @@ -39,7 +40,7 @@ public class AlignmentTest @Before public void setUp() throws IOException { - document = PDDocument.load(new File(IN_DIR, NAME_OF_PDF)); + document = PDFParser.load(new File(IN_DIR, NAME_OF_PDF)); acroForm = document.getDocumentCatalog().getAcroForm(); OUT_DIR.mkdirs(); } diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/ControlCharacterTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/ControlCharacterTest.java index 81277da4a22..93ed39a9da6 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/ControlCharacterTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/ControlCharacterTest.java @@ -24,8 +24,9 @@ import java.util.List; import org.apache.pdfbox.cos.COSString; -import org.apache.pdfbox.pdfparser.PDFStreamParser; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; +import org.apache.pdfbox.pdfparser.PDFStreamParser; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget; import org.junit.After; import org.junit.Before; @@ -66,7 +67,7 @@ public class ControlCharacterTest { @Before public void setUp() throws IOException { - document = PDDocument.load(new File(IN_DIR, NAME_OF_PDF)); + document = PDFParser.load(new File(IN_DIR, NAME_OF_PDF)); acroForm = document.getDocumentCatalog().getAcroForm(); } diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/HandleDifferentDALevelsTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/HandleDifferentDALevelsTest.java index bc56ada80d2..0424c233ffc 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/HandleDifferentDALevelsTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/HandleDifferentDALevelsTest.java @@ -24,6 +24,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget; import org.junit.After; import org.junit.Before; @@ -41,7 +42,7 @@ public class HandleDifferentDALevelsTest @Before public void setUp() throws IOException { - document = PDDocument.load(new File(IN_DIR, NAME_OF_PDF)); + document = PDFParser.load(new File(IN_DIR, NAME_OF_PDF)); acroForm = document.getDocumentCatalog().getAcroForm(); OUT_DIR.mkdirs(); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/MultilineFieldsTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/MultilineFieldsTest.java index f7cc7861058..9bddc031e8c 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/MultilineFieldsTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/MultilineFieldsTest.java @@ -19,7 +19,9 @@ import java.io.File; import java.io.IOException; + import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.rendering.TestPDFToImage; import org.junit.After; import org.junit.Before; @@ -40,7 +42,7 @@ public class MultilineFieldsTest @Before public void setUp() throws IOException { - document = PDDocument.load(new File(IN_DIR, NAME_OF_PDF)); + document = PDFParser.load(new File(IN_DIR, NAME_OF_PDF)); acroForm = document.getDocumentCatalog().getAcroForm(); OUT_DIR.mkdirs(); } diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java index 7495744d9d7..a87c429221a 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormFlattenTest.java @@ -30,6 +30,7 @@ import javax.imageio.ImageIO; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.rendering.PDFRenderer; import org.apache.pdfbox.rendering.TestPDFToImage; import org.junit.Before; @@ -209,6 +210,7 @@ public void testFlattenOpenOfficeFormFilled() throws IOException flattenAndCompare(sourceUrl, targetFileName); } + /** * PDFBOX-4157 Filled template. */ @@ -268,7 +270,7 @@ private static boolean flattenAndCompare(String sourceUrl, String targetFileName File inputFile = new File(IN_DIR, targetFileName); File outputFile = new File(OUT_DIR, targetFileName); - try (PDDocument testPdf = PDDocument.load(inputFile)) + try (PDDocument testPdf = PDFParser.load(inputFile)) { testPdf.getDocumentCatalog().getAcroForm().flatten(); testPdf.setAllSecurityToBeRemoved(true); @@ -305,7 +307,7 @@ private static void generateSamples(String sourceUrl, String targetFile) throws File file = new File(IN_DIR,targetFile); - try (PDDocument document = PDDocument.load(file, (String)null)) + try (PDDocument document = PDFParser.load(file, (String) null)) { String outputPrefix = IN_DIR.getAbsolutePath() + '/' + file.getName() + "-"; int numPages = document.getNumberOfPages(); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java index 4a58ef4b0a0..182ef48661e 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java @@ -32,6 +32,7 @@ import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDResources; @@ -101,7 +102,7 @@ public void testAcroFormProperties() public void testFlatten() throws IOException { File file = new File(OUT_DIR, "AlignmentTests-flattened.pdf"); - try (PDDocument testPdf = PDDocument.load(new File(IN_DIR, "AlignmentTests.pdf"))) + try (PDDocument testPdf = PDFParser.load(new File(IN_DIR, "AlignmentTests.pdf"))) { testPdf.getDocumentCatalog().getAcroForm().flatten(); assertTrue(testPdf.getDocumentCatalog().getAcroForm().getFields().isEmpty()); @@ -127,7 +128,7 @@ public void testFlattenWidgetNoRef() throws IOException { File file = new File(OUT_DIR, "AlignmentTests-flattened-noRef.pdf"); - try (PDDocument testPdf = PDDocument.load(new File(IN_DIR, "AlignmentTests.pdf"))) + try (PDDocument testPdf = PDFParser.load(new File(IN_DIR, "AlignmentTests.pdf"))) { PDAcroForm acroFormToTest = testPdf.getDocumentCatalog().getAcroForm(); for (PDField field : acroFormToTest.getFieldTree()) { @@ -159,7 +160,7 @@ public void testFlattenSpecificFieldsOnly() throws IOException List fieldsToFlatten = new ArrayList<>(); - try (PDDocument testPdf = PDDocument.load(new File(IN_DIR, "AlignmentTests.pdf"))) + try (PDDocument testPdf = PDFParser.load(new File(IN_DIR, "AlignmentTests.pdf"))) { PDAcroForm acroFormToFlatten = testPdf.getDocumentCatalog().getAcroForm(); int numFieldsBeforeFlatten = acroFormToFlatten.getFields().size(); @@ -193,7 +194,7 @@ public void testDontAddMissingInformationOnDocumentLoad() { byte[] pdfBytes = createAcroFormWithMissingResourceInformation(); - try (PDDocument pdfDocument = PDDocument.load(pdfBytes)) + try (PDDocument pdfDocument = PDFParser.load(pdfBytes)) { // do a low level access to the AcroForm to avoid the generation of missing entries PDDocumentCatalog documentCatalog = pdfDocument.getDocumentCatalog(); @@ -227,7 +228,7 @@ public void testAddMissingInformationOnAcroFormAccess() { byte[] pdfBytes = createAcroFormWithMissingResourceInformation(); - try (PDDocument pdfDocument = PDDocument.load(pdfBytes)) + try (PDDocument pdfDocument = PDFParser.load(pdfBytes)) { PDDocumentCatalog documentCatalog = pdfDocument.getDocumentCatalog(); @@ -335,7 +336,7 @@ public void testAcroFormDefaultFonts() throws IOException assertNotNull(zadb); doc.save(baos); } - try (PDDocument doc = PDDocument.load(baos.toByteArray())) + try (PDDocument doc = PDFParser.load(baos.toByteArray())) { PDAcroForm acroForm2 = doc.getDocumentCatalog().getAcroForm(); PDResources defaultResources = acroForm2.getDefaultResources(); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java index 22b0186d238..1e8d724e79b 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java @@ -30,6 +30,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget; import org.junit.After; @@ -62,7 +63,7 @@ public void setUp() throws IOException document = new PDDocument(); acroForm = new PDAcroForm(document); - acrobatDocument = PDDocument.load(new File(IN_DIR, NAME_OF_PDF)); + acrobatDocument = PDFParser.load(new File(IN_DIR, NAME_OF_PDF)); acrobatAcroForm = acrobatDocument.getDocumentCatalog().getAcroForm(); } @@ -114,7 +115,7 @@ public void testRadioButtonWithOptions() throws MalformedURLException File file = new File(TARGET_PDF_DIR, "PDFBOX-3656.pdf"); try (InputStream is = new FileInputStream(file); - PDDocument pdfDocument = PDDocument.load(is)) + PDDocument pdfDocument = PDFParser.load(is)) { PDRadioButton radioButton = (PDRadioButton) pdfDocument.getDocumentCatalog().getAcroForm().getField("Checking/Savings"); radioButton.setValue("Off"); @@ -144,7 +145,7 @@ public void testOptionsAndNamesNotNumbers() throws MalformedURLException { File file = new File(TARGET_PDF_DIR, "PDFBOX-3682.pdf"); try (InputStream is = new FileInputStream(file); - PDDocument pdfDocument = PDDocument.load(is)) + PDDocument pdfDocument = PDFParser.load(is)) { pdfDocument.getDocumentCatalog().getAcroForm().getField("RadioButton").setValue("c"); PDRadioButton radioButton = (PDRadioButton) pdfDocument.getDocumentCatalog().getAcroForm().getField("RadioButton"); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestCheckBox.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestCheckBox.java index c42db5a8052..0518b15bea8 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestCheckBox.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestCheckBox.java @@ -152,4 +152,4 @@ public void testCheckBoxNoAppearance() throws IOException assertEquals("Off", checkBox.getValue()); } } -} \ No newline at end of file +} diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java index 6e8e018dd6f..1c7d0e85cb0 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java @@ -24,6 +24,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSString; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget; /** @@ -123,7 +124,7 @@ public void testFlags() throws IOException */ public void testAcroFormsBasicFields() throws IOException { - try (PDDocument doc = PDDocument.load(new File(PATH_OF_PDF))) + try (PDDocument doc = PDFParser.load(new File(PATH_OF_PDF))) { // get and assert that there is a form PDAcroForm form = doc.getDocumentCatalog().getAcroForm(); @@ -182,7 +183,7 @@ public void testAcroFormsBasicFields() throws IOException */ public void testWidgetMissingRect() throws IOException { - try (PDDocument doc = PDDocument.load(new File(PATH_OF_PDF))) + try (PDDocument doc = PDFParser.load(new File(PATH_OF_PDF))) { PDAcroForm form = doc.getDocumentCatalog().getAcroForm(); @@ -200,4 +201,4 @@ public void testWidgetMissingRect() throws IOException } } -} \ No newline at end of file +} diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestListBox.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestListBox.java index 0b9ed214b12..a558ba9bcdf 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestListBox.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestListBox.java @@ -258,4 +258,4 @@ public void testListboxPDModel() throws IOException } } } -} \ No newline at end of file +} diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java index 35dd258df9e..133f21d5334 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java @@ -109,4 +109,4 @@ public void testRadioButtonPDModel() throws IOException assertEquals(radioButton.getExportValues(), new ArrayList()); } } -} \ No newline at end of file +} diff --git a/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestPDFToImage.java b/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestPDFToImage.java index 7f7254af1a8..5422d72512c 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestPDFToImage.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestPDFToImage.java @@ -32,6 +32,8 @@ import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.ParallelParameterized; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; + import static org.junit.Assert.fail; import org.junit.Test; import org.junit.runner.RunWith; @@ -224,7 +226,7 @@ public boolean doTestFile(final File file, String inDir, String outDir) throws I try { new FileOutputStream(new File(outDir, file.getName() + ".parseerror")).close(); - document = PDDocument.load(file, (String)null); + document = PDFParser.load(file, (String) null); String outputPrefix = outDir + '/' + file.getName() + "-"; int numPages = document.getNumberOfPages(); if (numPages < 1) @@ -258,7 +260,7 @@ public boolean doTestFile(final File file, String inDir, String outDir) throws I document.save(tmpFile); new File(outDir, file.getName() + ".saveerror").delete(); new FileOutputStream(new File(outDir, file.getName() + ".reloaderror")).close(); - PDDocument.load(tmpFile, (String)null).close(); + PDFParser.load(tmpFile, (String) null).close(); new File(outDir, file.getName() + ".reloaderror").delete(); tmpFile.delete(); } diff --git a/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestRendering.java b/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestRendering.java index 3db2bc77072..cc8ec6e6289 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestRendering.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/rendering/TestRendering.java @@ -19,6 +19,7 @@ import org.apache.pdfbox.ParallelParameterized; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized.Parameters; @@ -61,7 +62,7 @@ public TestRendering(String fileName) public void render() throws IOException { File file = new File(INPUT_DIR, fileName); - PDDocument document = PDDocument.load(file); + PDDocument document = PDFParser.load(file); PDFRenderer renderer = new PDFRenderer(document); renderer.renderImage(0); diff --git a/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java b/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java index f35b507825f..aa2f90b3164 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java @@ -32,6 +32,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -69,7 +70,7 @@ public void setUp() throws IOException } } - document = PDDocument.load(new File(IN_DIR, NAME_OF_PDF)); + document = PDFParser.load(new File(IN_DIR, NAME_OF_PDF)); stripper = new PDFTextStripper(); stripper.setLineSeparator("\n"); } @@ -123,7 +124,7 @@ public void doTestFile(File inFile, File outDir, boolean bLogResult, boolean bSo } } - PDDocument document = PDDocument.load(inFile); + PDDocument document = PDFParser.load(inFile); try { File outFile; diff --git a/pdfbox/src/test/java/org/apache/pdfbox/text/TestTextStripper.java b/pdfbox/src/test/java/org/apache/pdfbox/text/TestTextStripper.java index 105a1005bf3..d9d2b94c9a3 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/text/TestTextStripper.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/text/TestTextStripper.java @@ -46,6 +46,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.TestPDPageTree; import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination; import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline; @@ -250,7 +251,7 @@ public void doTestFile(File inFile, File outDir, boolean bLogResult, boolean bSo } //System.out.println(" " + inFile + (bSort ? " (sorted)" : "")); - try (PDDocument document = PDDocument.load(inFile)) + try (PDDocument document = PDFParser.load(inFile)) { File outFile; File diffFile; @@ -352,7 +353,7 @@ public void doTestFile(File inFile, File outDir, boolean bLogResult, boolean bSo List revised = fileToLines(outFile); // Compute diff. Get the Patch object. Patch is the container for computed deltas. - Patch patch = DiffUtils.diff(original, revised); + Patch patch = DiffUtils.diff(original, revised); try (PrintStream diffPS = new PrintStream(diffFile, ENCODING)) { @@ -437,7 +438,8 @@ private int findOutlineItemDestPageNum(PDDocument doc, PDOutlineItem oi) throws */ public void testStripByOutlineItems() throws IOException, URISyntaxException { - PDDocument doc = PDDocument.load(new File(TestPDPageTree.class.getResource("with_outline.pdf").toURI())); + PDDocument doc = PDFParser + .load(new File(TestPDPageTree.class.getResource("with_outline.pdf").toURI())); PDDocumentOutline outline = doc.getDocumentCatalog().getDocumentOutline(); Iterable children = outline.children(); Iterator it = children.iterator(); diff --git a/pdfbox/src/test/resources/input/rendering/png_demo.pdf-1.png b/pdfbox/src/test/resources/input/rendering/png_demo.pdf-1.png new file mode 100644 index 00000000000..1ad50573e3e Binary files /dev/null and b/pdfbox/src/test/resources/input/rendering/png_demo.pdf-1.png differ diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConstants.java b/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConstants.java index 86d832d2d45..fce366b119c 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConstants.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightConstants.java @@ -24,235 +24,128 @@ /** * This interface provide a set of constants which identify validation error. */ -public interface PreflightConstants +public class PreflightConstants { - String FORMAT_PDF_A1B = "PDF/A1-b"; - String FORMAT_PDF_A1A = "PDF/A1-a"; + public static final String FORMAT_PDF_A1B = "PDF/A1-b"; + public static final String FORMAT_PDF_A1A = "PDF/A1-a"; // ----------------------------------------------------------- // ---- CONSTANTS // ----------------------------------------------------------- - int EDOC_TOKEN_MGR_ERROR = 255; - String EDOC_TOKEN_MGR_ERROR_TAG = " ERROR_CODE: "; - int MAX_DICT_ENTRIES = 4095; - int MAX_ARRAY_ELEMENTS = 8191; - int MAX_NAME_SIZE = 127; - int MAX_STRING_LENGTH = 65535; - int MAX_INDIRECT_OBJ = 8388607; - int MAX_CID = 65535; - int MAX_GRAPHIC_STATES = 28; - int MAX_DEVICE_N_LIMIT = 8; - float MAX_POSITIVE_FLOAT = 32767f; - float MAX_NEGATIVE_FLOAT = -32767f; - - String OUTPUT_INTENT_DICTIONARY_KEY_S = "S"; - String OUTPUT_INTENT_DICTIONARY_KEY_INFO = "Info"; - String OUTPUT_INTENT_DICTIONARY_VALUE_GTS_PDFA1 = "GTS_PDFA1"; - String OUTPUT_INTENT_DICTIONARY_KEY_OUTPUT_CONDITION_IDENTIFIER = "OutputConditionIdentifier"; - String OUTPUT_INTENT_DICTIONARY_VALUE_OUTPUT_CONDITION_IDENTIFIER_CUSTOM = "Custom"; - - String TRANSPARENCY_DICTIONARY_KEY_EXTGSTATE_ENTRY_REGEX = "(GS|gs)([0-9])+"; - - String DICTIONARY_KEY_LINEARIZED = "Linearized"; - String DICTIONARY_KEY_LINEARIZED_L = "L"; - String DICTIONARY_KEY_LINEARIZED_H = "H"; - String DICTIONARY_KEY_LINEARIZED_O = "O"; - String DICTIONARY_KEY_LINEARIZED_E = "E"; - String DICTIONARY_KEY_LINEARIZED_N = "N"; - String DICTIONARY_KEY_LINEARIZED_T = "T"; - - String DICTIONARY_KEY_PATTERN_TYPE = "PatternType"; - int DICTIONARY_PATTERN_TILING = 1; - int DICTIONARY_PATTERN_SHADING = 2; - - String XOBJECT_DICTIONARY_VALUE_SUBTYPE_IMG = "Image"; - String XOBJECT_DICTIONARY_VALUE_SUBTYPE_FORM = "Form"; - String XOBJECT_DICTIONARY_VALUE_SUBTYPE_POSTSCRIPT = "PS"; - String XOBJECT_DICTIONARY_KEY_BBOX = "BBox"; - String XOBJECT_DICTIONARY_KEY_GROUP = "Group"; - String XOBJECT_DICTIONARY_VALUE_S_TRANSPARENCY = "Transparency"; - String PAGE_DICTIONARY_VALUE_THUMB = "Thumb"; - - String FONT_DICTIONARY_VALUE_FONT = "Font"; - String FONT_DICTIONARY_VALUE_COMPOSITE = "Type0"; - String FONT_DICTIONARY_VALUE_TRUETYPE = "TrueType"; - String FONT_DICTIONARY_VALUE_TYPE1 = "Type1"; - String FONT_DICTIONARY_VALUE_TYPE1C = "Type1C"; - String FONT_DICTIONARY_VALUE_MMTYPE = "MMType1"; - String FONT_DICTIONARY_VALUE_TYPE3 = "Type3"; - String FONT_DICTIONARY_VALUE_TYPE0 = "CIDFontType0"; - String FONT_DICTIONARY_VALUE_TYPE0C = "CIDFontType0C"; - String FONT_DICTIONARY_VALUE_TYPE2 = "CIDFontType2"; - String FONT_DICTIONARY_VALUE_ENCODING_MAC = "MacRomanEncoding"; - String FONT_DICTIONARY_VALUE_ENCODING_MAC_EXP = "MacExpertEncoding"; - String FONT_DICTIONARY_VALUE_ENCODING_WIN = "WinAnsiEncoding"; - String FONT_DICTIONARY_VALUE_ENCODING_STD = "StandardEncoding"; - String FONT_DICTIONARY_VALUE_ENCODING_PDFDOC = "PDFDocEncoding"; - - String FONT_DICTIONARY_VALUE_CMAP_IDENTITY_H = "Identity-H"; - String FONT_DICTIONARY_VALUE_CMAP_IDENTITY_V = "Identity-V"; - - String FONT_DICTIONARY_KEY_NAME = "Name"; - String FONT_DICTIONARY_KEY_BASEFONT = "BaseFont"; - String FONT_DICTIONARY_KEY_FIRSTCHAR = "FirstChar"; - String FONT_DICTIONARY_KEY_LASTCHAR = "LastChar"; - String FONT_DICTIONARY_KEY_WIDTHS = "Widths"; - String FONT_DICTIONARY_KEY_FONT_DESC = "FontDescriptor"; - String FONT_DICTIONARY_KEY_ENCODING = "Encoding"; - String FONT_DICTIONARY_KEY_TOUNICODE = "ToUnicode"; - String FONT_DICTIONARY_KEY_FONTNAME = "FontName"; - String FONT_DICTIONARY_KEY_FLAGS = "Flags"; - String FONT_DICTIONARY_KEY_ITALICANGLE = "ItalicAngle"; - String FONT_DICTIONARY_KEY_FONTBBOX = "FontBBox"; - String FONT_DICTIONARY_KEY_FONTMATRIX = "FontMatrix"; - String FONT_DICTIONARY_KEY_CHARPROCS = "CharProcs"; - String FONT_DICTIONARY_KEY_ASCENT = "Ascent"; - String FONT_DICTIONARY_KEY_DESCENT = "Descent"; - String FONT_DICTIONARY_KEY_CAPHEIGHT = "CapHeight"; - String FONT_DICTIONARY_KEY_STEMV = "StemV"; - String FONT_DICTIONARY_KEY_LENGTH2 = "Length2"; - String FONT_DICTIONARY_KEY_LENGTH3 = "Length3"; - String FONT_DICTIONARY_KEY_METADATA = "Metadata"; - String FONT_DICTIONARY_KEY_BASEENCODING = "BaseEncoding"; - String FONT_DICTIONARY_KEY_DESCENDANT_FONTS = "DescendantFonts"; - String FONT_DICTIONARY_KEY_CID_GIDMAP = "CIDToGIDMap"; - String FONT_DICTIONARY_KEY_CMAP_NAME = "CMapName"; - String FONT_DICTIONARY_KEY_CMAP_WMODE = "WMode"; - String FONT_DICTIONARY_KEY_CMAP_USECMAP = "UseCMap"; - String FONT_DICTIONARY_KEY_CIDSET = "CIDSet"; - int FONT_DICTIONARY_DEFAULT_CMAP_WMODE = 0; - - String STREAM_DICTIONARY_KEY_DECODEPARAMS = "DecodeParms"; - - String STREAM_DICTIONARY_VALUE_FILTER_LZW = "LZWDecode"; - - String STREAM_DICTIONARY_VALUE_FILTER_ASCII_HEX = "ASCIIHexDecode"; - String STREAM_DICTIONARY_VALUE_FILTER_ASCII_85 = "ASCII85Decode"; - String STREAM_DICTIONARY_VALUE_FILTER_RUN = "RunLengthDecode"; - String STREAM_DICTIONARY_VALUE_FILTER_CCITTFF = "CCITTFaxDecode"; - String STREAM_DICTIONARY_VALUE_FILTER_JBIG = "JBIG2Decode"; - String STREAM_DICTIONARY_VALUE_FILTER_DCT = "DCTDecode"; - String STREAM_DICTIONARY_VALUE_FILTER_FLATE_DECODE = "FlateDecode"; - - String FILE_SPECIFICATION_VALUE_TYPE = "Filespec"; - String FILE_SPECIFICATION_KEY_EMBEDDED_FILE = "EF"; - - String INLINE_DICTIONARY_VALUE_FILTER_LZW = "LZW"; - - String INLINE_DICTIONARY_VALUE_FILTER_ASCII_HEX = "AHx"; - String INLINE_DICTIONARY_VALUE_FILTER_ASCII_85 = "A85"; - String INLINE_DICTIONARY_VALUE_FILTER_RUN = "RL"; - String INLINE_DICTIONARY_VALUE_FILTER_CCITTFF = "CCF"; - String INLINE_DICTIONARY_VALUE_FILTER_DCT = "DCT"; - String INLINE_DICTIONARY_VALUE_FILTER_FLATE_DECODE = "Fl"; - - String ANNOT_DICTIONARY_KEY_QUADPOINTS = "QuadPoints"; - String ANNOT_DICTIONARY_KEY_INKLIST = "InkList"; - - String ANNOT_DICTIONARY_VALUE_TYPE = "Annot"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_TEXT = "Text"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_LINK = "Link"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_FREETEXT = "FreeText"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_LINE = "Line"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_SQUARE = "Square"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_CIRCLE = "Circle"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_HIGHLIGHT = "Highlight"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_UNDERLINE = "Underline"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_SQUIGGLY = "Squiggly"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_STRIKEOUT = "StrikeOut"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_STAMP = "Stamp"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_INK = "Ink"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_POPUP = "Popup"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_WIDGET = "Widget"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_PRINTERMARK = "PrinterMark"; - String ANNOT_DICTIONARY_VALUE_SUBTYPE_TRAPNET = "TrapNet"; - - String ACTION_DICTIONARY_VALUE_TYPE = "Action"; - String ACTION_DICTIONARY_KEY_NEXT = "Next"; - String ACTION_DICTIONARY_VALUE_ATYPE_GOTO = "GoTo"; - String ACTION_DICTIONARY_VALUE_ATYPE_GOTOR = "GoToR"; - String ACTION_DICTIONARY_VALUE_ATYPE_THREAD = "Thread"; - String ACTION_DICTIONARY_VALUE_ATYPE_URI = "URI"; - String ACTION_DICTIONARY_VALUE_ATYPE_HIDE = "Hide"; - String ACTION_DICTIONARY_VALUE_ATYPE_NAMED = "Named"; - String ACTION_DICTIONARY_VALUE_ATYPE_SUBMIT = "SubmitForm"; - String ACTION_DICTIONARY_VALUE_ATYPE_LAUNCH = "Launch"; - String ACTION_DICTIONARY_VALUE_ATYPE_SOUND = "Sound"; - String ACTION_DICTIONARY_VALUE_ATYPE_MOVIE = "Movie"; - String ACTION_DICTIONARY_VALUE_ATYPE_RESET = "ResetForm"; - String ACTION_DICTIONARY_VALUE_ATYPE_IMPORT = "ImportData"; - String ACTION_DICTIONARY_VALUE_ATYPE_JAVASCRIPT = "JavaScript"; - String ACTION_DICTIONARY_VALUE_ATYPE_SETSTATE = "SetState"; - String ACTION_DICTIONARY_VALUE_ATYPE_NOOP = "NOP"; - String ACTION_DICTIONARY_VALUE_ATYPE_NAMED_NEXT = "NextPage"; - String ACTION_DICTIONARY_VALUE_ATYPE_NAMED_PREV = "PrevPage"; - String ACTION_DICTIONARY_VALUE_ATYPE_NAMED_FIRST = "FirstPage"; - String ACTION_DICTIONARY_VALUE_ATYPE_NAMED_LAST = "LastPage"; - - String ACROFORM_DICTIONARY_KEY_NEED_APPEARANCES = "NeedAppearances"; - - String RENDERING_INTENT_REL_COLOR = "RelativeColorimetric"; - String RENDERING_INTENT_ABS_COLOR = "AbsoluteColorimetric"; - String RENDERING_INTENT_PERCEPTUAL = "Perceptual"; - String RENDERING_INTENT_SATURATION = "Saturation"; - - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA43 = "FOGRA43"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_006 = "CGATS TR 006"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR006 = "CGATS TR006"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA39 = "FOGRA39"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_JC200103 = "JC200103"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA27 = "FOGRA27"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_EUROSB104 = "EUROSB104"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA45 = "FOGRA45"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA46 = "FOGRA46"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA41 = "FOGRA41"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_001 = "CGATS TR 001"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR001 = "CGATS TR001"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_003 = "CGATS TR 003"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR003 = "CGATS TR003"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_005 = "CGATS TR 005"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR005 = "CGATS TR005"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA28 = "FOGRA28"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_JCW2003 = "JCW2003"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_EUROSB204 = "EUROSB204"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA47 = "FOGRA47"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA44 = "FOGRA44"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA29 = "FOGRA29"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_JC200104 = "JC200104"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA40 = "FOGRA40"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA30 = "FOGRA30"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA42 = "FOGRA42"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_IFRA26 = "IFRA26"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_JCN2002 = "JCN2002"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_002 = "CGATS TR 002"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR002 = "CGATS TR002"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA33 = "FOGRA33"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA37 = "FOGRA37"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA31 = "FOGRA31"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA35 = "FOGRA35"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA32 = "FOGRA32"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA34 = "FOGRA34"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA36 = "FOGRA36"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA38 = "FOGRA38"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_sRGB = "sRGB"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_sRGB_IEC = "sRGB IEC61966-2.1"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_Adobe = "Adobe RGB (1998)"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_bg_sRGB = "bg-sRGB"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_sYCC = "sYCC"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_scRGB = "scRGB"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_scRGB_nl = "scRGB-nl"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_scYCC_nl = "scYCC-nl"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_ROMM = "ROMM RGB"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_RIMM = "RIMM RGB"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_ERIMM = "ERIMM RGB"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_eciRGB = "eciRGB"; - String ICC_CHARACTERIZATION_DATA_REGISTRY_opRGB = "opRGB"; + public static final int EDOC_TOKEN_MGR_ERROR = 255; + public static final String EDOC_TOKEN_MGR_ERROR_TAG = " ERROR_CODE: "; + public static final int MAX_DICT_ENTRIES = 4095; + public static final int MAX_ARRAY_ELEMENTS = 8191; + public static final int MAX_NAME_SIZE = 127; + public static final int MAX_STRING_LENGTH = 65535; + public static final int MAX_INDIRECT_OBJ = 8388607; + public static final int MAX_CID = 65535; + public static final int MAX_GRAPHIC_STATES = 28; + public static final int MAX_DEVICE_N_LIMIT = 8; + public static final float MAX_POSITIVE_FLOAT = 32767f; + public static final float MAX_NEGATIVE_FLOAT = -32767f; + + public static final String FONT_DICTIONARY_VALUE_COMPOSITE = "Type0"; + public static final String FONT_DICTIONARY_VALUE_TRUETYPE = "TrueType"; + public static final String FONT_DICTIONARY_VALUE_TYPE1 = "Type1"; + public static final String FONT_DICTIONARY_VALUE_TYPE1C = "Type1C"; + public static final String FONT_DICTIONARY_VALUE_MMTYPE = "MMType1"; + public static final String FONT_DICTIONARY_VALUE_TYPE3 = "Type3"; + public static final String FONT_DICTIONARY_VALUE_TYPE0 = "CIDFontType0"; + public static final String FONT_DICTIONARY_VALUE_TYPE0C = "CIDFontType0C"; + public static final String FONT_DICTIONARY_VALUE_TYPE2 = "CIDFontType2"; + + public static final String FONT_DICTIONARY_VALUE_CMAP_IDENTITY_H = "Identity-H"; + public static final String FONT_DICTIONARY_VALUE_CMAP_IDENTITY_V = "Identity-V"; + + public static final int FONT_DICTIONARY_DEFAULT_CMAP_WMODE = 0; + + public static final String STREAM_DICTIONARY_VALUE_FILTER_LZW = "LZWDecode"; + public static final String STREAM_DICTIONARY_VALUE_FILTER_ASCII_HEX = "ASCIIHexDecode"; + public static final String STREAM_DICTIONARY_VALUE_FILTER_ASCII_85 = "ASCII85Decode"; + public static final String STREAM_DICTIONARY_VALUE_FILTER_RUN = "RunLengthDecode"; + public static final String STREAM_DICTIONARY_VALUE_FILTER_CCITTFF = "CCITTFaxDecode"; + public static final String STREAM_DICTIONARY_VALUE_FILTER_JBIG = "JBIG2Decode"; + public static final String STREAM_DICTIONARY_VALUE_FILTER_DCT = "DCTDecode"; + public static final String STREAM_DICTIONARY_VALUE_FILTER_FLATE_DECODE = "FlateDecode"; + + public static final String INLINE_DICTIONARY_VALUE_FILTER_LZW = "LZW"; + + public static final String INLINE_DICTIONARY_VALUE_FILTER_ASCII_HEX = "AHx"; + public static final String INLINE_DICTIONARY_VALUE_FILTER_ASCII_85 = "A85"; + public static final String INLINE_DICTIONARY_VALUE_FILTER_RUN = "RL"; + public static final String INLINE_DICTIONARY_VALUE_FILTER_CCITTFF = "CCF"; + public static final String INLINE_DICTIONARY_VALUE_FILTER_DCT = "DCT"; + public static final String INLINE_DICTIONARY_VALUE_FILTER_FLATE_DECODE = "Fl"; + + public static final String ANNOT_DICTIONARY_VALUE_SUBTYPE_PRINTERMARK = "PrinterMark"; + public static final String ANNOT_DICTIONARY_VALUE_SUBTYPE_TRAPNET = "TrapNet"; + + public static final String ACTION_DICTIONARY_VALUE_ATYPE_NOOP = "NOP"; + public static final String ACTION_DICTIONARY_VALUE_ATYPE_SETSTATE = "SetState"; + + public static final String ACTION_DICTIONARY_VALUE_ATYPE_NAMED_NEXT = "NextPage"; + public static final String ACTION_DICTIONARY_VALUE_ATYPE_NAMED_PREV = "PrevPage"; + public static final String ACTION_DICTIONARY_VALUE_ATYPE_NAMED_FIRST = "FirstPage"; + public static final String ACTION_DICTIONARY_VALUE_ATYPE_NAMED_LAST = "LastPage"; + + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA43 = "FOGRA43"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_006 = "CGATS TR 006"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR006 = "CGATS TR006"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA39 = "FOGRA39"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_JC200103 = "JC200103"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA27 = "FOGRA27"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_EUROSB104 = "EUROSB104"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA45 = "FOGRA45"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA46 = "FOGRA46"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA41 = "FOGRA41"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_001 = "CGATS TR 001"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR001 = "CGATS TR001"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_003 = "CGATS TR 003"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR003 = "CGATS TR003"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_005 = "CGATS TR 005"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR005 = "CGATS TR005"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA28 = "FOGRA28"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_JCW2003 = "JCW2003"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_EUROSB204 = "EUROSB204"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA47 = "FOGRA47"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA44 = "FOGRA44"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA29 = "FOGRA29"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_JC200104 = "JC200104"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA40 = "FOGRA40"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA30 = "FOGRA30"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA42 = "FOGRA42"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_IFRA26 = "IFRA26"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_JCN2002 = "JCN2002"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_002 = "CGATS TR 002"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR002 = "CGATS TR002"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA33 = "FOGRA33"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA37 = "FOGRA37"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA31 = "FOGRA31"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA35 = "FOGRA35"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA32 = "FOGRA32"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA34 = "FOGRA34"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA36 = "FOGRA36"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA38 = "FOGRA38"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_sRGB = "sRGB"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_sRGB_IEC = "sRGB IEC61966-2.1"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_Adobe = "Adobe RGB (1998)"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_bg_sRGB = "bg-sRGB"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_sYCC = "sYCC"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_scRGB = "scRGB"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_scRGB_nl = "scRGB-nl"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_scYCC_nl = "scYCC-nl"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_ROMM = "ROMM RGB"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_RIMM = "RIMM RGB"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_ERIMM = "ERIMM RGB"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_eciRGB = "eciRGB"; + public static final String ICC_CHARACTERIZATION_DATA_REGISTRY_opRGB = "opRGB"; /** * Error code uses by the Validator when there is an error without error code. */ - String ERROR_UNKNOWN_ERROR = "-1"; + public static final String ERROR_UNKNOWN_ERROR = "-1"; // ----------------------------------------------------------- // ---- FILE STRUCTURE ERRORS 1.x... @@ -261,180 +154,180 @@ public interface PreflightConstants /** * Error code for syntax error */ - String ERROR_SYNTAX_MAIN = "1"; + public static final String ERROR_SYNTAX_MAIN = "1"; // error code category which can occur in each pdf part - String ERROR_SYNTAX_COMMON = "1.0"; + public static final String ERROR_SYNTAX_COMMON = "1.0"; /** * Too many entries in a dictionary object */ - String ERROR_SYNTAX_TOO_MANY_ENTRIES = "1.0.1"; + public static final String ERROR_SYNTAX_TOO_MANY_ENTRIES = "1.0.1"; /** * Too many element in an array object */ - String ERROR_SYNTAX_ARRAY_TOO_LONG = "1.0.2"; + public static final String ERROR_SYNTAX_ARRAY_TOO_LONG = "1.0.2"; /** * The name length is too long */ - String ERROR_SYNTAX_NAME_TOO_LONG = "1.0.3"; + public static final String ERROR_SYNTAX_NAME_TOO_LONG = "1.0.3"; /** * The literal string is too long */ - String ERROR_SYNTAX_LITERAL_TOO_LONG = "1.0.4"; + public static final String ERROR_SYNTAX_LITERAL_TOO_LONG = "1.0.4"; /** * The hexa string is too long */ - String ERROR_SYNTAX_HEXA_STRING_TOO_LONG = "1.0.5"; + public static final String ERROR_SYNTAX_HEXA_STRING_TOO_LONG = "1.0.5"; /** * The number is out of Range ( ex : greatter than 2^31-1) */ - String ERROR_SYNTAX_NUMERIC_RANGE = "1.0.6"; + public static final String ERROR_SYNTAX_NUMERIC_RANGE = "1.0.6"; /** * A dictionary key isn't a name */ - String ERROR_SYNTAX_DICTIONARY_KEY_INVALID = "1.0.7"; + public static final String ERROR_SYNTAX_DICTIONARY_KEY_INVALID = "1.0.7"; /** * The language declared doesn't match with the RFC1766 */ - String ERROR_SYNTAX_LANG_NOT_RFC1766 = "1.0.8"; + public static final String ERROR_SYNTAX_LANG_NOT_RFC1766 = "1.0.8"; /** * There are too many objects */ - String ERROR_SYNTAX_INDIRECT_OBJ_RANGE = "1.0.9"; + public static final String ERROR_SYNTAX_INDIRECT_OBJ_RANGE = "1.0.9"; /** * CID too long */ - String ERROR_SYNTAX_CID_RANGE = "1.0.10"; + public static final String ERROR_SYNTAX_CID_RANGE = "1.0.10"; /** * Hexa string shall contain even number of non white space char */ - String ERROR_SYNTAX_HEXA_STRING_EVEN_NUMBER = "1.0.11"; + public static final String ERROR_SYNTAX_HEXA_STRING_EVEN_NUMBER = "1.0.11"; /** * Hexa string contain non hexadecimal characters */ - String ERROR_SYNTAX_HEXA_STRING_INVALID = "1.0.12"; + public static final String ERROR_SYNTAX_HEXA_STRING_INVALID = "1.0.12"; /** * An object is missing from the document */ - String ERROR_SYNTAX_MISSING_OFFSET = "1.0.13"; + public static final String ERROR_SYNTAX_MISSING_OFFSET = "1.0.13"; /** * An object has an invalid offset */ - String ERROR_SYNTAX_INVALID_OFFSET = "1.0.14"; + public static final String ERROR_SYNTAX_INVALID_OFFSET = "1.0.14"; - String ERROR_SYNTAX_HEADER = "1.1"; + public static final String ERROR_SYNTAX_HEADER = "1.1"; - String ERROR_SYNTAX_HEADER_FIRST_CHAR = "1.1.1"; + public static final String ERROR_SYNTAX_HEADER_FIRST_CHAR = "1.1.1"; - String ERROR_SYNTAX_HEADER_FILE_TYPE = "1.1.2"; + public static final String ERROR_SYNTAX_HEADER_FILE_TYPE = "1.1.2"; /** * Common error about body syntax */ - String ERROR_SYNTAX_BODY = "1.2"; + public static final String ERROR_SYNTAX_BODY = "1.2"; /** * Error on the object delimiters (obj / endobj) */ - String ERROR_SYNTAX_OBJ_DELIMITER = "1.2.1"; + public static final String ERROR_SYNTAX_OBJ_DELIMITER = "1.2.1"; /** * Error on the stream delimiters (stream / endstream) */ - String ERROR_SYNTAX_STREAM_DELIMITER = "1.2.2"; + public static final String ERROR_SYNTAX_STREAM_DELIMITER = "1.2.2"; /** * Required fields are missing from the dictionary */ - String ERROR_SYNTAX_DICT_INVALID = "1.2.3"; + public static final String ERROR_SYNTAX_DICT_INVALID = "1.2.3"; /** * The length entry is missing from the stream dictionary */ - String ERROR_SYNTAX_STREAM_LENGTH_MISSING = "1.2.4"; + public static final String ERROR_SYNTAX_STREAM_LENGTH_MISSING = "1.2.4"; /** * The length of the stream dictionary and the stream length is inconsistent */ - String ERROR_SYNTAX_STREAM_LENGTH_INVALID = "1.2.5"; + public static final String ERROR_SYNTAX_STREAM_LENGTH_INVALID = "1.2.5"; /** * F or/and FFilter or/and FDecodeParams are present in a stream dictionary */ - String ERROR_SYNTAX_STREAM_FX_KEYS = "1.2.6"; + public static final String ERROR_SYNTAX_STREAM_FX_KEYS = "1.2.6"; /** * The stream uses an invalid filter (The LZW) */ - String ERROR_SYNTAX_STREAM_INVALID_FILTER = "1.2.7"; + public static final String ERROR_SYNTAX_STREAM_INVALID_FILTER = "1.2.7"; /** * The content stream has some syntax errors */ - String ERROR_SYNTAX_CONTENT_STREAM_INVALID = "1.2.8"; + public static final String ERROR_SYNTAX_CONTENT_STREAM_INVALID = "1.2.8"; /** * EmbeddedFile entry is present in a FileSpecification dictionary */ - String ERROR_SYNTAX_EMBEDDED_FILES = "1.2.9"; + public static final String ERROR_SYNTAX_EMBEDDED_FILES = "1.2.9"; /** * The content stream uses an unsupported operator */ - String ERROR_SYNTAX_CONTENT_STREAM_UNSUPPORTED_OP = "1.2.10"; + public static final String ERROR_SYNTAX_CONTENT_STREAM_UNSUPPORTED_OP = "1.2.10"; /** * The content stream contains an invalid argument for the operator */ - String ERROR_SYNTAX_CONTENT_STREAM_INVALID_ARGUMENT = "1.2.11"; + public static final String ERROR_SYNTAX_CONTENT_STREAM_INVALID_ARGUMENT = "1.2.11"; /** * The stream uses a filter which isn't defined in the PDF Reference document. */ - String ERROR_SYNTAX_STREAM_UNDEFINED_FILTER = "1.2.12"; + public static final String ERROR_SYNTAX_STREAM_UNDEFINED_FILTER = "1.2.12"; /** * The stream can't be processed */ - String ERROR_SYNTAX_STREAM_DAMAGED = "1.2.13"; + public static final String ERROR_SYNTAX_STREAM_DAMAGED = "1.2.13"; /** * There are no catalog dictionary in the PDF File */ - String ERROR_SYNTAX_NOCATALOG = "1.2.14"; + public static final String ERROR_SYNTAX_NOCATALOG = "1.2.14"; /** * Common error about the cross ref table */ - String ERROR_SYNTAX_CROSS_REF = "1.3"; + public static final String ERROR_SYNTAX_CROSS_REF = "1.3"; /** * Common error about the trailer */ - String ERROR_SYNTAX_TRAILER = "1.4"; + public static final String ERROR_SYNTAX_TRAILER = "1.4"; /** * ID is missing from the trailer */ - String ERROR_SYNTAX_TRAILER_MISSING_ID = "1.4.1"; + public static final String ERROR_SYNTAX_TRAILER_MISSING_ID = "1.4.1"; /** * Encrypt is forbidden */ - String ERROR_SYNTAX_TRAILER_ENCRYPT = "1.4.2"; + public static final String ERROR_SYNTAX_TRAILER_ENCRYPT = "1.4.2"; /** * An trailer entry has an invalid type */ - String ERROR_SYNTAX_TRAILER_TYPE_INVALID = "1.4.3"; + public static final String ERROR_SYNTAX_TRAILER_TYPE_INVALID = "1.4.3"; /** * Size is missing from the trailer */ - String ERROR_SYNTAX_TRAILER_MISSING_SIZE = "1.4.4"; + public static final String ERROR_SYNTAX_TRAILER_MISSING_SIZE = "1.4.4"; /** * Root is missing from the trailer */ - String ERROR_SYNTAX_TRAILER_MISSING_ROOT = "1.4.5"; + public static final String ERROR_SYNTAX_TRAILER_MISSING_ROOT = "1.4.5"; /** * ID in 1st trailer and the last is different */ - String ERROR_SYNTAX_TRAILER_ID_CONSISTENCY = "1.4.6"; + public static final String ERROR_SYNTAX_TRAILER_ID_CONSISTENCY = "1.4.6"; /** * EmbeddedFile entry is present in the Names dictionary */ - String ERROR_SYNTAX_TRAILER_CATALOG_EMBEDDEDFILES = "1.4.7"; + public static final String ERROR_SYNTAX_TRAILER_CATALOG_EMBEDDEDFILES = "1.4.7"; /** * Optional content is forbidden */ - String ERROR_SYNTAX_TRAILER_CATALOG_OCPROPERTIES = "1.4.8"; + public static final String ERROR_SYNTAX_TRAILER_CATALOG_OCPROPERTIES = "1.4.8"; /** * Errors in the Outlines dictionary */ - String ERROR_SYNTAX_TRAILER_OUTLINES_INVALID = "1.4.9"; + public static final String ERROR_SYNTAX_TRAILER_OUTLINES_INVALID = "1.4.9"; /** * Last %%EOF sequence is followed by data */ - String ERROR_SYNTAX_TRAILER_EOF = "1.4.10"; + public static final String ERROR_SYNTAX_TRAILER_EOF = "1.4.10"; // ----------------------------------------------------------- // ---- GRAPHIC ERRORS 2.x... @@ -443,116 +336,116 @@ public interface PreflightConstants /** * Main error code for graphical problems */ - String ERROR_GRAPHIC_MAIN = "2"; + public static final String ERROR_GRAPHIC_MAIN = "2"; - String ERROR_GRAPHIC_INVALID = "2.1"; + public static final String ERROR_GRAPHIC_INVALID = "2.1"; /** * BBox Entry of a Form XObject is missing or isn't an Array */ - String ERROR_GRAPHIC_INVALID_BBOX = "2.1.1"; + public static final String ERROR_GRAPHIC_INVALID_BBOX = "2.1.1"; /** * The OutputIntent dictionary is invalid */ - String ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY = "2.1.2"; + public static final String ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY = "2.1.2"; /** * The S entry of the OutputIntent isn't GTS_PDFA1 */ - String ERROR_GRAPHIC_OUTPUT_INTENT_S_VALUE_INVALID = "2.1.3"; + public static final String ERROR_GRAPHIC_OUTPUT_INTENT_S_VALUE_INVALID = "2.1.3"; /** * The ICC Profile is invalid */ - String ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_INVALID = "2.1.4"; + public static final String ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_INVALID = "2.1.4"; /** * There are more than one ICC Profile */ - String ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_MULTIPLE = "2.1.5"; + public static final String ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_MULTIPLE = "2.1.5"; /** * Profile version is too recent for PDF 1.4 document */ - String ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_TOO_RECENT = "2.1.6"; + public static final String ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_TOO_RECENT = "2.1.6"; - String ERROR_GRAPHIC_MISSING_FIELD = "2.1.7"; + public static final String ERROR_GRAPHIC_MISSING_FIELD = "2.1.7"; - String ERROR_GRAPHIC_TOO_MANY_GRAPHIC_STATES = "2.1.8"; + public static final String ERROR_GRAPHIC_TOO_MANY_GRAPHIC_STATES = "2.1.8"; - String ERROR_GRAPHIC_MISSING_OBJECT = "2.1.9"; + public static final String ERROR_GRAPHIC_MISSING_OBJECT = "2.1.9"; - String ERROR_GRAPHIC_XOBJECT_INVALID_TYPE = "2.1.10"; + public static final String ERROR_GRAPHIC_XOBJECT_INVALID_TYPE = "2.1.10"; /** * Main error code for graphical transparency problems */ - String ERROR_GRAPHIC_TRANSPARENCY = "2.2"; + public static final String ERROR_GRAPHIC_TRANSPARENCY = "2.2"; /** * A Group entry with S = Transparency is used or the S = Null */ - String ERROR_GRAPHIC_TRANSPARENCY_GROUP = "2.2.1"; + public static final String ERROR_GRAPHIC_TRANSPARENCY_GROUP = "2.2.1"; /** * A XObject SMask value isn't None */ - String ERROR_GRAPHIC_TRANSPARENCY_SMASK = "2.2.2"; + public static final String ERROR_GRAPHIC_TRANSPARENCY_SMASK = "2.2.2"; /** * A XObject has an unexpected key defined */ - String ERROR_GRAPHIC_UNEXPECTED_KEY = "2.3"; + public static final String ERROR_GRAPHIC_UNEXPECTED_KEY = "2.3"; /** * A XObject has an unexpected value for a defined key */ - String ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY = "2.3.2"; + public static final String ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY = "2.3.2"; /** * An invalid color space is used */ - String ERROR_GRAPHIC_INVALID_COLOR_SPACE = "2.4"; + public static final String ERROR_GRAPHIC_INVALID_COLOR_SPACE = "2.4"; /** * RGB color space used in the PDF file but the DestOutputProfile isn't RGB */ - String ERROR_GRAPHIC_INVALID_COLOR_SPACE_RGB = "2.4.1"; + public static final String ERROR_GRAPHIC_INVALID_COLOR_SPACE_RGB = "2.4.1"; /** * CMYK color space used in the PDF file but the DestOutputProfile isn't CMYK */ - String ERROR_GRAPHIC_INVALID_COLOR_SPACE_CMYK = "2.4.2"; + public static final String ERROR_GRAPHIC_INVALID_COLOR_SPACE_CMYK = "2.4.2"; /** * color space used in the PDF file but the DestOutputProfile is missing */ - String ERROR_GRAPHIC_INVALID_COLOR_SPACE_MISSING = "2.4.3"; + public static final String ERROR_GRAPHIC_INVALID_COLOR_SPACE_MISSING = "2.4.3"; /** * Unknown ColorSpace */ - String ERROR_GRAPHIC_INVALID_UNKNOWN_COLOR_SPACE = "2.4.4"; + public static final String ERROR_GRAPHIC_INVALID_UNKNOWN_COLOR_SPACE = "2.4.4"; /** * The pattern color space can't be used */ - String ERROR_GRAPHIC_INVALID_PATTERN_COLOR_SPACE_FORBIDDEN = "2.4.5"; + public static final String ERROR_GRAPHIC_INVALID_PATTERN_COLOR_SPACE_FORBIDDEN = "2.4.5"; /** * The pattern is invalid due to missing key or invalid value */ - String ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION = "2.4.6"; + public static final String ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION = "2.4.6"; /** * alternate color space used in the PDF file but the DestOutputProfile isn't consistent */ - String ERROR_GRAPHIC_INVALID_COLOR_SPACE_ALTERNATE = "2.4.7"; + public static final String ERROR_GRAPHIC_INVALID_COLOR_SPACE_ALTERNATE = "2.4.7"; /** * Base ColorSpace in the Indexed color space is invalid */ - String ERROR_GRAPHIC_INVALID_COLOR_SPACE_INDEXED = "2.4.8"; + public static final String ERROR_GRAPHIC_INVALID_COLOR_SPACE_INDEXED = "2.4.8"; /** * ColorSpace is forbidden due to some restriction (ex : Only DeviceXXX are auth in inlined image) */ - String ERROR_GRAPHIC_INVALID_COLOR_SPACE_FORBIDDEN = "2.4.9"; + public static final String ERROR_GRAPHIC_INVALID_COLOR_SPACE_FORBIDDEN = "2.4.9"; - String ERROR_GRAPHIC_INVALID_COLOR_SPACE_TOO_MANY_COMPONENTS_DEVICEN = "2.4.10"; + public static final String ERROR_GRAPHIC_INVALID_COLOR_SPACE_TOO_MANY_COMPONENTS_DEVICEN = "2.4.10"; /** * ICC Based color space used in the PDF file is invalid */ - String ERROR_GRAPHIC_INVALID_COLOR_SPACE_ICCBASED = "2.4.11"; + public static final String ERROR_GRAPHIC_INVALID_COLOR_SPACE_ICCBASED = "2.4.11"; /** * Validation asked on a missing ColorSpace */ - String ERROR_GRAPHIC_MISSING_COLOR_SPACE_ICCBASED = "2.4.12"; + public static final String ERROR_GRAPHIC_MISSING_COLOR_SPACE_ICCBASED = "2.4.12"; // ----------------------------------------------------------- // ---- FONT ERRORS 3.x... // ----------------------------------------------------------- @@ -560,363 +453,363 @@ public interface PreflightConstants /** * Main error code for font problems */ - String ERROR_FONTS_MAIN = "3"; + public static final String ERROR_FONTS_MAIN = "3"; - String ERROR_FONTS_INVALID_DATA = "3.1"; + public static final String ERROR_FONTS_INVALID_DATA = "3.1"; /** * Some mandatory fields are missing from the FONT Dictionary */ - String ERROR_FONTS_DICTIONARY_INVALID = "3.1.1"; + public static final String ERROR_FONTS_DICTIONARY_INVALID = "3.1.1"; /** * Some mandatory fields are missing from the FONT Descriptor Dictionary */ - String ERROR_FONTS_DESCRIPTOR_INVALID = "3.1.2"; + public static final String ERROR_FONTS_DESCRIPTOR_INVALID = "3.1.2"; /** * Error on the "Font File x" in the Font Descriptor (ex : FontFile and FontFile2 are present in the same * dictionary) */ - String ERROR_FONTS_FONT_FILEX_INVALID = "3.1.3"; + public static final String ERROR_FONTS_FONT_FILEX_INVALID = "3.1.3"; /** * Charset declaration is missing in a Type 1 Subset */ - String ERROR_FONTS_CHARSET_MISSING_FOR_SUBSET = "3.1.4"; + public static final String ERROR_FONTS_CHARSET_MISSING_FOR_SUBSET = "3.1.4"; /** * Encoding is inconsistent with the Font (ex : Symbolic TrueType mustn't declare encoding) */ - String ERROR_FONTS_ENCODING = "3.1.5"; + public static final String ERROR_FONTS_ENCODING = "3.1.5"; /** * Width array and Font program Width are inconsistent */ - String ERROR_FONTS_METRICS = "3.1.6"; + public static final String ERROR_FONTS_METRICS = "3.1.6"; /** * Required entry in a Composite Font dictionary is missing */ - String ERROR_FONTS_CIDKEYED_INVALID = "3.1.7"; + public static final String ERROR_FONTS_CIDKEYED_INVALID = "3.1.7"; /** * The CIDSystemInfo dictionary is invalid */ - String ERROR_FONTS_CIDKEYED_SYSINFO = "3.1.8"; + public static final String ERROR_FONTS_CIDKEYED_SYSINFO = "3.1.8"; /** * The CIDToGID is invalid */ - String ERROR_FONTS_CIDKEYED_CIDTOGID = "3.1.9"; + public static final String ERROR_FONTS_CIDKEYED_CIDTOGID = "3.1.9"; /** * The CMap of the Composite Font is missing or invalid */ - String ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING = "3.1.10"; + public static final String ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING = "3.1.10"; /** * The CIDSet entry i mandatory from a subset of composite font */ - String ERROR_FONTS_CIDSET_MISSING_FOR_SUBSET = "3.1.11"; + public static final String ERROR_FONTS_CIDSET_MISSING_FOR_SUBSET = "3.1.11"; /** * The CMap of the Composite Font is missing or invalid */ - String ERROR_FONTS_ENCODING_ERROR = "3.1.12"; + public static final String ERROR_FONTS_ENCODING_ERROR = "3.1.12"; /** * Encoding entry can't be read due to IOException */ - String ERROR_FONTS_ENCODING_IO = "3.1.13"; + public static final String ERROR_FONTS_ENCODING_IO = "3.1.13"; /** * The font type is unknown */ - String ERROR_FONTS_UNKNOWN_FONT_TYPE = "3.1.14"; + public static final String ERROR_FONTS_UNKNOWN_FONT_TYPE = "3.1.14"; /** * The embedded font is damaged */ - String ERROR_FONTS_DAMAGED = "3.2"; + public static final String ERROR_FONTS_DAMAGED = "3.2"; /** * The embedded Type1 font is damaged */ - String ERROR_FONTS_TYPE1_DAMAGED = "3.2.1"; + public static final String ERROR_FONTS_TYPE1_DAMAGED = "3.2.1"; /** * The embedded TrueType font is damaged */ - String ERROR_FONTS_TRUETYPE_DAMAGED = "3.2.2"; + public static final String ERROR_FONTS_TRUETYPE_DAMAGED = "3.2.2"; /** * The embedded composite font is damaged */ - String ERROR_FONTS_CID_DAMAGED = "3.2.3"; + public static final String ERROR_FONTS_CID_DAMAGED = "3.2.3"; /** * The embedded type 3 font is damaged */ - String ERROR_FONTS_TYPE3_DAMAGED = "3.2.4"; + public static final String ERROR_FONTS_TYPE3_DAMAGED = "3.2.4"; /** * The embedded CID Map is damaged */ - String ERROR_FONTS_CID_CMAP_DAMAGED = "3.2.5"; + public static final String ERROR_FONTS_CID_CMAP_DAMAGED = "3.2.5"; /** * Common error for a Glyph problem */ - String ERROR_FONTS_GLYPH = "3.3"; + public static final String ERROR_FONTS_GLYPH = "3.3"; /** * a glyph is missing */ - String ERROR_FONTS_GLYPH_MISSING = "3.3.1"; + public static final String ERROR_FONTS_GLYPH_MISSING = "3.3.1"; /** * a glyph is missing */ - String ERROR_FONTS_UNKNOWN_FONT_REF = "3.3.2"; + public static final String ERROR_FONTS_UNKNOWN_FONT_REF = "3.3.2"; // ----------------------------------------------------------- // ---- TRANSPARENCY ERRORS 4.x... // ----------------------------------------------------------- - String ERROR_TRANSPARENCY_MAIN = "4"; + public static final String ERROR_TRANSPARENCY_MAIN = "4"; /** * Common transparency error */ - String ERROR_TRANSPARENCY_EXT_GRAPHICAL_STATE = "4.1"; + public static final String ERROR_TRANSPARENCY_EXT_GRAPHICAL_STATE = "4.1"; /** * Soft mask entry is present but is forbidden */ - String ERROR_TRANSPARENCY_EXT_GS_SOFT_MASK = "4.1.1"; + public static final String ERROR_TRANSPARENCY_EXT_GS_SOFT_MASK = "4.1.1"; /** * Ca or/and ca entry are present but the value isn't 1.0 */ - String ERROR_TRANSPARENCY_EXT_GS_CA = "4.1.2"; + public static final String ERROR_TRANSPARENCY_EXT_GS_CA = "4.1.2"; /** * BlendMode value isn't valid (only Normal and Compatible are authorized) */ - String ERROR_TRANSPARENCY_EXT_GS_BLEND_MODE = "4.1.3"; + public static final String ERROR_TRANSPARENCY_EXT_GS_BLEND_MODE = "4.1.3"; // ----------------------------------------------------------- // ---- ANNOTATION ERRORS 5.x... // ----------------------------------------------------------- - String ERROR_ANNOT_MAIN = "5"; + public static final String ERROR_ANNOT_MAIN = "5"; /** * Common missing field error in annotation dictionary */ - String ERROR_ANNOT_MISSING_FIELDS = "5.1"; + public static final String ERROR_ANNOT_MISSING_FIELDS = "5.1"; /** * The subtype entry is missing from the annotation dictionary */ - String ERROR_ANNOT_MISSING_SUBTYPE = "5.1.1"; + public static final String ERROR_ANNOT_MISSING_SUBTYPE = "5.1.1"; /** * The AP dictionary of the annotation contains forbidden/invalid entries (only the N entry is authorized) */ - String ERROR_ANNOT_MISSING_AP_N_CONTENT = "5.1.2"; + public static final String ERROR_ANNOT_MISSING_AP_N_CONTENT = "5.1.2"; /** * An annotation validation is required but there are no element to validate */ - String ERROR_ANNOT_MISSING_ANNOTATION_DICTIONARY = "5.1.3"; + public static final String ERROR_ANNOT_MISSING_ANNOTATION_DICTIONARY = "5.1.3"; /** * Common forbidden field error in annotation dictionary */ - String ERROR_ANNOT_FORBIDDEN_ELEMENT = "5.2"; + public static final String ERROR_ANNOT_FORBIDDEN_ELEMENT = "5.2"; /** * This type of annotation is forbidden (ex : Movie) */ - String ERROR_ANNOT_FORBIDDEN_SUBTYPE = "5.2.1"; + public static final String ERROR_ANNOT_FORBIDDEN_SUBTYPE = "5.2.1"; /** * The annotation uses a flag which is forbidden. */ - String ERROR_ANNOT_FORBIDDEN_FLAG = "5.2.2"; + public static final String ERROR_ANNOT_FORBIDDEN_FLAG = "5.2.2"; /** * Annotation uses a Color profile which isn't the same than the profile contained by the OutputIntent */ - String ERROR_ANNOT_FORBIDDEN_COLOR = "5.2.3"; + public static final String ERROR_ANNOT_FORBIDDEN_COLOR = "5.2.3"; /** * Dest entry can't be used if the A element is used too */ - String ERROR_ANNOT_FORBIDDEN_DEST = "5.2.4"; + public static final String ERROR_ANNOT_FORBIDDEN_DEST = "5.2.4"; /** * The AA field is forbidden for the Widget annotation when the PDF is a PDF/A */ - String ERROR_ANNOT_FORBIDDEN_AA = "5.2.5"; + public static final String ERROR_ANNOT_FORBIDDEN_AA = "5.2.5"; /** * The annotation uses a flag which is not recommended but not forbidden by the ISO 19005-1:2005. */ - String ERROR_ANNOT_NOT_RECOMMENDED_FLAG = "5.2.6"; + public static final String ERROR_ANNOT_NOT_RECOMMENDED_FLAG = "5.2.6"; /** * The AA field is forbidden for the Catalog when the PDF is a PDF/A */ - String ERROR_ANNOT_CATALOG_FORBIDDEN_AA = "5.2.7"; + public static final String ERROR_ANNOT_CATALOG_FORBIDDEN_AA = "5.2.7"; /** * Common Invalid field error in annotation dictionary */ - String ERROR_ANNOT_INVALID_ELEMENT = "5.3"; + public static final String ERROR_ANNOT_INVALID_ELEMENT = "5.3"; /** * The AP dictionary of the annotation contains forbidden/invalid entries (only the N entry is authorized) */ - String ERROR_ANNOT_INVALID_AP_CONTENT = "5.3.1"; + public static final String ERROR_ANNOT_INVALID_AP_CONTENT = "5.3.1"; /** * Ca or/and ca entry are present but the value isn't 1.0 */ - String ERROR_ANNOT_INVALID_CA = "5.3.2"; + public static final String ERROR_ANNOT_INVALID_CA = "5.3.2"; /** * Dest entry of an annotation can't be checked due to an IO Exception */ - String ERROR_ANNOT_INVALID_DEST = "5.3.3"; + public static final String ERROR_ANNOT_INVALID_DEST = "5.3.3"; // ----------------------------------------------------------- // ---- ACTION ERRORS 6.x... // ----------------------------------------------------------- - String ERROR_ACTION_MAIN = "6"; + public static final String ERROR_ACTION_MAIN = "6"; /** * Common invalid action error */ - String ERROR_ACTION_INVALID_ACTIONS = "6.1"; + public static final String ERROR_ACTION_INVALID_ACTIONS = "6.1"; /** * A mandatory entry in the action dictionary is missing */ - String ERROR_ACTION_MISING_KEY = "6.1.1"; + public static final String ERROR_ACTION_MISING_KEY = "6.1.1"; /** * Some elements of the annotation dictionary have an invalid type (ex : array instead of Dictionary) */ - String ERROR_ACTION_INVALID_TYPE = "6.1.3"; + public static final String ERROR_ACTION_INVALID_TYPE = "6.1.3"; /** * The H entry of a Hide action is set to true (so some annotation can be hide) */ - String ERROR_ACTION_HIDE_H_INVALID = "6.1.4"; + public static final String ERROR_ACTION_HIDE_H_INVALID = "6.1.4"; /** * An action validation is required but there are no element to validate */ - String ERROR_ACTION_MISSING_ACTION_DICTIONARY = "6.1.5"; + public static final String ERROR_ACTION_MISSING_ACTION_DICTIONARY = "6.1.5"; /** * Common forbidden action error */ - String ERROR_ACTION_FORBIDDEN_ACTIONS = "6.2"; + public static final String ERROR_ACTION_FORBIDDEN_ACTIONS = "6.2"; /** * Named action other than predefined not allowed */ - String ERROR_ACTION_FORBIDDEN_ACTIONS_NAMED = "6.2.1"; + public static final String ERROR_ACTION_FORBIDDEN_ACTIONS_NAMED = "6.2.1"; /** * Additional action entry is forbidden */ - String ERROR_ACTION_FORBIDDEN_ADDITIONAL_ACTION = "6.2.2"; + public static final String ERROR_ACTION_FORBIDDEN_ADDITIONAL_ACTION = "6.2.2"; /** * Additional action entry is forbidden in a form field object */ - String ERROR_ACTION_FORBIDDEN_ADDITIONAL_ACTIONS_FIELD = "6.2.3"; + public static final String ERROR_ACTION_FORBIDDEN_ADDITIONAL_ACTIONS_FIELD = "6.2.3"; /** * A widget annotation linked with a form field shall not have any action */ - String ERROR_ACTION_FORBIDDEN_WIDGET_ACTION_FIELD = "6.2.4"; + public static final String ERROR_ACTION_FORBIDDEN_WIDGET_ACTION_FIELD = "6.2.4"; /** * An explicitly forbidden action is used in the PDF file. */ - String ERROR_ACTION_FORBIDDEN_ACTIONS_EXPLICITLY_FORBIDDEN = "6.2.5"; + public static final String ERROR_ACTION_FORBIDDEN_ACTIONS_EXPLICITLY_FORBIDDEN = "6.2.5"; /** * Actions is rejected if it isn't defined in the PDF Reference Third Edition This is to avoid not consistent file * due to new features of the PDF format. */ - String ERROR_ACTION_FORBIDDEN_ACTIONS_UNDEF = "6.2.6"; + public static final String ERROR_ACTION_FORBIDDEN_ACTIONS_UNDEF = "6.2.6"; // ----------------------------------------------------------- // ---- METADATA ERRORS 7.x... // ----------------------------------------------------------- /** * Main metadata error code */ - String ERROR_METADATA_MAIN = "7"; + public static final String ERROR_METADATA_MAIN = "7"; /** * Invalid metadata found */ - String ERROR_METADATA_FORMAT = "7.1"; + public static final String ERROR_METADATA_FORMAT = "7.1"; /** * Unknown metadata */ - String ERROR_METADATA_PROPERTY_UNKNOWN = "7.1.1"; + public static final String ERROR_METADATA_PROPERTY_UNKNOWN = "7.1.1"; /** * Invalid xmp metadata format */ - String ERROR_METADATA_PROPERTY_FORMAT = "7.1.2"; + public static final String ERROR_METADATA_PROPERTY_FORMAT = "7.1.2"; /** * Unexpected type of a Metadata entry */ - String ERROR_METADATA_FORMAT_UNKNOWN = "7.1.3"; + public static final String ERROR_METADATA_FORMAT_UNKNOWN = "7.1.3"; /** * Invalid metadata, unable to process the font due to IOException */ - String ERROR_METADATA_FORMAT_STREAM = "7.1.4"; + public static final String ERROR_METADATA_FORMAT_STREAM = "7.1.4"; /** * Invalid metadata, unable to process the font due to Invalid XPacket exception */ - String ERROR_METADATA_FORMAT_XPACKET = "7.1.5"; + public static final String ERROR_METADATA_FORMAT_XPACKET = "7.1.5"; /** * Metadata mismatch between PDF Dictionary and xmp */ - String ERROR_METADATA_MISMATCH = "7.2"; + public static final String ERROR_METADATA_MISMATCH = "7.2"; /** * Invalid information in xpacket processing instruction */ - String ERROR_METADATA_XPACKET_DEPRECATED = "7.0.0"; + public static final String ERROR_METADATA_XPACKET_DEPRECATED = "7.0.0"; /** * Description schema required not embedded */ - String ERROR_METADATA_ABSENT_DESCRIPTION_SCHEMA = "7.3"; + public static final String ERROR_METADATA_ABSENT_DESCRIPTION_SCHEMA = "7.3"; /** * A required namespace URI missing */ - String ERROR_METADATA_NS_URI_MISSING = "7.4"; + public static final String ERROR_METADATA_NS_URI_MISSING = "7.4"; /** * A namespace URI has an unexpected value */ - String ERROR_METADATA_WRONG_NS_URI = "7.4.1"; + public static final String ERROR_METADATA_WRONG_NS_URI = "7.4.1"; /** * A namespace prefix has an unexpected value */ - String ERROR_METADATA_WRONG_NS_PREFIX = "7.4.2"; + public static final String ERROR_METADATA_WRONG_NS_PREFIX = "7.4.2"; /** * Required property is missing */ - String ERROR_METADATA_PROPERTY_MISSING = "7.5"; + public static final String ERROR_METADATA_PROPERTY_MISSING = "7.5"; /** * A valueType is used but is not declared */ - String ERROR_METADATA_UNKNOWN_VALUETYPE = "7.6"; + public static final String ERROR_METADATA_UNKNOWN_VALUETYPE = "7.6"; /** * PDF/A Identification Schema not found */ - String ERROR_METADATA_PDFA_ID_MISSING = "7.11"; + public static final String ERROR_METADATA_PDFA_ID_MISSING = "7.11"; /** * PDF/A Identification Conformance Invalid */ - String ERROR_METADATA_INVALID_PDFA_CONFORMANCE = "7.11.1"; + public static final String ERROR_METADATA_INVALID_PDFA_CONFORMANCE = "7.11.1"; /** * PDF/A Identification Version Identifier Invalid (pdfaid:part) */ - String ERROR_METADATA_INVALID_PDFA_VERSION_ID = "7.11.2"; + public static final String ERROR_METADATA_INVALID_PDFA_VERSION_ID = "7.11.2"; /** * rdf:about is missing */ - String ERROR_METADATA_RDF_ABOUT_ATTRIBUTE_MISSING = "7.0"; + public static final String ERROR_METADATA_RDF_ABOUT_ATTRIBUTE_MISSING = "7.0"; /** * One of rdf:about attribute embedded in RDF:rdf have a different value than the others */ - String ERROR_METADATA_RDF_ABOUT_ATTRIBUTE_INEQUAL_VALUE = "7.0.1"; + public static final String ERROR_METADATA_RDF_ABOUT_ATTRIBUTE_INEQUAL_VALUE = "7.0.1"; /** * a category has an invalid value in one property description (must be internal or external) */ - String ERROR_METADATA_CATEGORY_PROPERTY_INVALID = "7.5.1"; + public static final String ERROR_METADATA_CATEGORY_PROPERTY_INVALID = "7.5.1"; /** * the info dictionary is corrupt or value can't be read */ - String ERROR_METADATA_DICT_INFO_CORRUPT = "7.12"; + public static final String ERROR_METADATA_DICT_INFO_CORRUPT = "7.12"; /** * Error about PDF processing : that is not necessary a specific PDF/A validation error * but a PDF specification requirement that isn't respected. */ - String ERROR_PDF_PROCESSING = "8"; + public static final String ERROR_PDF_PROCESSING = "8"; /** * A Mandatory element is missing */ - String ERROR_PDF_PROCESSING_MISSING = "8.1"; + public static final String ERROR_PDF_PROCESSING_MISSING = "8.1"; } diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java b/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java index 1c318d51c2d..0ad9db6f019 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java @@ -22,6 +22,8 @@ package org.apache.pdfbox.preflight; import java.util.Collection; +import java.util.Collections; +import java.util.List; import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.pdmodel.PDDocument; @@ -31,7 +33,6 @@ public class PreflightDocument extends PDDocument { - private ValidationResult result = new ValidationResult(true); private PreflightConfiguration config; @@ -40,107 +41,84 @@ public class PreflightDocument extends PDDocument private final Format specification; - /** - * Create an empty preflight document and load the default configuration for the given format. - * - * @param format - */ - public PreflightDocument(Format format) - { - this(format, null); - } - /** * Create a preflight document based on the COSDocument and load the default configuration for the given format. * - * @param doc - * @param format + * @param doc the underlying COSDocument + * @param format the format used for validation */ public PreflightDocument(COSDocument doc, Format format) { this(doc, format, null); } - /** - * Create an empty preflight document that will use the given configuration bean to process the validation. if the - * configuration is null, a default configuration will be load using the given format. - * - * @param format - * @param cfg - */ - public PreflightDocument(Format format, PreflightConfiguration cfg) - { - this(new COSDocument(), format, cfg); - } - /** * Create a preflight document based on the COSDocument that will use the given configuration bean to process the * validation. if the configuration is null, a default configuration will be load using the given format. * - * @param doc - * @param format - * @param config + * @param doc the underlying COSDocument + * @param format the format used for validation + * @param config the configuration used for validation */ public PreflightDocument(COSDocument doc, Format format, PreflightConfiguration config) { super(doc); this.specification = format; - this.config = config; - if (this.config == null) - { - initConfiguration(format); - } + // PDF/A1-b is default + this.config = config == null ? PreflightConfiguration.createPdfA1BConfiguration() : config; } - private void initConfiguration(Format format) - { - switch (format) - { - default: // default is PDF/A1-b - this.config = PreflightConfiguration.createPdfA1BConfiguration(); - break; - } - - } - - public ValidationResult getResult() + /** + * Returns an unmodifiable list of all validation errors. + * + * @return an unmodifiable list of all validation errors + */ + public List getValidationErrors() { - return result; + return Collections.unmodifiableList(result.getErrorsList()); } - public void setResult(ValidationResult result) + /** + * Add a validation error. + * + * @param error the validation error to be added + */ + public void addValidationError(ValidationError error) { - if (this.result != null) - { - this.result.mergeResult(result); - } - else if (result != null) - { - this.result = result; - } - else + if (error != null) { - this.result = new ValidationResult(true); + this.result.addError(error); } } - public void addValidationError(ValidationError error) + /** + * Add a list of validation errors. + * + * @param errorList the list of validation errors + */ + public void addValidationErrors(List errorList) { - if (error != null) + if (errorList != null) { - if (result == null) - { - this.result = new ValidationResult(error.isWarning()); - } - this.result.addError(error); + this.result.addErrors(errorList); } } + /** + * Returns the associated preflight context. It is created after parsing the pdf. + * + * @return the associated preflight context + */ public PreflightContext getContext() { return this.context; } + /** + * Set the preflight context for this document. + * + * @param context the associated preflight context + */ public void setContext(PreflightContext context) { this.context = context; @@ -149,9 +127,10 @@ public void setContext(PreflightContext context) /** * Check that PDDocument is a valid file according to the format given during the object creation. * + * @return the validation result * @throws ValidationException */ - public void validate() throws ValidationException + public ValidationResult validate() throws ValidationException { // force early class loading to check if people forgot to use --add-modules javax.xml.bind // on java 9 & 10, or to add jaxb-api on java 11 and later @@ -162,8 +141,14 @@ public void validate() throws ValidationException { ContextHelper.validateElement(context, name); } + return result; } + /** + * Returns the format which is used to valide the pdf document. + * + * @return the format used for validation + */ public Format getSpecification() { return specification; diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java b/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java index bf05a1d2c5a..6a45f870b17 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java @@ -39,7 +39,6 @@ import javax.xml.transform.stream.StreamResult; import org.apache.pdfbox.preflight.ValidationResult.ValidationError; -import org.apache.pdfbox.preflight.exception.SyntaxValidationException; import org.apache.pdfbox.preflight.parser.PreflightParser; import org.apache.pdfbox.preflight.parser.XmlResultParser; import org.apache.pdfbox.util.Version; @@ -166,21 +165,7 @@ private static void usage() private static int runSimple(File file) throws IOException { - ValidationResult result; - PreflightParser parser = new PreflightParser(file); - try - { - parser.parse(); - try (PreflightDocument document = parser.getPreflightDocument()) - { - document.validate(); - result = document.getResult(); - } - } - catch (SyntaxValidationException e) - { - result = e.getResult(); - } + ValidationResult result = PreflightParser.validate(file); if (result.isValid()) { diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/action/ActionManagerFactory.java b/preflight/src/main/java/org/apache/pdfbox/preflight/action/ActionManagerFactory.java index aabe8b327d3..409b18c5b70 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/action/ActionManagerFactory.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/action/ActionManagerFactory.java @@ -31,28 +31,28 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSObject; import org.apache.pdfbox.cos.COSObjectKey; +import org.apache.pdfbox.pdmodel.interactive.action.PDAction; +import org.apache.pdfbox.pdmodel.interactive.action.PDActionGoTo; +import org.apache.pdfbox.pdmodel.interactive.action.PDActionHide; +import org.apache.pdfbox.pdmodel.interactive.action.PDActionImportData; +import org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript; +import org.apache.pdfbox.pdmodel.interactive.action.PDActionLaunch; +import org.apache.pdfbox.pdmodel.interactive.action.PDActionMovie; +import org.apache.pdfbox.pdmodel.interactive.action.PDActionNamed; +import org.apache.pdfbox.pdmodel.interactive.action.PDActionRemoteGoTo; +import org.apache.pdfbox.pdmodel.interactive.action.PDActionResetForm; +import org.apache.pdfbox.pdmodel.interactive.action.PDActionSound; +import org.apache.pdfbox.pdmodel.interactive.action.PDActionSubmitForm; +import org.apache.pdfbox.pdmodel.interactive.action.PDActionThread; +import org.apache.pdfbox.pdmodel.interactive.action.PDActionURI; import org.apache.pdfbox.preflight.PreflightConstants; import org.apache.pdfbox.preflight.PreflightContext; import org.apache.pdfbox.preflight.ValidationResult.ValidationError; import org.apache.pdfbox.preflight.exception.ValidationException; -import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_GOTO; -import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_GOTOR; -import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_HIDE; -import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_IMPORT; -import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_JAVASCRIPT; -import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_LAUNCH; -import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_MOVIE; -import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_NAMED; import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_NOOP; -import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_RESET; import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_SETSTATE; -import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_SOUND; -import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_SUBMIT; -import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_THREAD; -import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_URI; -import static org.apache.pdfbox.preflight.PreflightConstants.ACTION_DICTIONARY_VALUE_TYPE; public class ActionManagerFactory { @@ -225,7 +225,7 @@ protected AbstractActionManager createActionManager(PreflightContext ctx, COSDic { String type = action.getNameAsString(COSName.TYPE); - if (type != null && !ACTION_DICTIONARY_VALUE_TYPE.equals(type)) + if (type != null && !PDAction.TYPE.equals(type)) { throw new ValidationException("The given dictionary isn't the dictionary of an Action"); } @@ -235,46 +235,48 @@ protected AbstractActionManager createActionManager(PreflightContext ctx, COSDic String s = action.getNameAsString(COSName.S); // --- Here is authorized actions - if (ACTION_DICTIONARY_VALUE_ATYPE_GOTO.equals(s)) + if (PDActionGoTo.SUB_TYPE.equals(s)) { return new GoToAction(this, action, ctx, aaKey); } - if (ACTION_DICTIONARY_VALUE_ATYPE_GOTOR.equals(s)) + if (PDActionRemoteGoTo.SUB_TYPE.equals(s)) { return new GoToRemoteAction(this, action, ctx, aaKey); } - if (ACTION_DICTIONARY_VALUE_ATYPE_THREAD.equals(s)) + if (PDActionThread.SUB_TYPE.equals(s)) { return new ThreadAction(this, action, ctx, aaKey); } - if (ACTION_DICTIONARY_VALUE_ATYPE_URI.equals(s)) + if (PDActionURI.SUB_TYPE.equals(s)) { return new UriAction(this, action, ctx, aaKey); } - if (ACTION_DICTIONARY_VALUE_ATYPE_HIDE.equals(s)) + if (PDActionHide.SUB_TYPE.equals(s)) { return new HideAction(this, action, ctx, aaKey); } - if (ACTION_DICTIONARY_VALUE_ATYPE_NAMED.equals(s)) + if (PDActionNamed.SUB_TYPE.equals(s)) { return new NamedAction(this, action, ctx, aaKey); } - if (ACTION_DICTIONARY_VALUE_ATYPE_SUBMIT.equals(s)) + if (PDActionSubmitForm.SUB_TYPE.equals(s)) { return new SubmitAction(this, action, ctx, aaKey); } // --- Here is forbidden actions - if (ACTION_DICTIONARY_VALUE_ATYPE_LAUNCH.equals(s) || ACTION_DICTIONARY_VALUE_ATYPE_SOUND.equals(s) - || ACTION_DICTIONARY_VALUE_ATYPE_MOVIE.equals(s) || ACTION_DICTIONARY_VALUE_ATYPE_RESET.equals(s) - || ACTION_DICTIONARY_VALUE_ATYPE_IMPORT.equals(s) || ACTION_DICTIONARY_VALUE_ATYPE_JAVASCRIPT.equals(s) - || ACTION_DICTIONARY_VALUE_ATYPE_SETSTATE.equals(s) || ACTION_DICTIONARY_VALUE_ATYPE_NOOP.equals(s)) + if (PDActionLaunch.SUB_TYPE.equals(s) || PDActionSound.SUB_TYPE.equals(s) + || PDActionMovie.SUB_TYPE.equals(s) || PDActionResetForm.SUB_TYPE.equals(s) + || PDActionImportData.SUB_TYPE.equals(s) + || PDActionJavaScript.SUB_TYPE.equals(s) + || ACTION_DICTIONARY_VALUE_ATYPE_SETSTATE.equals(s) + || ACTION_DICTIONARY_VALUE_ATYPE_NOOP.equals(s)) { return new InvalidAction(this, action, ctx, aaKey, s); } diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/action/NamedAction.java b/preflight/src/main/java/org/apache/pdfbox/preflight/action/NamedAction.java index 2035efbb699..576ca667206 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/action/NamedAction.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/action/NamedAction.java @@ -67,7 +67,7 @@ protected boolean innerValid() String n = this.actionDictionary.getNameAsString(COSName.N); // ---- N entry is mandatory - if (n == null || "".equals(n)) + if (n == null || n.isEmpty()) { context.addValidationError(new ValidationError(ERROR_ACTION_MISING_KEY, "N entry is mandatory for the NamedActions")); diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/AnnotationValidator.java b/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/AnnotationValidator.java index c47c5c4f54f..9c8632b5275 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/AnnotationValidator.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/AnnotationValidator.java @@ -29,6 +29,7 @@ import org.apache.pdfbox.cos.COSStream; import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationPopup; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary; import org.apache.pdfbox.preflight.PreflightContext; @@ -39,7 +40,6 @@ import static org.apache.pdfbox.preflight.PreflightConfiguration.ACTIONS_PROCESS; import static org.apache.pdfbox.preflight.PreflightConfiguration.GRAPHIC_PROCESS; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_POPUP; import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_ANNOT_FORBIDDEN_COLOR; import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_ANNOT_FORBIDDEN_FLAG; import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_ANNOT_INVALID_AP_CONTENT; @@ -292,7 +292,7 @@ protected boolean checkActions() throws ValidationException protected boolean checkPopup() throws ValidationException { COSBase cosPopup = this.annotDictionary - .getDictionaryObject(COSName.getPDFName(ANNOT_DICTIONARY_VALUE_SUBTYPE_POPUP)); + .getDictionaryObject(COSName.getPDFName(PDAnnotationPopup.SUB_TYPE)); if (cosPopup != null) { if (!(cosPopup instanceof COSDictionary)) diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/InkAnnotationValidator.java b/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/InkAnnotationValidator.java index eadb8416f8f..87aabcadfd8 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/InkAnnotationValidator.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/InkAnnotationValidator.java @@ -21,8 +21,6 @@ package org.apache.pdfbox.preflight.annotation; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_KEY_INKLIST; - import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationUnknown; @@ -48,6 +46,6 @@ public InkAnnotationValidator(PreflightContext ctx, COSDictionary annotDictionar @Override protected boolean checkSpecificMandatoryFields() { - return this.annotDictionary.containsKey(COSName.getPDFName(ANNOT_DICTIONARY_KEY_INKLIST)); + return annotDictionary.containsKey(COSName.INKLIST); } } diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/MarkupAnnotationValidator.java b/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/MarkupAnnotationValidator.java index 99fdcce7ab5..a07a4fd7c8e 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/MarkupAnnotationValidator.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/MarkupAnnotationValidator.java @@ -21,8 +21,6 @@ package org.apache.pdfbox.preflight.annotation; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_KEY_QUADPOINTS; - import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationTextMarkup; @@ -46,6 +44,6 @@ protected MarkupAnnotationValidator(PreflightContext ctx, COSDictionary annotDic @Override protected boolean checkSpecificMandatoryFields() { - return this.annotDictionary.containsKey(COSName.getPDFName(ANNOT_DICTIONARY_KEY_QUADPOINTS)); + return this.annotDictionary.containsKey(COSName.QUADPOINTS); } } diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/pdfa/PDFAbAnnotationFactory.java b/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/pdfa/PDFAbAnnotationFactory.java index d7487d725e4..c0868b3e989 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/pdfa/PDFAbAnnotationFactory.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/annotation/pdfa/PDFAbAnnotationFactory.java @@ -21,23 +21,23 @@ package org.apache.pdfbox.preflight.annotation.pdfa; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_CIRCLE; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_FREETEXT; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_HIGHLIGHT; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_INK; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_LINE; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_LINK; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_POPUP; import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_PRINTERMARK; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_SQUARE; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_SQUIGGLY; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_STAMP; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_STRIKEOUT; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_TEXT; import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_TRAPNET; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_UNDERLINE; -import static org.apache.pdfbox.preflight.PreflightConstants.ANNOT_DICTIONARY_VALUE_SUBTYPE_WIDGET; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationCircle; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationFreeText; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationHighlight; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationInk; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLine; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationPopup; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationRubberStamp; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquare; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquiggly; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationStrikeout; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationText; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationUnderline; +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget; import org.apache.pdfbox.preflight.annotation.AnnotationValidatorFactory; import org.apache.pdfbox.preflight.annotation.CircleAnnotationValidator; import org.apache.pdfbox.preflight.annotation.FreeTextAnnotationValidator; @@ -66,23 +66,27 @@ public class PDFAbAnnotationFactory extends AnnotationValidatorFactory @Override protected void initializeClasses() { - this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_TEXT, TextAnnotationValidator.class); - this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_LINK, LinkAnnotationValidator.class); - this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_FREETEXT, FreeTextAnnotationValidator.class); - this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_LINE, LineAnnotationValidator.class); + this.validatorClasses.put(PDAnnotationText.SUB_TYPE, TextAnnotationValidator.class); + this.validatorClasses.put(PDAnnotationLink.SUB_TYPE, LinkAnnotationValidator.class); + this.validatorClasses.put(PDAnnotationFreeText.SUB_TYPE, FreeTextAnnotationValidator.class); + this.validatorClasses.put(PDAnnotationLine.SUB_TYPE, LineAnnotationValidator.class); - this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_SQUARE, SquareAnnotationValidator.class); - this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_CIRCLE, CircleAnnotationValidator.class); + this.validatorClasses.put(PDAnnotationSquare.SUB_TYPE, SquareAnnotationValidator.class); + this.validatorClasses.put(PDAnnotationCircle.SUB_TYPE, CircleAnnotationValidator.class); - this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_HIGHLIGHT, HighlightAnnotationValidator.class); - this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_UNDERLINE, UnderlineAnnotationValidator.class); - this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_STRIKEOUT, StrikeoutAnnotationValidator.class); - this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_SQUIGGLY, SquigglyAnnotationValidator.class); + this.validatorClasses.put(PDAnnotationHighlight.SUB_TYPE, + HighlightAnnotationValidator.class); + this.validatorClasses.put(PDAnnotationUnderline.SUB_TYPE, + UnderlineAnnotationValidator.class); + this.validatorClasses.put(PDAnnotationStrikeout.SUB_TYPE, + StrikeoutAnnotationValidator.class); + this.validatorClasses.put(PDAnnotationSquiggly.SUB_TYPE, SquigglyAnnotationValidator.class); - this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_STAMP, RubberStampAnnotationValidator.class); - this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_INK, InkAnnotationValidator.class); - this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_POPUP, PopupAnnotationValidator.class); - this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_WIDGET, WidgetAnnotationValidator.class); + this.validatorClasses.put(PDAnnotationRubberStamp.SUB_TYPE, + RubberStampAnnotationValidator.class); + this.validatorClasses.put(PDAnnotationInk.SUB_TYPE, InkAnnotationValidator.class); + this.validatorClasses.put(PDAnnotationPopup.SUB_TYPE, PopupAnnotationValidator.class); + this.validatorClasses.put(PDAnnotationWidget.SUB_TYPE, WidgetAnnotationValidator.class); this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_PRINTERMARK, PrintMarkAnnotationValidator.class); this.validatorClasses.put(ANNOT_DICTIONARY_VALUE_SUBTYPE_TRAPNET, TrapNetAnnotationValidator.class); } diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java b/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java index 66abd7cbf67..235b6a6d0b0 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java @@ -223,19 +223,12 @@ public PreflightStreamEngine(PreflightContext context, PDPage page) */ protected void validateRenderingIntent(Operator operator, List arguments) throws ContentStreamException { - if (OperatorName.SET_RENDERINGINTENT.equals(operator.getName())) + if (OperatorName.SET_RENDERINGINTENT.equals(operator.getName()) + && arguments.get(0) instanceof COSName + && !RenderingIntents.contains((COSName) arguments.get(0))) { - String riArgument0 = ""; - if (arguments.get(0) instanceof COSName) - { - riArgument0 = ((COSName) arguments.get(0)).getName(); - } - - if (!RenderingIntents.contains(riArgument0)) - { - registerError("Unexpected value '" + arguments.get(0) + "' for ri operand. ", - ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY); - } + registerError("Unexpected value '" + arguments.get(0) + "' for ri operand. ", + ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY); } } diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java b/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java index 7bbc41c6f3c..34326f1cde2 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type0FontValidator.java @@ -28,8 +28,6 @@ import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_FONTS_CID_CMAP_DAMAGED; import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_FONTS_DICTIONARY_INVALID; import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_DEFAULT_CMAP_WMODE; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_KEY_CMAP_USECMAP; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_KEY_CMAP_WMODE; import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_VALUE_CMAP_IDENTITY_H; import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_VALUE_CMAP_IDENTITY_V; @@ -259,8 +257,7 @@ private void processCMapAsStream(COSStream aCMap) * According to the getInt javadoc, -1 is returned if there is no result. In the PDF Reference v1.7 p449, * we can read that the default value is 0. */ - int wmode = aCMap.getInt(COSName.getPDFName(FONT_DICTIONARY_KEY_CMAP_WMODE), - FONT_DICTIONARY_DEFAULT_CMAP_WMODE); + int wmode = aCMap.getInt(COSName.WMODE, FONT_DICTIONARY_DEFAULT_CMAP_WMODE); COSName type = aCMap.getCOSName(COSName.TYPE); String cmapName = aCMap.getNameAsString(COSName.CMAPNAME); @@ -285,8 +282,7 @@ else if (!COSName.CMAP.equals(type)) this.fontContainer.push(new ValidationError(ERROR_FONTS_CID_CMAP_DAMAGED, font.getName() + ": The CMap type is damaged", e)); } - COSDictionary cmapUsed = (COSDictionary) aCMap.getDictionaryObject(COSName - .getPDFName(FONT_DICTIONARY_KEY_CMAP_USECMAP)); + COSDictionary cmapUsed = (COSDictionary) aCMap.getDictionaryObject(COSName.USE_CMAP); if (cmapUsed != null) { checkCMapEncoding(cmapUsed); diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type1FontValidator.java b/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type1FontValidator.java index 16247432a40..2510acc3e36 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type1FontValidator.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/font/Type1FontValidator.java @@ -25,19 +25,12 @@ import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.font.PDSimpleFont; +import org.apache.pdfbox.preflight.PreflightConstants; import org.apache.pdfbox.preflight.PreflightContext; import org.apache.pdfbox.preflight.ValidationResult.ValidationError; import org.apache.pdfbox.preflight.font.container.Type1Container; import org.apache.pdfbox.preflight.font.descriptor.Type1DescriptorHelper; - -import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_FONTS_ENCODING; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_VALUE_ENCODING_MAC; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_VALUE_ENCODING_MAC_EXP; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_VALUE_ENCODING_PDFDOC; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_VALUE_ENCODING_STD; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_VALUE_ENCODING_WIN; - public class Type1FontValidator extends SimpleFontValidator { public Type1FontValidator(PreflightContext context, PDSimpleFont font) @@ -48,7 +41,7 @@ public Type1FontValidator(PreflightContext context, PDSimpleFont font) @Override protected void createFontDescriptorHelper() { - this.descriptorHelper = new Type1DescriptorHelper(context, (PDSimpleFont)font, fontContainer); + descriptorHelper = new Type1DescriptorHelper(context, (PDSimpleFont) font, fontContainer); } @Override @@ -59,19 +52,21 @@ protected void checkEncoding() { if (encoding instanceof COSName) { - String encodingName = ((COSName) encoding).getName(); - if (!(encodingName.equals(FONT_DICTIONARY_VALUE_ENCODING_MAC) - || encodingName.equals(FONT_DICTIONARY_VALUE_ENCODING_MAC_EXP) - || encodingName.equals(FONT_DICTIONARY_VALUE_ENCODING_WIN) - || encodingName.equals(FONT_DICTIONARY_VALUE_ENCODING_PDFDOC) || encodingName - .equals(FONT_DICTIONARY_VALUE_ENCODING_STD))) + COSName encodingName = (COSName) encoding; + if (!(encodingName.equals(COSName.MAC_ROMAN_ENCODING) + || encodingName.equals(COSName.MAC_EXPERT_ENCODING) + || encodingName.equals(COSName.WIN_ANSI_ENCODING) + || encodingName.equals(COSName.PDF_DOC_ENCODING) + || encodingName.equals(COSName.STANDARD_ENCODING))) { - this.fontContainer.push(new ValidationError(ERROR_FONTS_ENCODING)); + fontContainer + .push(new ValidationError(PreflightConstants.ERROR_FONTS_ENCODING)); } } else if (!(encoding instanceof COSDictionary)) { - this.fontContainer.push(new ValidationError(ERROR_FONTS_ENCODING)); + fontContainer + .push(new ValidationError(PreflightConstants.ERROR_FONTS_ENCODING)); } } } diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/FontDescriptorHelper.java b/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/FontDescriptorHelper.java index 17edcb34101..687e87576cb 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/FontDescriptorHelper.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/FontDescriptorHelper.java @@ -29,13 +29,6 @@ import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_METADATA_FORMAT_XPACKET; import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_METADATA_UNKNOWN_VALUETYPE; import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_STREAM_INVALID_FILTER; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_KEY_ASCENT; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_KEY_CAPHEIGHT; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_KEY_DESCENT; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_KEY_FLAGS; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_KEY_FONTBBOX; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_KEY_ITALICANGLE; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_KEY_STEMV; import java.io.IOException; import java.io.InputStream; @@ -77,13 +70,13 @@ public abstract class FontDescriptorHelper static { MANDATORYFIELDS = new HashSet<>(); - MANDATORYFIELDS.add(FONT_DICTIONARY_KEY_FLAGS); - MANDATORYFIELDS.add(FONT_DICTIONARY_KEY_ITALICANGLE); - MANDATORYFIELDS.add(FONT_DICTIONARY_KEY_CAPHEIGHT); - MANDATORYFIELDS.add(FONT_DICTIONARY_KEY_FONTBBOX); - MANDATORYFIELDS.add(FONT_DICTIONARY_KEY_ASCENT); - MANDATORYFIELDS.add(FONT_DICTIONARY_KEY_DESCENT); - MANDATORYFIELDS.add(FONT_DICTIONARY_KEY_STEMV); + MANDATORYFIELDS.add(COSName.FLAGS.getName()); + MANDATORYFIELDS.add(COSName.ITALIC_ANGLE.getName()); + MANDATORYFIELDS.add(COSName.CAP_HEIGHT.getName()); + MANDATORYFIELDS.add(COSName.FONT_BBOX.getName()); + MANDATORYFIELDS.add(COSName.ASCENT.getName()); + MANDATORYFIELDS.add(COSName.DESCENT.getName()); + MANDATORYFIELDS.add(COSName.STEM_V.getName()); MANDATORYFIELDS.add(COSName.FONT_NAME.getName()); MANDATORYFIELDS.add(COSName.TYPE.getName()); } diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/Type1DescriptorHelper.java b/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/Type1DescriptorHelper.java index fb9b0f834cd..521e922c0b3 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/Type1DescriptorHelper.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/font/descriptor/Type1DescriptorHelper.java @@ -35,8 +35,6 @@ import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_FONTS_CHARSET_MISSING_FOR_SUBSET; import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_FONTS_FONT_FILEX_INVALID; import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_FONTS_TYPE1_DAMAGED; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_KEY_LENGTH2; -import static org.apache.pdfbox.preflight.PreflightConstants.FONT_DICTIONARY_KEY_LENGTH3; public class Type1DescriptorHelper extends FontDescriptorHelper { @@ -55,7 +53,7 @@ protected boolean checkMandatoryFields(COSDictionary fDescriptor) if (isSubSet(fontDescriptor.getFontName())) { String charsetStr = fontDescriptor.getCharSet(); - if (charsetStr == null || "".equals(charsetStr)) + if (charsetStr == null || charsetStr.isEmpty()) { this.fContainer.push(new ValidationError(ERROR_FONTS_CHARSET_MISSING_FOR_SUBSET, fontDescriptor.getFontName() @@ -84,8 +82,8 @@ public PDStream extractFontFile(PDFontDescriptor fontDescriptor) } boolean hasLength1 = stream.getInt(COSName.LENGTH1) > 0; - boolean hasLength2 = stream.getInt(COSName.getPDFName(FONT_DICTIONARY_KEY_LENGTH2)) > 0; - boolean hasLength3 = stream.getInt(COSName.getPDFName(FONT_DICTIONARY_KEY_LENGTH3)) >= 0; + boolean hasLength2 = stream.getInt(COSName.LENGTH2) > 0; + boolean hasLength3 = stream.getInt(COSName.LENGTH3) >= 0; if (!(hasLength1 && hasLength2 && hasLength3)) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/StandardColorSpaceHelper.java b/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/StandardColorSpaceHelper.java index f6c72fe287c..33c2c2f1bd1 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/StandardColorSpaceHelper.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/StandardColorSpaceHelper.java @@ -468,9 +468,9 @@ else if (colorSpace.getName().equals(ColorSpaces.DeviceGray.getLabel()) && if (defaultCS != null) { // defaultCS is valid if the number of errors hasn't changed - int nbOfErrors = context.getDocument().getResult().getErrorsList().size(); + int nbOfErrors = context.getDocument().getValidationErrors().size(); processAllColorSpace(defaultCS); - int newNbOfErrors = context.getDocument().getResult().getErrorsList().size(); + int newNbOfErrors = context.getDocument().getValidationErrors().size(); result = (nbOfErrors == newNbOfErrors); } diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java b/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java index 2e0c12887f1..adb96efe6a1 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java @@ -26,15 +26,12 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.pdfbox.cos.COSArray; import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDictionary; -import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.cos.COSFloat; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSNull; @@ -43,11 +40,8 @@ import org.apache.pdfbox.cos.COSObjectKey; import org.apache.pdfbox.cos.COSStream; import org.apache.pdfbox.cos.COSString; -import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream; -import org.apache.pdfbox.io.RandomAccessRead; import org.apache.pdfbox.io.ScratchFile; -import org.apache.pdfbox.pdfparser.PDFObjectStreamParser; import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdfparser.XrefTrailerResolver.XRefType; import org.apache.pdfbox.pdmodel.PDDocument; @@ -88,13 +82,15 @@ public class PreflightParser extends PDFParser * Define a one byte encoding that hasn't specific encoding in UTF-8 charset. Avoid unexpected * error when the encoding is Cp5816 */ - public static final Charset ENCODING = StandardCharsets.ISO_8859_1; + private static final Charset ENCODING = StandardCharsets.ISO_8859_1; - protected ValidationResult validationResult; + private Format format = null; - protected PreflightDocument preflightDocument; + private PreflightConfiguration config = null; - protected PreflightContext ctx; + private PreflightDocument preflightDocument; + + private ValidationResult validationResult; /** * Constructor. @@ -104,9 +100,7 @@ public class PreflightParser extends PDFParser */ public PreflightParser(File file) throws IOException { - // TODO move file handling outside of the parser super(new RandomAccessBufferedFileInputStream(file)); - this.setLenient(false); } /** @@ -118,9 +112,7 @@ public PreflightParser(File file) throws IOException */ public PreflightParser(File file, ScratchFile scratch) throws IOException { - // TODO move file handling outside of the parser super(new RandomAccessBufferedFileInputStream(file), scratch); - this.setLenient(false); } /** @@ -131,7 +123,6 @@ public PreflightParser(File file, ScratchFile scratch) throws IOException */ public PreflightParser(String filename) throws IOException { - // TODO move file handling outside of the parser this(new File(filename)); } @@ -144,74 +135,23 @@ public PreflightParser(String filename) throws IOException */ public PreflightParser(String filename, ScratchFile scratch) throws IOException { - // TODO move file handling outside of the parser this(new File(filename), scratch); } /** - * Constructor. This one is slower than the file and the filename constructors, because - * a temporary file will be created. - * - * @param source - * @throws IOException if there is a reading error. - */ - public PreflightParser(RandomAccessRead source) throws IOException - { - // TODO move file handling outside of the parser - super(source); - this.setLenient(false); - } - - /** - * Constructor. This one is slower than the file and the filename constructors, because - * a temporary file will be created. - * - * @param source - * @param scratch - * @throws IOException if there is a reading error. - */ - public PreflightParser(RandomAccessRead source, ScratchFile scratch) throws IOException - { - // TODO move file handling outside of the parser - super(source, scratch); - this.setLenient(false); - } - - /** - * Create an instance of ValidationResult with a ValidationError(UNKNOWN_ERROR) + * Add a validation error to the ValidationResult. * - * @return the ValidationError instance. + * @param error the validation error to be added */ - protected static ValidationResult createUnknownErrorResult() + private void addValidationError(ValidationError error) { - ValidationError error = new ValidationError(PreflightConstants.ERROR_UNKNOWN_ERROR); - return new ValidationResult(error); - } - - /** - * Add the error to the ValidationResult. If the validationResult is null, an instance is created using the - * isWarning boolean of the ValidationError to know if the ValidationResult must be flagged as Valid. - * - * @param error - */ - protected void addValidationError(ValidationError error) - { - if (this.validationResult == null) - { - this.validationResult = new ValidationResult(error.isWarning()); - } - this.validationResult.addError(error); - } - - protected void addValidationErrors(List errors) - { - errors.forEach(this::addValidationError); + validationResult.addError(error); } @Override - public void parse() throws IOException + public PDDocument parse() throws IOException { - parse(Format.PDF_A1B); + return parse(Format.PDF_A1B); } /** @@ -221,9 +161,9 @@ public void parse() throws IOException * format that the document should follow (default {@link Format#PDF_A1B}) * @throws IOException */ - public void parse(Format format) throws IOException + public PDDocument parse(Format format) throws IOException { - parse(format, null); + return parse(format, null); } /** @@ -236,82 +176,51 @@ public void parse(Format format) throws IOException * the default configuration. * @throws IOException */ - public void parse(Format format, PreflightConfiguration config) throws IOException + public PDDocument parse(Format format, PreflightConfiguration config) throws IOException { + this.format = format == null ? Format.PDF_A1B : format; + this.config = config; + validationResult = new ValidationResult(true); + PDDocument pdDocument = null; checkPdfHeader(); try { - super.parse(); + // disable leniency + pdDocument = super.parse(false); } catch (IOException e) { addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_COMMON, e.getMessage())); - throw new SyntaxValidationException(e, this.validationResult); - } - finally - { - // TODO move file handling outside of the parser - IOUtils.closeQuietly(source); + throw new SyntaxValidationException(e, validationResult); } - Format formatToUse = (format == null ? Format.PDF_A1B : format); - createPdfADocument(formatToUse, config); - createContext(); - } - - protected void createPdfADocument(Format format, PreflightConfiguration config) throws IOException - { - COSDocument cosDocument = getDocument(); - this.preflightDocument = new PreflightDocument(cosDocument, format, config); - } - - /** - * Create a validation context. This context is set to the PreflightDocument. - */ - protected void createContext() - { - ctx = new PreflightContext(); - ctx.setDocument(preflightDocument); - preflightDocument.setContext(ctx); - ctx.setXrefTrailerResolver(xrefTrailerResolver); - ctx.setFileLen(this.fileLen); + // create context + PreflightContext context = new PreflightContext(); + context.setDocument(preflightDocument); + preflightDocument.setContext(context); + context.setXrefTrailerResolver(xrefTrailerResolver); + context.setFileLen(fileLen); + preflightDocument.addValidationErrors(validationResult.getErrorsList()); + return pdDocument; } @Override - public PDDocument getPDDocument() throws IOException + protected PDDocument createDocument() throws IOException { - preflightDocument.setResult(validationResult); - // Add XMP MetaData + preflightDocument = new PreflightDocument(getDocument(), format, config); return preflightDocument; } - public PreflightDocument getPreflightDocument() throws IOException - { - return (PreflightDocument) getPDDocument(); - } - // -------------------------------------------------------- // - Below All methods that adds controls on the PDF syntax // -------------------------------------------------------- @Override - /** - * Fill the CosDocument with some object that isn't set by the NonSequentialParser - */ protected void initialParse() throws IOException { super.initialParse(); - // For each ObjectKey, we check if the object has been loaded - // useful for linearized PDFs - Map xrefTable = document.getXrefTable(); - for (Entry entry : xrefTable.entrySet()) - { - COSObject co = document.getObjectFromPool(entry.getKey()); - if (co.getObject() == null) - { - // object isn't loaded - parse the object to load its content - parseObjectDynamically(co, true); - } - } + // Dereference each object to trigger parser validation errors + Set objectKeys = document.getXrefTable().keySet(); + objectKeys.forEach(key -> document.getObjectFromPool(key).getObject()); } /** @@ -319,7 +228,7 @@ protected void initialParse() throws IOException * be a comment with the PDF version (version 1.0 isn't conform to the PDF/A specification) * Second line is a comment with at least 4 bytes greater than 0x80 */ - protected void checkPdfHeader() + private void checkPdfHeader() { try { @@ -333,29 +242,20 @@ protected void checkPdfHeader() String secondLine = readLine(); if (secondLine != null) { - byte[] secondLineAsBytes = secondLine.getBytes(ENCODING.name()); - if (secondLineAsBytes.length >= 5) + boolean secondLineFails = false; + byte[] secondLineAsBytes = secondLine.getBytes(ENCODING); + if (secondLineAsBytes[0] != '%') { - if (secondLineAsBytes[0] != '%') - { - addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_HEADER, - "Second line must begin with '%' followed by at least 4 bytes greater than 127")); - } - else + secondLineFails = true; + } + else if (secondLine.length() >= 5) + { + for (int i = 1; i < 5; ++i) { - for (int i = 1; i < 5; ++i) - { - byte b = secondLineAsBytes[i]; - if ((b & 0xFF) < 0x80) - { - addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_HEADER, - "Second line must begin with '%' followed by at least 4 bytes greater than 127")); - break; - } - } + secondLineFails |= (secondLineAsBytes[i] & 0xFF) < 0x80; } } - else + if (secondLineFails) { addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_HEADER, "Second line must begin with '%' followed by at least 4 bytes greater than 127")); @@ -523,11 +423,11 @@ private long checkStreamKeyWord() throws IOException } long startOffset = source.getPosition(); int nextChar = source.read(); - if (nextChar == 13 && source.peek() == 10) + if (nextChar == ASCII_CR && source.peek() == ASCII_LF) { startOffset += 2; } - else if (nextChar == 10) + else if (nextChar == ASCII_LF) { startOffset++; } @@ -555,12 +455,12 @@ private void checkEndstreamKeyWord(COSDictionary dic, long startOffset) boolean eolFound = false; boolean crlfFound = false; // LF found - if (nextChar == '\n') + if (nextChar == ASCII_LF) { eolFound = true; // check if the LF is part of a CRLF source.rewind(2); - if (source.read() == '\r') + if (source.read() == ASCII_CR) { endOffset--; crlfFound = true; @@ -660,13 +560,8 @@ protected COSString parseCOSString() throws IOException do { nextChar = (char) source.read(); - if (nextChar != '>') + if (!isWhitespace(nextChar) && nextChar != '>') { - if (isWhitespace(nextChar)) - { - // ignore space characters - continue; - } if (Character.digit(nextChar, 16) >= 0) { count++; @@ -752,11 +647,12 @@ protected COSBase parseObjectDynamically(long objNr, int objGenNr, boolean requi // ---- create object key and get object (container) from pool final COSObjectKey objKey = new COSObjectKey(objNr, objGenNr); final COSObject pdfObject = document.getObjectFromPool(objKey); + COSBase referencedObject = !pdfObject.isObjectNull() ? pdfObject.getObject() : null; - if (pdfObject.getObject() == null) + // not previously parsed + if (referencedObject == null) { - // not previously parsed - // ---- read offset or object stream object number from xref table + // read offset or object stream object number from xref table Long offsetOrObjstmObNr = document.getXrefTable().get(objKey); // sanity test to circumvent loops with broken documents @@ -766,13 +662,16 @@ protected COSBase parseObjectDynamically(long objNr, int objGenNr, boolean requi "Object must be defined and must not be compressed object: " + objKey.getNumber() + ":" + objKey.getGeneration())); throw new SyntaxValidationException("Object must be defined and must not be compressed object: " - + objKey.getNumber() + ":" + objKey.getGeneration(), validationResult); + + objKey.getNumber() + ":" + objKey.getGeneration(), + validationResult); } if (offsetOrObjstmObNr == null) { // not defined object -> NULL object (Spec. 1.7, chap. 3.2.9) - pdfObject.setObject(COSNull.NULL); + // remove parser to avoid endless recursion + pdfObject.setToNull(); + } else if (offsetOrObjstmObNr == 0) { @@ -782,144 +681,148 @@ else if (offsetOrObjstmObNr == 0) else if (offsetOrObjstmObNr > 0) { // offset of indirect object in file - // ---- go to object start - source.seek(offsetOrObjstmObNr); - // ---- we must have an indirect object - long readObjNr; - int readObjGen; - - long offset = source.getPosition(); - String line = readLine(); - Pattern pattern = Pattern.compile("(\\d+)\\s(\\d+)\\sobj"); - Matcher matcher = pattern.matcher(line); - if (matcher.matches()) - { - readObjNr = Long.parseLong(matcher.group(1)); - readObjGen = Integer.parseInt(matcher.group(2)); - } - else - { - - addValidationError(new ValidationError(ERROR_SYNTAX_OBJ_DELIMITER, "Single space expected [offset="+offset+"; key="+offsetOrObjstmObNr.toString()+"; line="+line+"; object="+pdfObject.toString()+"]")); - - // reset source cursor to read object information - source.seek(offset); - readObjNr = readObjectNumber(); - readObjGen = readGenerationNumber(); - skipSpaces(); // skip spaces between Object Generation number and the 'obj' keyword - for (char c : OBJ_MARKER) - { - if (source.read() != c) - { - addValidationError(new ValidationError(ERROR_SYNTAX_OBJ_DELIMITER, "Expected pattern '" - + new String(OBJ_MARKER) + " but missed at character '" + c + "'")); - throw new SyntaxValidationException("Expected pattern '" + new String(OBJ_MARKER) - + " but missed at character '" + c + "'", validationResult); - } - } - } - - // ---- consistency check - if ((readObjNr != objKey.getNumber()) || (readObjGen != objKey.getGeneration())) - { - throw new IOException("XREF for " + objKey.getNumber() + ":" + objKey.getGeneration() - + " points to wrong object: " + readObjNr + ":" + readObjGen); - } + referencedObject = parseFileObject(offsetOrObjstmObNr, objKey); + } + else + { + // xref value is object nr of object stream containing object to be parsed + // since our object was not found it means object stream was not parsed so far + referencedObject = parseObjectStreamObject((int) -offsetOrObjstmObNr, objKey); + } + if (referencedObject != null && referencedObject != COSNull.NULL) + { + pdfObject.setObject(referencedObject); + } + else + { + pdfObject.setToNull(); + } + } + return referencedObject; + } - skipSpaces(); - COSBase pb = parseDirObject(); - skipSpaces(); - long endObjectOffset = source.getPosition(); - String endObjectKey = readString(); + private COSBase parseFileObject(Long offsetOrObjstmObNr, final COSObjectKey objKey) + throws IOException + { + // offset of indirect object in file + // ---- go to object start + source.seek(offsetOrObjstmObNr); + // ---- we must have an indirect object + long readObjNr; + int readObjGen; - if (endObjectKey.equals("stream")) - { - source.seek(endObjectOffset); - if (pb instanceof COSDictionary) - { - COSStream stream = parseCOSStream((COSDictionary) pb); - if (securityHandler != null) - { - securityHandler.decryptStream(stream, objNr, objGenNr); - } - pb = stream; - } - else - { - // this is not legal - // the combination of a dict and the stream/endstream forms a complete stream object - throw new IOException("Stream not preceded by dictionary (offset: " + offsetOrObjstmObNr + ")."); - } - skipSpaces(); - endObjectOffset = source.getPosition(); - endObjectKey = readString(); + long offset = source.getPosition(); + String line = readLine(); + Pattern pattern = Pattern.compile("(\\d+)\\s(\\d+)\\sobj"); + Matcher matcher = pattern.matcher(line); + if (matcher.matches()) + { + readObjNr = Long.parseLong(matcher.group(1)); + readObjGen = Integer.parseInt(matcher.group(2)); + } + else + { - // we have case with a second 'endstream' before endobj - if (!endObjectKey.startsWith("endobj") && endObjectKey.startsWith("endstream")) - { - endObjectKey = endObjectKey.substring(9).trim(); - if (endObjectKey.length() == 0) - { - // no other characters in extra endstream line - endObjectKey = readString(); // read next line - } - } - } - else if (securityHandler != null) + addValidationError(new ValidationError(ERROR_SYNTAX_OBJ_DELIMITER, + "Single space expected [offset=" + offset + "; key=" + + offsetOrObjstmObNr.toString() + "; line=" + line + "; object=" + + objKey.getNumber() + " " + objKey.getGeneration() + "]")); + + // reset source cursor to read object information + source.seek(offset); + readObjNr = readObjectNumber(); + readObjGen = readGenerationNumber(); + skipSpaces(); // skip spaces between Object Generation number and the 'obj' keyword + for (char c : OBJ_MARKER) + { + if (source.read() != c) { - securityHandler.decrypt(pb, objNr, objGenNr); + addValidationError(new ValidationError(ERROR_SYNTAX_OBJ_DELIMITER, + "Expected pattern '" + new String(OBJ_MARKER) + + " but missed at character '" + c + "'")); + throw new SyntaxValidationException("Expected pattern '" + + new String(OBJ_MARKER) + " but missed at character '" + c + "'", + validationResult); } + } + } - pdfObject.setObject(pb); + // ---- consistency check + if ((readObjNr != objKey.getNumber()) || (readObjGen != objKey.getGeneration())) + { + throw new IOException("XREF for " + objKey.getNumber() + ":" + objKey.getGeneration() + + " points to wrong object: " + readObjNr + ":" + readObjGen); + } - if (!endObjectKey.startsWith("endobj")) - { - throw new IOException("Object (" + readObjNr + ":" + readObjGen + ") at offset " - + offsetOrObjstmObNr + " does not end with 'endobj'."); - } - else - { - offset = source.getPosition(); - source.seek(endObjectOffset - 1); - if (!nextIsEOL()) - { - addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_OBJ_DELIMITER, - "EOL expected before the 'endobj' keyword at offset "+source.getPosition())); - } - source.seek(offset); - } + skipSpaces(); + COSBase referencedObject = parseDirObject(); + skipSpaces(); + long endObjectOffset = source.getPosition(); + String endObjectKey = readString(); - if (!nextIsEOL()) + if (endObjectKey.equals("stream")) + { + source.seek(endObjectOffset); + if (referencedObject instanceof COSDictionary) + { + COSStream stream = parseCOSStream((COSDictionary) referencedObject); + if (securityHandler != null) { - addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_OBJ_DELIMITER, - "EOL expected after the 'endobj' keyword at offset "+source.getPosition())); + securityHandler.decryptStream(stream, readObjNr, readObjGen); } + referencedObject = stream; } else { - // xref value is object nr of object stream containing object to be parsed; - // since our object was not found it means object stream was not parsed so far - final int objstmObjNr = (int) (-offsetOrObjstmObNr); - final COSBase objstmBaseObj = parseObjectDynamically(objstmObjNr, 0, true); - if (objstmBaseObj instanceof COSStream) + // this is not legal + // the combination of a dict and the stream/endstream forms a complete stream object + throw new IOException( + "Stream not preceded by dictionary (offset: " + offsetOrObjstmObNr + ")."); + } + skipSpaces(); + endObjectOffset = source.getPosition(); + endObjectKey = readString(); + + // we have case with a second 'endstream' before endobj + if (!endObjectKey.startsWith("endobj") && endObjectKey.startsWith("endstream")) + { + endObjectKey = endObjectKey.substring(9).trim(); + if (endObjectKey.length() == 0) { - // parse object stream - PDFObjectStreamParser parser = new PDFObjectStreamParser((COSStream) objstmBaseObj, document); - // register all objects which are referenced to be contained in object stream - parser.parse().forEach(next -> - { - COSObjectKey stmObjKey = new COSObjectKey(next); - Long offset = document.getXrefTable().get(stmObjKey); - if (offset != null && offset == -objstmObjNr) - { - COSObject stmObj = document.getObjectFromPool(stmObjKey); - stmObj.setObject(next.getObject()); - } - }); + // no other characters in extra endstream line + endObjectKey = readString(); // read next line } } } - return pdfObject.getObject(); + else if (securityHandler != null) + { + securityHandler.decrypt(referencedObject, readObjNr, readObjGen); + } + if (!endObjectKey.startsWith("endobj")) + { + throw new IOException("Object (" + readObjNr + ":" + readObjGen + ") at offset " + + offsetOrObjstmObNr + " does not end with 'endobj'."); + } + else + { + offset = source.getPosition(); + source.seek(endObjectOffset - 1); + if (!nextIsEOL()) + { + addValidationError( + new ValidationError(PreflightConstants.ERROR_SYNTAX_OBJ_DELIMITER, + "EOL expected before the 'endobj' keyword at offset " + + source.getPosition())); + } + source.seek(offset); + } + + if (!nextIsEOL()) + { + addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_OBJ_DELIMITER, + "EOL expected after the 'endobj' keyword at offset " + source.getPosition())); + } + return referencedObject; } @Override @@ -931,27 +834,49 @@ protected int lastIndexOf(final char[] pattern, final byte[] buf, final int endO // this is the offset of the last %%EOF sequence. // nothing should be present after this sequence. int tmpOffset = offset + pattern.length; - if (tmpOffset != buf.length) + int offsetDiff = buf.length - tmpOffset; + // EOL is authorized + if (offsetDiff > 2 + || (offsetDiff == 2 + && (buf[tmpOffset] != ASCII_CR || buf[tmpOffset + 1] != ASCII_LF)) + || (offsetDiff == 1 + && (buf[tmpOffset] != ASCII_CR && buf[tmpOffset] != ASCII_LF))) { - // EOL is authorized - if ((buf.length - tmpOffset) > 2 - || (buf.length - tmpOffset == 2 && (buf[tmpOffset] != 13 || buf[tmpOffset + 1] != 10)) - || (buf.length - tmpOffset == 1 && (buf[tmpOffset] != 13 && buf[tmpOffset] != 10))) + long position; + try { - long position; - try - { - position = source.getPosition(); - } - catch (IOException ex) - { - position = Long.MIN_VALUE; - } - addValidationError(new ValidationError(ERROR_SYNTAX_TRAILER_EOF, - "File contains data after the last %%EOF sequence at offset " + position)); + position = source.getPosition(); } + catch (IOException ex) + { + position = Long.MIN_VALUE; + } + addValidationError(new ValidationError(ERROR_SYNTAX_TRAILER_EOF, + "File contains data after the last %%EOF sequence at offset " + position)); } } return offset; } + + /** + * Load and validate the given file. Returns the validation result and closes the read pdf. + * + * @param file thew file to be read and validated + * @return the validation result + * @throws IOException in case of a file reading or parsing error + */ + public static ValidationResult validate(File file) throws IOException + { + ValidationResult result; + PreflightParser parser = new PreflightParser(file); + try (PreflightDocument document = (PreflightDocument) parser.parse()) + { + result = document.validate(); + } + catch (SyntaxValidationException e) + { + result = e.getResult(); + } + return result; + } } diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java b/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java index cc1fd5def38..d225e67f896 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java @@ -32,36 +32,47 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream; -import org.apache.pdfbox.io.RandomAccessRead; -import org.apache.pdfbox.preflight.PreflightDocument; +import org.apache.pdfbox.preflight.Format; import org.apache.pdfbox.preflight.ValidationResult; import org.apache.pdfbox.preflight.ValidationResult.ValidationError; -import org.apache.pdfbox.preflight.exception.SyntaxValidationException; import org.w3c.dom.Document; import org.w3c.dom.Element; public class XmlResultParser { - + /** + * Validate the given file. + * + * @param file the file to be validated + * @return the validation results as XML + * @throws IOException if something went wrong + */ public Element validate(File file) throws IOException { - return validate(new RandomAccessBufferedFileInputStream(file), file.getName()); + return validate(file, file.getName()); } + /** + * Validate the given file. Add the validation results to the given XML tree. + * + * @param rdocument XML based validation results of a former run + * @param file the file to be validated + * @return the validation results as XML + * @throws IOException if something went wrong + */ public Element validate(Document rdocument, File file) throws IOException { - return validate(rdocument, new RandomAccessBufferedFileInputStream(file), file.getName()); + return validate(rdocument, file, file.getName()); } - private Element validate(RandomAccessRead source, String name) throws IOException + private Element validate(File file, String name) throws IOException { try { @SuppressWarnings({"squid:S2755"}) // self-created XML Document rdocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - return validate(rdocument, source, name); + return validate(rdocument, file, name); } catch (ParserConfigurationException e) { @@ -70,29 +81,15 @@ private Element validate(RandomAccessRead source, String name) throws IOExceptio } - private Element validate(Document rdocument, RandomAccessRead source, String name) + private Element validate(Document rdocument, File file, String name) throws IOException { - String pdfType = null; + String pdfType = Format.PDF_A1B.getFname(); ValidationResult result; long before = System.currentTimeMillis(); try { - PreflightParser parser = new PreflightParser(source); - try - { - parser.parse(); - try (PreflightDocument document = parser.getPreflightDocument()) - { - document.validate(); - pdfType = document.getSpecification().getFname(); - result = document.getResult(); - } - } - catch (SyntaxValidationException e) - { - result = e.getResult(); - } + result = PreflightParser.validate(file); } catch(Exception e) { @@ -175,7 +172,8 @@ private Map cleanErrorList(List errors return cleaned; } - protected Element generateFailureResponse(Document rdocument, String name,long duration, String pdfType, Exception e) + private Element generateFailureResponse(Document rdocument, String name, long duration, + String pdfType, Exception e) { Element preflight = generateResponseSkeleton(rdocument, name, duration); // valid ? diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java b/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java index c10c096bed0..985caf08240 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java @@ -39,7 +39,6 @@ import static org.apache.pdfbox.preflight.PreflightConfiguration.ANNOTATIONS_PROCESS; -import static org.apache.pdfbox.preflight.PreflightConstants.ACROFORM_DICTIONARY_KEY_NEED_APPEARANCES; import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_ACTION_FORBIDDEN_ADDITIONAL_ACTIONS_FIELD; import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_ACTION_FORBIDDEN_WIDGET_ACTION_FIELD; import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_BODY; @@ -85,7 +84,7 @@ public void validate(PreflightContext ctx) throws ValidationException */ protected void checkNeedAppearences(PreflightContext ctx, PDAcroForm acroForm) { - if (acroForm.getCOSObject().getBoolean(ACROFORM_DICTIONARY_KEY_NEED_APPEARANCES, false)) + if (acroForm.getCOSObject().getBoolean(COSName.NEED_APPEARANCES, false)) { addValidationError(ctx, new ValidationError(ERROR_SYNTAX_DICT_INVALID, "NeedAppearance is present with the value \"true\"")); diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java b/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java index 4a95909f899..d288c2c1030 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java @@ -252,8 +252,8 @@ public void validateOutputIntent(PreflightContext ctx) throws ValidationExceptio else { // S entry is mandatory and must be equals to GTS_PDFA1 - String sValue = outputIntentDict.getNameAsString(OUTPUT_INTENT_DICTIONARY_KEY_S); - if (!OUTPUT_INTENT_DICTIONARY_VALUE_GTS_PDFA1.equals(sValue)) + COSName sValue = outputIntentDict.getCOSName(COSName.S); + if (!COSName.GTS_PDFA1.equals(sValue)) { addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_S_VALUE_INVALID, "The S entry of the OutputIntent isn't GTS_PDFA1")); @@ -262,7 +262,7 @@ public void validateOutputIntent(PreflightContext ctx) throws ValidationExceptio // OutputConditionIdentifier is a mandatory field String outputConditionIdentifier = outputIntentDict - .getString(OUTPUT_INTENT_DICTIONARY_KEY_OUTPUT_CONDITION_IDENTIFIER); + .getString(COSName.OUTPUT_CONDITION_IDENTIFIER); if (outputConditionIdentifier == null) { // empty string is authorized (it may be an application specific value) @@ -284,7 +284,7 @@ public void validateOutputIntent(PreflightContext ctx) throws ValidationExceptio PreflightConfiguration config = ctx.getConfig(); if (config.isLazyValidation() && !isStandardICCCharacterization(outputConditionIdentifier)) { - String info = outputIntentDict.getString(COSName.getPDFName(OUTPUT_INTENT_DICTIONARY_KEY_INFO)); + String info = outputIntentDict.getString(COSName.INFO); if (info == null || "".equals(info)) { ValidationError error = new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/process/FileSpecificationValidationProcess.java b/preflight/src/main/java/org/apache/pdfbox/preflight/process/FileSpecificationValidationProcess.java index 95083af90d6..06c96870c14 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/process/FileSpecificationValidationProcess.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/process/FileSpecificationValidationProcess.java @@ -21,19 +21,10 @@ package org.apache.pdfbox.preflight.process; -import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_EMBEDDED_FILES; -import static org.apache.pdfbox.preflight.PreflightConstants.FILE_SPECIFICATION_KEY_EMBEDDED_FILE; -import static org.apache.pdfbox.preflight.PreflightConstants.FILE_SPECIFICATION_VALUE_TYPE; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.cos.COSName; -import org.apache.pdfbox.cos.COSObject; -import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.preflight.PreflightConstants; import org.apache.pdfbox.preflight.PreflightContext; import org.apache.pdfbox.preflight.ValidationResult.ValidationError; import org.apache.pdfbox.preflight.exception.ValidationException; @@ -48,24 +39,10 @@ public class FileSpecificationValidationProcess extends AbstractProcess @Override public void validate(PreflightContext ctx) throws ValidationException { - PDDocument pdfDoc = ctx.getDocument(); - COSDocument cDoc = pdfDoc.getDocument(); + COSDocument cDoc = ctx.getDocument().getDocument(); - List lCOSObj = cDoc.getObjects(); - for (Object o : lCOSObj) - { - COSBase cBase = ((COSObject) o).getObject(); - if (cBase instanceof COSDictionary) - { - COSDictionary dic = (COSDictionary) cBase; - String type = dic.getNameAsString(COSName.TYPE); - if (FILE_SPECIFICATION_VALUE_TYPE.equals(type) || COSName.F.getName().equals(type)) - { - // ---- It is a file specification - validateFileSpecification(ctx, dic); - } - } - } + cDoc.getObjectsByType(COSName.FILESPEC, COSName.F) + .forEach(o -> validateFileSpecification(ctx, (COSDictionary) o.getObject())); } /** @@ -73,20 +50,16 @@ public void validate(PreflightContext ctx) throws ValidationException * * @param ctx the preflight context. * @param fileSpec the FileSpec Dictionary. - * @return the list of validation errors. */ - public List validateFileSpecification(PreflightContext ctx, COSDictionary fileSpec) + public void validateFileSpecification(PreflightContext ctx, COSDictionary fileSpec) { - List result = new ArrayList<>(0); - // ---- Check dictionary entries // ---- Only the EF entry is forbidden - if (fileSpec.getItem(COSName.getPDFName(FILE_SPECIFICATION_KEY_EMBEDDED_FILE)) != null) + if (fileSpec.getItem(COSName.EF) != null) { - addValidationError(ctx, new ValidationError(ERROR_SYNTAX_EMBEDDED_FILES, + addValidationError(ctx, + new ValidationError(PreflightConstants.ERROR_SYNTAX_EMBEDDED_FILES, "EmbeddedFile entry is present in a FileSpecification dictionary")); } - - return result; } } diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/process/PageTreeValidationProcess.java b/preflight/src/main/java/org/apache/pdfbox/preflight/process/PageTreeValidationProcess.java index 7161cd3ed7d..aa160574695 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/process/PageTreeValidationProcess.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/process/PageTreeValidationProcess.java @@ -57,7 +57,8 @@ public void validate(PreflightContext context) throws ValidationException context.setCurrentPageNumber(p); validatePage(context, page); - if (context.getDocument().getResult().getErrorsList().size() > context.getConfig().getMaxErrors()) + if (context.getDocument().getValidationErrors().size() > context.getConfig() + .getMaxErrors()) { context.addValidationError(new ValidationError(PreflightConstants.ERROR_UNKNOWN_ERROR, "Over " + context.getConfig().getMaxErrors() + @@ -74,7 +75,7 @@ public void validate(PreflightContext context) throws ValidationException } } - protected void validatePage(PreflightContext context, PDPage page) throws ValidationException + private void validatePage(PreflightContext context, PDPage page) throws ValidationException { ContextHelper.validateElement(context, page, PAGE_PROCESS); } diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java b/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java index 84131aeb82a..24f3b072b40 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java @@ -26,13 +26,15 @@ import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_STREAM_LENGTH_MISSING; import java.util.List; +import java.util.Map.Entry; +import java.util.stream.Collectors; import org.apache.pdfbox.cos.COSArray; import org.apache.pdfbox.cos.COSBase; +import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.cos.COSName; -import org.apache.pdfbox.cos.COSObject; +import org.apache.pdfbox.cos.COSObjectKey; import org.apache.pdfbox.cos.COSStream; -import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.preflight.PreflightContext; import org.apache.pdfbox.preflight.ValidationResult.ValidationError; import org.apache.pdfbox.preflight.exception.ValidationException; @@ -44,24 +46,29 @@ public class StreamValidationProcess extends AbstractProcess @Override public void validate(PreflightContext ctx) throws ValidationException { - PDDocument pdfDoc = ctx.getDocument(); + COSDocument cosDocument = ctx.getDocument().getDocument(); - List lCOSObj = pdfDoc.getDocument().getObjects(); - for (COSObject cObj : lCOSObj) + // get all keys with a positive offset in ascending order to read the pdf linear + List objectKeys = cosDocument.getXrefTable().entrySet().stream() // + .filter(e -> e.getValue() > 0L) // + .sorted((e1, e2) -> e1.getValue().compareTo(e2.getValue())) // + .map(Entry::getKey) // + .collect(Collectors.toList()); + + for (COSObjectKey objectKey : objectKeys) { // If this object represents a Stream, the Dictionary must contain the Length key - COSBase cBase = cObj.getObject(); + COSBase cBase = cosDocument.getObjectFromPool(objectKey).getObject(); if (cBase instanceof COSStream) { - validateStreamObject(ctx, cObj); + validateStreamObject(ctx, cBase); } } } - public void validateStreamObject(PreflightContext context, COSObject cObj) throws ValidationException + public void validateStreamObject(PreflightContext context, COSBase cObj) { - COSStream streamObj = (COSStream) cObj.getObject(); - + COSStream streamObj = (COSStream) cObj; // ---- Check dictionary entries // ---- Only the Length entry is mandatory // ---- In a PDF/A file, F, FFilter and FDecodeParms are forbidden diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java b/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java index 03f60071542..7e6a9eec1d6 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java @@ -21,15 +21,6 @@ package org.apache.pdfbox.preflight.process; -import static org.apache.pdfbox.preflight.PreflightConstants.DICTIONARY_KEY_LINEARIZED; -import static org.apache.pdfbox.preflight.PreflightConstants.DICTIONARY_KEY_LINEARIZED_E; -import static org.apache.pdfbox.preflight.PreflightConstants.DICTIONARY_KEY_LINEARIZED_H; -import static org.apache.pdfbox.preflight.PreflightConstants.DICTIONARY_KEY_LINEARIZED_L; -import static org.apache.pdfbox.preflight.PreflightConstants.DICTIONARY_KEY_LINEARIZED_N; -import static org.apache.pdfbox.preflight.PreflightConstants.DICTIONARY_KEY_LINEARIZED_O; -import static org.apache.pdfbox.preflight.PreflightConstants.DICTIONARY_KEY_LINEARIZED_T; -import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_TRAILER; - import java.util.List; import org.apache.pdfbox.cos.COSArray; @@ -55,7 +46,7 @@ public void validate(PreflightContext ctx) throws ValidationException { PDDocument pdfDoc = ctx.getDocument(); - COSDictionary linearizedDict = getLinearizedDictionary(pdfDoc); + COSDictionary linearizedDict = pdfDoc.getDocument().getLinearizedDictionary(); // linearized files have two trailers, everything else is not a linearized file // so don't make the checks for updated linearized files if (linearizedDict != null && ctx.getXrefTrailerResolver().getTrailerCount() == 2 && @@ -95,7 +86,8 @@ protected void checkTrailersForLinearizedPDF14(PreflightContext ctx) COSDictionary first = ctx.getXrefTrailerResolver().getFirstTrailer(); if (first == null) { - addValidationError(ctx, new ValidationError(ERROR_SYNTAX_TRAILER, "There are no trailer in the PDF file")); + addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER, + "There are no trailer in the PDF file")); } else { @@ -116,9 +108,7 @@ protected void checkTrailersForLinearizedPDF14(PreflightContext ctx) */ protected void checkTrailersForLinearizedPDF15(PreflightContext ctx) { - PDDocument pdfDoc = ctx.getDocument(); - - COSDocument cosDocument = pdfDoc.getDocument(); + COSDocument cosDocument = ctx.getDocument().getDocument(); List xrefs = cosDocument.getObjectsByType(COSName.XREF); if (xrefs.isEmpty()) @@ -221,137 +211,71 @@ protected boolean compareIds(COSDictionary first, COSDictionary last) */ protected void checkMainTrailer(PreflightContext ctx, COSDictionary trailer) { - boolean id = false; - boolean root = false; - boolean size = false; - boolean prev = false; - boolean info = false; - boolean encrypt = false; - - for (COSName cosName : trailer.keySet()) - { - if (cosName.equals(COSName.ENCRYPT)) - { - encrypt = true; - } - if (cosName.equals(COSName.SIZE)) - { - size = true; - } - if (cosName.equals(COSName.PREV)) - { - prev = true; - } - if (cosName.equals(COSName.ROOT)) - { - root = true; - } - if (cosName.equals(COSName.INFO)) - { - info = true; - } - if (cosName.equals(COSName.ID)) - { - id = true; - } - } - // PDF/A Trailer dictionary must contain the ID key - if (!id) + if (!trailer.containsKey(COSName.ID)) { - addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_MISSING_ID, - "The trailer dictionary doesn't contain ID")); + addValidationError(ctx, + new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_MISSING_ID, + "The trailer dictionary doesn't contain ID")); } - else + else if (trailer.getCOSArray(COSName.ID) == null) { - COSBase trailerId = trailer.getDictionaryObject(COSName.ID); - if (!(trailerId instanceof COSArray)) - { - addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID, - "The trailer dictionary contains an id but it isn't an array")); - } + addValidationError(ctx, + new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID, + "The trailer dictionary contains an id but it isn't an array")); } + // PDF/A Trailer dictionary mustn't contain the Encrypt key - if (encrypt) + if (trailer.containsKey(COSName.ENCRYPT)) { addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_ENCRYPT, "The trailer dictionary contains Encrypt")); } + // PDF Trailer dictionary must contain the Size key - if (!size) + if (!trailer.containsKey(COSName.SIZE)) { - addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_MISSING_SIZE, - "The trailer dictionary doesn't contain Size")); + addValidationError(ctx, + new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_MISSING_SIZE, + "The trailer dictionary doesn't contain Size")); } - else + else if (!(trailer.getDictionaryObject(COSName.SIZE) instanceof COSInteger)) { - COSBase trailerSize = trailer.getDictionaryObject(COSName.SIZE); - if (!(trailerSize instanceof COSInteger)) - { - addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID, - "The trailer dictionary contains a size but it isn't an integer")); - } + addValidationError(ctx, + new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID, + "The trailer dictionary contains a size but it isn't an integer")); } // PDF Trailer dictionary must contain the Root key - if (!root) + if (!trailer.containsKey(COSName.ROOT)) { - addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_MISSING_ROOT, - "The trailer dictionary doesn't contain Root")); + addValidationError(ctx, + new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_MISSING_ROOT, + "The trailer dictionary doesn't contain Root")); } - else + else if (trailer.getCOSDictionary(COSName.ROOT) == null) { - COSBase trailerRoot = trailer.getDictionaryObject(COSName.ROOT); - if (!(trailerRoot instanceof COSDictionary)) - { - addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID, - "The trailer dictionary contains a root but it isn't a dictionary")); - } + addValidationError(ctx, + new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID, + "The trailer dictionary contains a root but it isn't a dictionary")); } + // PDF Trailer dictionary may contain the Prev key - if (prev) + if (trailer.containsKey(COSName.PREV) + && !(trailer.getDictionaryObject(COSName.PREV) instanceof COSInteger)) { - COSBase trailerPrev = trailer.getDictionaryObject(COSName.PREV); - if (!(trailerPrev instanceof COSInteger)) - { - addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID, - "The trailer dictionary contains a prev but it isn't an integer")); - } - } - // PDF Trailer dictionary may contain the Info key - if (info) - { - COSBase trailerInfo = trailer.getDictionaryObject(COSName.INFO); - if (!(trailerInfo instanceof COSDictionary)) - { - addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID, - "The trailer dictionary contains an info but it isn't a dictionary")); - } + addValidationError(ctx, + new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID, + "The trailer dictionary contains a prev but it isn't an integer")); } - } - /** - * According to the PDF Reference, A linearized PDF contain a dictionary as first object (linearized dictionary) and - * only this one in the first section. - * - * @param document the document to validate. - * @return the linearization dictionary or null. - */ - protected COSDictionary getLinearizedDictionary(PDDocument document) - { - // ---- Get Ref to obj - COSDocument cDoc = document.getDocument(); - List lObj = cDoc.getObjects(); - for (COSObject object : lObj) + // PDF Trailer dictionary may contain the Info key + if (trailer.containsKey(COSName.INFO) && trailer.getCOSDictionary(COSName.INFO) == null) { - COSBase curObj = object.getObject(); - if (curObj instanceof COSDictionary - && ((COSDictionary) curObj).keySet().contains(COSName.getPDFName(DICTIONARY_KEY_LINEARIZED))) - { - return (COSDictionary) curObj; - } + addValidationError(ctx, + new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_TYPE_INVALID, + "The trailer dictionary contains an info but it isn't a dictionary")); } - return null; } /** @@ -364,41 +288,12 @@ protected void checkLinearizedDictionary(PreflightContext ctx, COSDictionary lin { // ---- check if all keys are authorized in a linearized dictionary // ---- Linearized dictionary must contain the lhoent keys - boolean l = false; - boolean h = false; - boolean o = false; - boolean e = false; - boolean n = false; - boolean t = false; - - for (COSName key : linearizedDict.keySet()) - { - String cosName = key.getName(); - if (cosName.equals(DICTIONARY_KEY_LINEARIZED_L)) - { - l = true; - } - if (cosName.equals(DICTIONARY_KEY_LINEARIZED_H)) - { - h = true; - } - if (cosName.equals(DICTIONARY_KEY_LINEARIZED_O)) - { - o = true; - } - if (cosName.equals(DICTIONARY_KEY_LINEARIZED_E)) - { - e = true; - } - if (cosName.equals(DICTIONARY_KEY_LINEARIZED_N)) - { - n = true; - } - if (cosName.equals(DICTIONARY_KEY_LINEARIZED_T)) - { - t = true; - } - } + boolean l = linearizedDict.getItem(COSName.L) != null; + boolean h = linearizedDict.getItem(COSName.H) != null; + boolean o = linearizedDict.getItem(COSName.O) != null; + boolean e = linearizedDict.getItem(COSName.E) != null; + boolean n = linearizedDict.getItem(COSName.N) != null; + boolean t = linearizedDict.getItem(COSName.T) != null; if (!(l && h && o && e && t && n)) { diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/process/XRefValidationProcess.java b/preflight/src/main/java/org/apache/pdfbox/preflight/process/XRefValidationProcess.java index 0fc7c01014d..51130089d11 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/process/XRefValidationProcess.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/process/XRefValidationProcess.java @@ -40,7 +40,7 @@ public void validate(PreflightContext ctx) throws ValidationException { addValidationError(ctx, new ValidationError(ERROR_SYNTAX_TRAILER, "/XRef cross reference streams are not allowed")); } - if (document.getObjects().size() > PreflightConstants.MAX_INDIRECT_OBJ) + if (document.getXrefTable().size() > PreflightConstants.MAX_INDIRECT_OBJ) { addValidationError(ctx, new ValidationError(ERROR_SYNTAX_INDIRECT_OBJ_RANGE, "Too many indirect objects")); } diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/utils/RenderingIntents.java b/preflight/src/main/java/org/apache/pdfbox/preflight/utils/RenderingIntents.java index edbb27e325c..4cbf984082e 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/utils/RenderingIntents.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/utils/RenderingIntents.java @@ -21,15 +21,12 @@ package org.apache.pdfbox.preflight.utils; -import static org.apache.pdfbox.preflight.PreflightConstants.RENDERING_INTENT_ABS_COLOR; -import static org.apache.pdfbox.preflight.PreflightConstants.RENDERING_INTENT_PERCEPTUAL; -import static org.apache.pdfbox.preflight.PreflightConstants.RENDERING_INTENT_REL_COLOR; -import static org.apache.pdfbox.preflight.PreflightConstants.RENDERING_INTENT_SATURATION; - import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.apache.pdfbox.cos.COSName; + /** * This class contains a static list of RenderingIntent values to allow an easy RenderingIntent value validation. Here * is the content of the RenderingIntent list : @@ -42,15 +39,15 @@ */ public final class RenderingIntents { - private static final List RENDERING_INTENTS; + private static final List RENDERING_INTENTS; static { - List al = new ArrayList<>(4); - al.add(RENDERING_INTENT_REL_COLOR); - al.add(RENDERING_INTENT_ABS_COLOR); - al.add(RENDERING_INTENT_PERCEPTUAL); - al.add(RENDERING_INTENT_SATURATION); + List al = new ArrayList<>(4); + al.add(COSName.RELATIVE_COLORIMETRIC); + al.add(COSName.ABSOLUTE_COLORIMETRIC); + al.add(COSName.PERCEPTUAL); + al.add(COSName.SATURATION); RENDERING_INTENTS = Collections.unmodifiableList(al); } @@ -58,8 +55,8 @@ private RenderingIntents() { } - public static boolean contains(String riArg) + public static boolean contains(COSName renderingIntent) { - return RENDERING_INTENTS.contains(riArg); + return RENDERING_INTENTS.contains(renderingIntent); } } diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjImageValidator.java b/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjImageValidator.java index dae435f4d5a..313545197c4 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjImageValidator.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/xobject/XObjImageValidator.java @@ -86,7 +86,7 @@ protected void checkAlternates() throws ValidationException /* * 6.2.4 if interpolates, value = false */ - protected void checkInterpolate() throws ValidationException + protected void checkInterpolate() { if (this.xobject.getItem(COSName.INTERPOLATE) != null && this.xobject.getBoolean(COSName.INTERPOLATE, true)) @@ -99,16 +99,14 @@ protected void checkInterpolate() throws ValidationException /* * 6.2.4 Intent has specific values */ - protected void checkIntent() throws ValidationException + protected void checkIntent() { - if (this.xobject.getItem("Intent") != null) + COSName renderingIntent = xobject.getCOSName(COSName.INTENT); + if (renderingIntent != null && !RenderingIntents.contains(renderingIntent)) { - String s = this.xobject.getNameAsString("Intent"); - if (!RenderingIntents.contains(s)) - { - context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY, - "Unexpected value '" + s + "' for Intent key in image")); - } + context.addValidationError(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY, + "Unexpected value '" + renderingIntent.getName() + + "' for Intent key in image")); } } diff --git a/preflight/src/test/java/org/apache/pdfbox/preflight/Benchmark.java b/preflight/src/test/java/org/apache/pdfbox/preflight/Benchmark.java index 1494921a688..ee54ed64658 100644 --- a/preflight/src/test/java/org/apache/pdfbox/preflight/Benchmark.java +++ b/preflight/src/test/java/org/apache/pdfbox/preflight/Benchmark.java @@ -75,19 +75,13 @@ public static void main(String[] args) throws Exception { File file = lfd.get(i % size); long startLTime = System.currentTimeMillis(); - PreflightParser parser = new PreflightParser(file); - parser.parse(); - try (PreflightDocument document = parser.getPreflightDocument()) + ValidationResult result = PreflightParser.validate(file); + if (!result.isValid()) { - document.validate(); - ValidationResult result = document.getResult(); - if (!result.isValid()) + resFile.write(file.getAbsolutePath() + " isn't PDF/A\n"); + for (ValidationError error : result.getErrorsList()) { - resFile.write(file.getAbsolutePath() + " isn't PDF/A\n"); - for (ValidationError error : result.getErrorsList()) - { - resFile.write(error.getErrorCode() + " : " + error.getDetails() + "\n"); - } + resFile.write(error.getErrorCode() + " : " + error.getDetails() + "\n"); } } long endLTime = System.currentTimeMillis(); diff --git a/preflight/src/test/java/org/apache/pdfbox/preflight/TestInvalidDirectory.java b/preflight/src/test/java/org/apache/pdfbox/preflight/TestInvalidDirectory.java index 3f08acc4718..59074dbd9e7 100644 --- a/preflight/src/test/java/org/apache/pdfbox/preflight/TestInvalidDirectory.java +++ b/preflight/src/test/java/org/apache/pdfbox/preflight/TestInvalidDirectory.java @@ -26,7 +26,6 @@ import java.util.Collection; import java.util.List; -import org.apache.pdfbox.preflight.exception.SyntaxValidationException; import org.apache.pdfbox.preflight.parser.PreflightParser; import org.junit.Assert; import org.junit.Test; @@ -50,29 +49,8 @@ public TestInvalidDirectory(File file) @Test public void validate() throws Exception { - PreflightDocument document = null; - System.out.println(target); - ValidationResult result = null; - try - { - PreflightParser parser = new PreflightParser(target); - parser.parse(); - document = (PreflightDocument) parser.getPDDocument(); - document.validate(); - result = document.getResult(); - } - catch (SyntaxValidationException e) - { - result = e.getResult(); - } - finally - { - if (document != null) - { - document.close(); - } - } + ValidationResult result = PreflightParser.validate(target); Assert.assertFalse("Test of " + target, result.isValid()); } diff --git a/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorBavaria.java b/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorBavaria.java index 707431e1647..8aacfac8f29 100644 --- a/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorBavaria.java +++ b/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorBavaria.java @@ -36,7 +36,6 @@ import org.apache.commons.io.FileUtils; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.preflight.ValidationResult.ValidationError; -import org.apache.pdfbox.preflight.exception.SyntaxValidationException; import org.apache.pdfbox.preflight.parser.PreflightParser; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -175,27 +174,9 @@ public TestIsartorBavaria(File path, Set errorSet) @Test() public void validate() throws Exception { - PreflightDocument document = null; - try + ValidationResult result = PreflightParser.validate(file); + if (result != null) { - ValidationResult result; - try - { - PreflightParser parser = new PreflightParser(file); - parser.parse(); - document = (PreflightDocument) parser.getPDDocument(); - // to speeds up tests, skip validation of page count is over the limit - if (document.getNumberOfPages() < 8191) - { - document.validate(); - } - result = document.getResult(); - } - catch (SyntaxValidationException e) - { - result = e.getResult(); - } - if (this.expectedErrorSet.isEmpty()) { Set errorSet = new HashSet<>(); @@ -205,7 +186,7 @@ public void validate() throws Exception } StringBuilder message = new StringBuilder(); message.append(file.getName()); - message.append( " : PDF/A file should be valid, but has error"); + message.append(" : PDF/A file should be valid, but has error"); if (errorSet.size() > 1) { message.append('s'); @@ -221,8 +202,8 @@ public void validate() throws Exception } else { - assertFalse(file.getName() + " : PDF/A file should be invalid (expected " + - this.expectedErrorSet + ")", result.isValid()); //TODO + assertFalse(file.getName() + " : PDF/A file should be invalid (expected " + + this.expectedErrorSet + ")", result.isValid()); // TODO assertTrue(file.getName() + " : Should find at least one error", result.getErrorsList().size() > 0); @@ -241,8 +222,8 @@ public void validate() throws Exception } if (isartorResultFile != null && !logged) { - String log = file.getName().replace(".pdf", "") + "#" + error.getErrorCode() + - "#" + error.getDetails() + "\n"; + String log = file.getName().replace(".pdf", "") + "#" + + error.getErrorCode() + "#" + error.getDetails() + "\n"; isartorResultFile.write(log.getBytes()); } } @@ -251,7 +232,7 @@ public void validate() throws Exception allFound = false; break; } - + // log only in the first inner loop logged = true; } @@ -277,12 +258,5 @@ public void validate() throws Exception // if each of the expected errors are found, we consider test valid } } - finally - { - if (document != null) - { - document.close(); - } - } } } diff --git a/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3741.java b/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3741.java index 5dddf0cf320..b185689e494 100644 --- a/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3741.java +++ b/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3741.java @@ -37,16 +37,8 @@ public class TestPDFBox3741 @Test public void testPDFBox3741() throws IOException { - PreflightParser parser = new PreflightParser( - new File("src/test/resources/PDFBOX-3741.pdf")); - parser.parse(); - ValidationResult result; - try (PreflightDocument document = parser.getPreflightDocument()) - { - document.validate(); - result = document.getResult(); - } - + ValidationResult result = PreflightParser + .validate(new File("src/test/resources/PDFBOX-3741.pdf")); // Error should be: // 2.4.3: Invalid Color space, /DeviceGray default for operator "Tj" can't be used without Color Profile Assert.assertFalse("File PDFBOX-3741.pdf should be detected as not PDF/A-1b", result.isValid()); diff --git a/preflight/src/test/java/org/apache/pdfbox/preflight/TestValidDirectory.java b/preflight/src/test/java/org/apache/pdfbox/preflight/TestValidDirectory.java index 4b158310a6e..a15f8599778 100644 --- a/preflight/src/test/java/org/apache/pdfbox/preflight/TestValidDirectory.java +++ b/preflight/src/test/java/org/apache/pdfbox/preflight/TestValidDirectory.java @@ -26,7 +26,6 @@ import java.util.Collection; import java.util.List; -import org.apache.pdfbox.preflight.exception.SyntaxValidationException; import org.apache.pdfbox.preflight.parser.PreflightParser; import org.junit.Assert; import org.junit.Test; @@ -48,28 +47,8 @@ public TestValidDirectory(File file) @Test public void validate() throws Exception { - PreflightDocument document = null; System.out.println(target); - ValidationResult result = null; - try - { - PreflightParser parser = new PreflightParser(target); - parser.parse(); - document = (PreflightDocument) parser.getPDDocument(); - document.validate(); - result = document.getResult(); - } - catch (SyntaxValidationException e) - { - result = e.getResult(); - } - finally - { - if (document != null) - { - document.close(); - } - } + ValidationResult result = PreflightParser.validate(target); Assert.assertTrue("Validation of " + target, result.isValid()); } diff --git a/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/AbstractTestAction.java b/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/AbstractTestAction.java index f3ff652a9db..ec0ce883706 100644 --- a/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/AbstractTestAction.java +++ b/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/AbstractTestAction.java @@ -25,6 +25,7 @@ import java.util.List; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.interactive.action.PDAction; import org.apache.pdfbox.preflight.Format; @@ -48,7 +49,7 @@ public abstract class AbstractTestAction */ protected PreflightContext createContext() throws Exception { - PDDocument doc = PDDocument + PDDocument doc = PDFParser .load(new File("src/test/resources/pdfa-with-annotations-square.pdf")); PreflightDocument preflightDocument = new PreflightDocument(doc.getDocument(), Format.PDF_A1B); PreflightContext ctx = new PreflightContext(); @@ -107,12 +108,12 @@ protected void valid(COSDictionary action, boolean valid, String expectedCode) t abstractActionManager.valid(); } + List errors = ctx.getDocument().getValidationErrors(); // check the result if (!valid) { - List errors = ctx.getDocument().getResult().getErrorsList(); assertFalse(errors.isEmpty()); - if (expectedCode != null || !"".equals(expectedCode)) + if (expectedCode != null && !expectedCode.isEmpty()) { boolean found = false; for (ValidationError err : errors) @@ -128,11 +129,7 @@ protected void valid(COSDictionary action, boolean valid, String expectedCode) t } else { - if (ctx.getDocument().getResult() != null) - { - List errors = ctx.getDocument().getResult().getErrorsList(); - assertTrue(errors.isEmpty()); - } + assertTrue(errors.isEmpty()); } ctx.getDocument().close(); } diff --git a/preflight/src/test/java/org/apache/pdfbox/preflight/integration/AbstractInvalidFileTester.java b/preflight/src/test/java/org/apache/pdfbox/preflight/integration/AbstractInvalidFileTester.java index cabf06a9081..1c5ff54cb86 100644 --- a/preflight/src/test/java/org/apache/pdfbox/preflight/integration/AbstractInvalidFileTester.java +++ b/preflight/src/test/java/org/apache/pdfbox/preflight/integration/AbstractInvalidFileTester.java @@ -28,10 +28,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.io.IOUtils; -import org.apache.pdfbox.preflight.PreflightDocument; import org.apache.pdfbox.preflight.ValidationResult; import org.apache.pdfbox.preflight.ValidationResult.ValidationError; -import org.apache.pdfbox.preflight.exception.ValidationException; import org.apache.pdfbox.preflight.parser.PreflightParser; import org.junit.After; import org.junit.Assert; @@ -86,74 +84,57 @@ public final void validate() throws Exception logger.warn("This is an empty test"); return; } - PreflightDocument document = null; - try + ValidationResult result = PreflightParser.validate(path); + Assert.assertFalse(path + " : Isartor file should be invalid (" + path + ")", + result.isValid()); + Assert.assertTrue(path + " : Should find at least one error", + result.getErrorsList().size() > 0); + // could contain more than one error + boolean found = false; + if (this.expectedError != null) { - PreflightParser parser = new PreflightParser(path); - parser.parse(); - document = parser.getPreflightDocument(); - document.validate(); - - ValidationResult result = document.getResult(); - Assert.assertFalse(path + " : Isartor file should be invalid (" + path + ")", result.isValid()); - Assert.assertTrue(path + " : Should find at least one error", result.getErrorsList().size() > 0); - // could contain more than one error - boolean found = false; - if (this.expectedError != null) + for (ValidationError error : result.getErrorsList()) { - for (ValidationError error : result.getErrorsList()) + if (error.getErrorCode().equals(this.expectedError)) { - if (error.getErrorCode().equals(this.expectedError)) - { - found = true; - if (outputResult == null) - { - break; - } - } - if (outputResult != null) + found = true; + if (outputResult == null) { - String log = path.getName().replace(".pdf", "") + "#" + error.getErrorCode() + "#" - + error.getDetails() + "\n"; - outputResult.write(log.getBytes()); + break; } } + if (outputResult != null) + { + String log = path.getName().replace(".pdf", "") + "#" + error.getErrorCode() + + "#" + error.getDetails() + "\n"; + outputResult.write(log.getBytes()); + } } + } - if (result.getErrorsList().size() > 0) + if (result.getErrorsList().size() > 0) + { + if (this.expectedError == null) { - if (this.expectedError == null) - { - logger.info("File invalid as expected (no expected code) :" + this.path.getAbsolutePath()); - } - else if (!found) - { - StringBuilder message = new StringBuilder(100); - message.append(path).append(" : Invalid error code returned. Expected "); - message.append(this.expectedError).append(", found "); - for (ValidationError error : result.getErrorsList()) - { - message.append(error.getErrorCode()).append(" "); - } - Assert.fail(message.toString()); - } + logger.info("File invalid as expected (no expected code) :" + + this.path.getAbsolutePath()); } - else + else if (!found) { - Assert.assertEquals(path + " : Invalid error code returned.", this.expectedError, result - .getErrorsList().get(0).getErrorCode()); + StringBuilder message = new StringBuilder(100); + message.append(path).append(" : Invalid error code returned. Expected "); + message.append(this.expectedError).append(", found "); + for (ValidationError error : result.getErrorsList()) + { + message.append(error.getErrorCode()).append(" "); + } + Assert.fail(message.toString()); } } - catch (ValidationException e) - { - throw new Exception(path + " :" + e.getMessage(), e); - } - finally + else { - if (document != null) - { - document.close(); - } + Assert.assertEquals(path + " : Invalid error code returned.", this.expectedError, + result.getErrorsList().get(0).getErrorCode()); } } diff --git a/preflight/src/test/java/org/apache/pdfbox/preflight/integration/TestValidFiles.java b/preflight/src/test/java/org/apache/pdfbox/preflight/integration/TestValidFiles.java index 71d2cbea0f1..74315b6cd41 100644 --- a/preflight/src/test/java/org/apache/pdfbox/preflight/integration/TestValidFiles.java +++ b/preflight/src/test/java/org/apache/pdfbox/preflight/integration/TestValidFiles.java @@ -32,9 +32,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.io.IOUtils; -import org.apache.pdfbox.preflight.PreflightDocument; import org.apache.pdfbox.preflight.ValidationResult; -import org.apache.pdfbox.preflight.exception.ValidationException; import org.apache.pdfbox.preflight.parser.PreflightParser; import org.junit.AfterClass; import org.junit.Assert; @@ -129,33 +127,16 @@ public void validate() throws Exception logger.warn("This is an empty test"); return; } - PreflightDocument document = null; - try + ValidationResult result = PreflightParser.validate(path); + + Assert.assertFalse(path + " : Isartor file should be invalid (" + path + ")", + result.isValid()); + Assert.assertTrue(path + " : Should find at least one error", + result.getErrorsList().size() > 0); + // could contain more than one error + if (result.getErrorsList().size() > 0) { - PreflightParser parser = new PreflightParser(path); - parser.parse(); - document = parser.getPreflightDocument(); - document.validate(); - - ValidationResult result = document.getResult(); - Assert.assertFalse(path + " : Isartor file should be invalid (" + path + ")", result.isValid()); - Assert.assertTrue(path + " : Should find at least one error", result.getErrorsList().size() > 0); - // could contain more than one error - if (result.getErrorsList().size() > 0) - { - Assert.fail("File expected valid : " + path.getAbsolutePath()); - } - } - catch (ValidationException e) - { - throw new Exception(path + " :" + e.getMessage(), e); - } - finally - { - if (document != null) - { - document.close(); - } + Assert.fail("File expected valid : " + path.getAbsolutePath()); } } diff --git a/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestMetadataFiles.java b/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestMetadataFiles.java index 28cac5dc494..cec7b69c72d 100644 --- a/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestMetadataFiles.java +++ b/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestMetadataFiles.java @@ -28,9 +28,7 @@ import java.io.File; import java.io.IOException; -import org.apache.pdfbox.preflight.PreflightDocument; import org.apache.pdfbox.preflight.ValidationResult; -import org.apache.pdfbox.preflight.exception.SyntaxValidationException; import org.apache.pdfbox.preflight.parser.PreflightParser; import org.junit.Test; @@ -67,22 +65,13 @@ public void validate() throws Exception private boolean checkPDF(File pdf) { - PreflightDocument document = null; boolean testResult = false; if (pdf.exists()) { ValidationResult result = null; try { - PreflightParser parser = new PreflightParser(pdf); - parser.parse(); - document = (PreflightDocument) parser.getPDDocument(); - document.validate(); - result = document.getResult(); - } - catch (SyntaxValidationException e) - { - result = e.getResult(); + result = PreflightParser.validate(pdf); } catch (IOException e) { @@ -92,17 +81,6 @@ private boolean checkPDF(File pdf) { testResult = result.isValid(); } - if (document != null) - { - try - { - document.close(); - } - catch (IOException e) - { - // shouldn't happen; - } - } } else { diff --git a/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java b/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java index d765089b331..ccefebd6aea 100644 --- a/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java +++ b/preflight/src/test/java/org/apache/pdfbox/preflight/metadata/TestSynchronizedMetadataValidation.java @@ -27,7 +27,6 @@ import java.util.List; import org.junit.Assert; - import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocumentInformation; import org.apache.pdfbox.preflight.PreflightConstants; diff --git a/tools/src/main/java/org/apache/pdfbox/tools/DecompressObjectstreams.java b/tools/src/main/java/org/apache/pdfbox/tools/DecompressObjectstreams.java index 0b10d76c4ff..ad8d068f56f 100644 --- a/tools/src/main/java/org/apache/pdfbox/tools/DecompressObjectstreams.java +++ b/tools/src/main/java/org/apache/pdfbox/tools/DecompressObjectstreams.java @@ -18,21 +18,15 @@ import java.io.File; import java.io.IOException; -import org.apache.pdfbox.cos.COSName; -import org.apache.pdfbox.cos.COSObject; -import org.apache.pdfbox.cos.COSStream; -import org.apache.pdfbox.pdfparser.PDFObjectStreamParser; import org.apache.pdfbox.pdmodel.PDDocument; -import org.apache.pdfbox.cos.COSObjectKey; -import org.apache.pdfbox.io.IOUtils; +import org.apache.pdfbox.pdfparser.PDFParser; /** - * This program will just take all of the stream objects in a PDF and dereference - * them. The streams will be gone in the resulting file and the objects will be - * present. This is very helpful when trying to debug problems as it'll make - * it possible to easily look through a PDF using a text editor. It also exposes - * problems which stem from objects inside object streams overwriting other - * objects. + * This program will just save the loaded pdf without any changes. As PDFBox doesn't support writing compressed object + * streams those streams are stripped and will be gone in the resulting file. This is very helpful when trying to debug + * problems as it'll make it possible to easily look through a PDF using a text editor. It also exposes problems which + * stem from objects inside object streams overwriting other objects. + * * @author Adam Nichols */ public final class DecompressObjectstreams @@ -77,32 +71,17 @@ public static void main(String[] args) } } - PDDocument doc = null; - try + try (PDDocument doc = PDFParser.load(new File(inputFilename))) { - doc = PDDocument.load(new File(inputFilename)); - for(COSObject objStream : doc.getDocument().getObjectsByType(COSName.OBJ_STM)) - { - COSStream stream = (COSStream)objStream.getObject(); - PDFObjectStreamParser sp = new PDFObjectStreamParser(stream, doc.getDocument()); - for (COSObject next : sp.parse()) - { - COSObjectKey key = new COSObjectKey(next); - COSObject obj = doc.getDocument().getObjectFromPool(key); - obj.setObject(next.getObject()); - } - doc.getDocument().removeObject(new COSObjectKey(objStream)); - } + // It is sufficient to simply write the loaded pdf without further processing. + // As PDFBox doesn't support writing compressed object streams that streams will + // be simply omitted doc.save(outputFilename); } catch (IOException e) { System.err.println("Error processing file: " + e.getMessage()); } - finally - { - IOUtils.closeQuietly(doc); - } } /** diff --git a/tools/src/main/java/org/apache/pdfbox/tools/Decrypt.java b/tools/src/main/java/org/apache/pdfbox/tools/Decrypt.java index 6381c154482..ec4a41f8a6d 100644 --- a/tools/src/main/java/org/apache/pdfbox/tools/Decrypt.java +++ b/tools/src/main/java/org/apache/pdfbox/tools/Decrypt.java @@ -31,6 +31,7 @@ import org.apache.commons.cli.ParseException; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.encryption.AccessPermission; /** @@ -151,7 +152,7 @@ private void decrypt() throws IOException { keyStoreStream = new FileInputStream(keyStore); } - document = PDDocument.load(new File(infile), password, keyStoreStream, alias); + document = PDFParser.load(new File(infile), password, keyStoreStream, alias); if (document.isEncrypted()) { diff --git a/tools/src/main/java/org/apache/pdfbox/tools/Encrypt.java b/tools/src/main/java/org/apache/pdfbox/tools/Encrypt.java index a24c917923b..771c1cdaace 100644 --- a/tools/src/main/java/org/apache/pdfbox/tools/Encrypt.java +++ b/tools/src/main/java/org/apache/pdfbox/tools/Encrypt.java @@ -25,6 +25,7 @@ import java.security.cert.X509Certificate; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.encryption.AccessPermission; import org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy; import org.apache.pdfbox.pdmodel.encryption.PublicKeyRecipient; @@ -163,7 +164,7 @@ else if( outfile == null ) { outfile = infile; } - document = PDDocument.load( new File(infile) ); + document = PDFParser.load(new File(infile)); if( !document.isEncrypted() ) { diff --git a/tools/src/main/java/org/apache/pdfbox/tools/ExportFDF.java b/tools/src/main/java/org/apache/pdfbox/tools/ExportFDF.java index 2c269bd1c6c..4f28337d893 100644 --- a/tools/src/main/java/org/apache/pdfbox/tools/ExportFDF.java +++ b/tools/src/main/java/org/apache/pdfbox/tools/ExportFDF.java @@ -20,6 +20,7 @@ import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; import org.apache.pdfbox.pdmodel.fdf.FDFDocument; @@ -64,7 +65,7 @@ private void exportFDF( String[] args ) throws IOException } else { - try (PDDocument pdf = PDDocument.load( new File(args[0]) )) + try (PDDocument pdf = PDFParser.load(new File(args[0]))) { PDAcroForm form = pdf.getDocumentCatalog().getAcroForm(); if( form == null ) diff --git a/tools/src/main/java/org/apache/pdfbox/tools/ExportXFDF.java b/tools/src/main/java/org/apache/pdfbox/tools/ExportXFDF.java index 3d1569d6b66..4541c532ba2 100644 --- a/tools/src/main/java/org/apache/pdfbox/tools/ExportXFDF.java +++ b/tools/src/main/java/org/apache/pdfbox/tools/ExportXFDF.java @@ -20,6 +20,7 @@ import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; import org.apache.pdfbox.pdmodel.fdf.FDFDocument; @@ -46,7 +47,6 @@ public ExportXFDF() * @param args command line arguments * @throws IOException in case the file can not be read or the data can not be exported. * - * @throws IOException If there is an error importing the FDF document. */ public static void main(String[] args) throws IOException { @@ -65,7 +65,7 @@ private void exportXFDF( String[] args ) throws IOException } else { - try (PDDocument pdf = PDDocument.load( new File(args[0]) )) + try (PDDocument pdf = PDFParser.load(new File(args[0]))) { PDAcroForm form = pdf.getDocumentCatalog().getAcroForm(); if( form == null ) diff --git a/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java b/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java index 264bf26b930..6acc74fde3c 100644 --- a/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java +++ b/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java @@ -31,6 +31,7 @@ import org.apache.pdfbox.cos.COSStream; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.encryption.AccessPermission; @@ -67,7 +68,7 @@ public final class ExtractImages COSName.DCT_DECODE_ABBREVIATION.getName()); private boolean useDirectJPEG; - private String prefix; + private String filePrefix; private final Set seen = new HashSet<>(); private int imageCounter = 1; @@ -120,7 +121,7 @@ private void run(String[] args) throws IOException { usage(); } - prefix = args[i]; + filePrefix = args[i]; break; case DIRECTJPEG: useDirectJPEG = true; @@ -139,9 +140,9 @@ private void run(String[] args) throws IOException } else { - if (prefix == null && pdfFile.length() >4) + if (filePrefix == null && pdfFile.length() > 4) { - prefix = pdfFile.substring(0, pdfFile.length() -4); + filePrefix = pdfFile.substring(0, pdfFile.length() - 4); } extract(pdfFile, password); @@ -168,7 +169,7 @@ private static void usage() private void extract(String pdfFile, String password) throws IOException { - try (PDDocument document = PDDocument.load(new File(pdfFile), password)) + try (PDDocument document = PDFParser.load(new File(pdfFile), password)) { AccessPermission ap = document.getCurrentAccessPermission(); if (!ap.canExtractContent()) @@ -232,7 +233,7 @@ public void drawImage(PDImage pdImage) throws IOException } // save image - String name = prefix + "-" + imageCounter; + String name = filePrefix + "-" + imageCounter; imageCounter++; System.out.println("Writing image: " + name); diff --git a/tools/src/main/java/org/apache/pdfbox/tools/ExtractText.java b/tools/src/main/java/org/apache/pdfbox/tools/ExtractText.java index 9934df42d3b..c18540b49b5 100644 --- a/tools/src/main/java/org/apache/pdfbox/tools/ExtractText.java +++ b/tools/src/main/java/org/apache/pdfbox/tools/ExtractText.java @@ -31,6 +31,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary; import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode; @@ -215,7 +216,7 @@ else if( args[i].equals( CONSOLE ) ) { outputFile = new File( pdfFile.substring( 0, pdfFile.length() -4 ) + ext ).getAbsolutePath(); } - document = PDDocument.load(new File( pdfFile ), password); + document = PDFParser.load(new File(pdfFile), password); AccessPermission ap = document.getCurrentAccessPermission(); if( ! ap.canExtractContent() ) @@ -301,7 +302,7 @@ else if( args[i].equals( CONSOLE ) ) System.err.println(" is PDF (size=" + file.getSize() + ")"); } try (InputStream fis = file.createInputStream(); - PDDocument subDoc = PDDocument.load(fis)) + PDDocument subDoc = PDFParser.load(fis)) { if (toHTML) { diff --git a/tools/src/main/java/org/apache/pdfbox/tools/ImageToPDF.java b/tools/src/main/java/org/apache/pdfbox/tools/ImageToPDF.java index 17501de8e7e..7a058fff97c 100644 --- a/tools/src/main/java/org/apache/pdfbox/tools/ImageToPDF.java +++ b/tools/src/main/java/org/apache/pdfbox/tools/ImageToPDF.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; + import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; diff --git a/tools/src/main/java/org/apache/pdfbox/tools/ImportFDF.java b/tools/src/main/java/org/apache/pdfbox/tools/ImportFDF.java index e4e7a4e22ef..4372f28cd8e 100644 --- a/tools/src/main/java/org/apache/pdfbox/tools/ImportFDF.java +++ b/tools/src/main/java/org/apache/pdfbox/tools/ImportFDF.java @@ -19,7 +19,9 @@ import java.io.File; import java.io.IOException; +import org.apache.pdfbox.pdfparser.FDFParser; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.fdf.FDFDocument; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; @@ -91,8 +93,8 @@ private void importFDF( String[] args ) throws IOException { ImportFDF importer = new ImportFDF(); - try (PDDocument pdf = PDDocument.load( new File(args[0]) ); - FDFDocument fdf = FDFDocument.load( args[1] )) + try (PDDocument pdf = PDFParser.load(new File(args[0])); + FDFDocument fdf = FDFParser.load(args[1])) { importer.importFDF( pdf, fdf ); diff --git a/tools/src/main/java/org/apache/pdfbox/tools/ImportXFDF.java b/tools/src/main/java/org/apache/pdfbox/tools/ImportXFDF.java index 95d74225450..2b8bd407842 100644 --- a/tools/src/main/java/org/apache/pdfbox/tools/ImportXFDF.java +++ b/tools/src/main/java/org/apache/pdfbox/tools/ImportXFDF.java @@ -16,7 +16,9 @@ */ package org.apache.pdfbox.tools; +import org.apache.pdfbox.pdfparser.FDFParser; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.fdf.FDFDocument; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; @@ -84,8 +86,8 @@ private void importXFDF( String[] args ) throws IOException else { ImportFDF importer = new ImportFDF(); - try (PDDocument pdf = PDDocument.load( new File(args[0]) ); - FDFDocument fdf = FDFDocument.loadXFDF( args[1] )) + try (PDDocument pdf = PDFParser.load(new File(args[0])); + FDFDocument fdf = FDFParser.loadXFDF(args[1])) { importer.importFDF( pdf, fdf ); pdf.save( args[2] ); diff --git a/tools/src/main/java/org/apache/pdfbox/tools/PDFSplit.java b/tools/src/main/java/org/apache/pdfbox/tools/PDFSplit.java index 4e5009ec21a..328adba75a9 100644 --- a/tools/src/main/java/org/apache/pdfbox/tools/PDFSplit.java +++ b/tools/src/main/java/org/apache/pdfbox/tools/PDFSplit.java @@ -21,8 +21,9 @@ import java.util.List; -import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.multipdf.Splitter; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; /** * This is the main program that will take a pdf document and split it into @@ -131,7 +132,7 @@ private void split( String[] args ) throws IOException List documents = null; try { - document = PDDocument.load(new File(pdfFile), password); + document = PDFParser.load(new File(pdfFile), password); int numberOfPages = document.getNumberOfPages(); boolean startEndPageSet = false; @@ -207,4 +208,4 @@ private static void usage() System.err.println(message); System.exit( 1 ); } -} \ No newline at end of file +} diff --git a/tools/src/main/java/org/apache/pdfbox/tools/PDFToImage.java b/tools/src/main/java/org/apache/pdfbox/tools/PDFToImage.java index 922e8b3bda5..4a0a78c7a26 100644 --- a/tools/src/main/java/org/apache/pdfbox/tools/PDFToImage.java +++ b/tools/src/main/java/org/apache/pdfbox/tools/PDFToImage.java @@ -25,6 +25,7 @@ import javax.imageio.ImageIO; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; @@ -199,7 +200,7 @@ public static void main( String[] args ) throws IOException quality = "png".equals(imageFormat) ? 0f : 1f; } - try (PDDocument document = PDDocument.load(new File(pdfFile), password)) + try (PDDocument document = PDFParser.load(new File(pdfFile), password)) { PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm(); if (acroForm != null && acroForm.getNeedAppearances()) diff --git a/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java b/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java index 81792baf810..8c977260368 100644 --- a/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java +++ b/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java @@ -26,6 +26,7 @@ import javax.print.PrintService; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.encryption.AccessPermission; import org.apache.pdfbox.printing.Orientation; import org.apache.pdfbox.printing.PDFPageable; @@ -146,7 +147,7 @@ public static void main(String[] args) throws PrinterException, IOException usage(); } - try (PDDocument document = PDDocument.load(new File(pdfFile), password)) + try (PDDocument document = PDFParser.load(new File(pdfFile), password)) { AccessPermission ap = document.getCurrentAccessPermission(); if (!ap.canPrint()) diff --git a/tools/src/main/java/org/apache/pdfbox/tools/WriteDecodedDoc.java b/tools/src/main/java/org/apache/pdfbox/tools/WriteDecodedDoc.java index 2712c2525c7..1c80d628d13 100644 --- a/tools/src/main/java/org/apache/pdfbox/tools/WriteDecodedDoc.java +++ b/tools/src/main/java/org/apache/pdfbox/tools/WriteDecodedDoc.java @@ -20,10 +20,12 @@ import java.io.IOException; import java.io.OutputStream; import org.apache.pdfbox.cos.COSBase; +import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSObject; import org.apache.pdfbox.cos.COSStream; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.common.PDStream; /** @@ -59,47 +61,46 @@ public WriteDecodedDoc() public void doIt(String in, String out, String password, boolean skipImages) throws IOException { - try (PDDocument doc = PDDocument.load(new File(in), password)) + try (PDDocument doc = PDFParser.load(new File(in), password)) { doc.setAllSecurityToBeRemoved(true); - for (COSObject cosObject : doc.getDocument().getObjects()) - { - COSBase base = cosObject.getObject(); - if (base instanceof COSStream) - { - COSStream stream = (COSStream) base; - if (skipImages && - COSName.XOBJECT.equals(stream.getItem(COSName.TYPE)) && - COSName.IMAGE.equals(stream.getItem(COSName.SUBTYPE))) - { - continue; - } - byte[] bytes; - try - { - bytes = new PDStream(stream).toByteArray(); - } - catch (IOException ex) - { - System.err.println("skip " + - cosObject.getObjectNumber() + " " + - cosObject.getGenerationNumber() + " obj: " + - ex.getMessage()); - continue; - } - stream.removeItem(COSName.FILTER); - try (OutputStream streamOut = stream.createOutputStream()) - { - streamOut.write(bytes); - } - } - } + COSDocument cosDocument = doc.getDocument(); + cosDocument.getXrefTable().keySet().stream() + .forEach(o -> processObject(cosDocument.getObjectFromPool(o), skipImages)); doc.getDocumentCatalog(); doc.getDocument().setIsXRefStream(false); doc.save( out ); } } + private void processObject(COSObject cosObject, boolean skipImages) + { + COSBase base = cosObject.getObject(); + if (base instanceof COSStream) + { + COSStream stream = (COSStream) base; + if (skipImages && COSName.XOBJECT.equals(stream.getItem(COSName.TYPE)) + && COSName.IMAGE.equals(stream.getItem(COSName.SUBTYPE))) + { + return; + } + try + { + byte[] bytes = new PDStream(stream).toByteArray(); + stream.removeItem(COSName.FILTER); + try (OutputStream streamOut = stream.createOutputStream()) + { + streamOut.write(bytes); + } + } + catch (IOException ex) + { + System.err.println("skip " + cosObject.getObjectNumber() + " " + + cosObject.getGenerationNumber() + " obj: " + ex.getMessage()); + } + } + + } /** * This will write a PDF document with completely decoded streams. *
diff --git a/tools/src/test/java/org/apache/pdfbox/tools/TestTextToPdf.java b/tools/src/test/java/org/apache/pdfbox/tools/TestTextToPdf.java index 6fc0464193b..68e9b297788 100644 --- a/tools/src/test/java/org/apache/pdfbox/tools/TestTextToPdf.java +++ b/tools/src/test/java/org/apache/pdfbox/tools/TestTextToPdf.java @@ -19,12 +19,12 @@ import java.io.IOException; import java.io.StringReader; +import org.apache.pdfbox.pdmodel.PDDocument; + import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; -import org.apache.pdfbox.pdmodel.PDDocument; - /** * Test suite for TextToPDF. */ diff --git a/tools/src/test/java/org/apache/pdfbox/tools/imageio/TestImageIOUtils.java b/tools/src/test/java/org/apache/pdfbox/tools/imageio/TestImageIOUtils.java index 1b5cbf87ef0..d9be2813193 100644 --- a/tools/src/test/java/org/apache/pdfbox/tools/imageio/TestImageIOUtils.java +++ b/tools/src/test/java/org/apache/pdfbox/tools/imageio/TestImageIOUtils.java @@ -42,6 +42,7 @@ import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.graphics.PDXObject; import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject; @@ -117,7 +118,7 @@ private void doTestFile(File file, String outDir) throws IOException try { float dpi = 36; // low DPI so that rendering is FAST - document = PDDocument.load(file); + document = PDFParser.load(file); // Save image resources of first page checkSaveResources(document.getPage(0).getResources());