You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2020/01/12 16:38:11 UTC
svn commit: r1872678 [3/7] - in /pdfbox/trunk:
debugger/src/main/java/org/apache/pdfbox/debugger/
debugger/src/main/java/org/apache/pdfbox/debugger/ui/
examples/src/main/java/org/apache/pdfbox/examples/interactive/form/
examples/src/main/java/org/apach...
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java Sun Jan 12 16:38:09 2020
@@ -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 class PDFParser extends COSParser
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 @@ public class PDFParser extends COSParser
+ " 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 @@ public class PDFParser extends COSParser
{
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 @@ public class PDFParser extends COSParser
}
/**
- * 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 class PDFParser extends COSParser
initialParse();
}
exceptionOccurred = false;
+ PDDocument pdDocument = createDocument();
+ pdDocument.setEncryptionDictionary(getEncryption());
+ return pdDocument;
}
finally
{
@@ -231,4 +549,14 @@ public class PDFParser extends COSParser
}
}
+ /**
+ * 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());
+ }
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java Sun Jan 12 16:38:09 2020
@@ -191,7 +191,7 @@ public class PDFStreamParser extends Bas
String line = readString();
if( line.equals( "R" ) )
{
- retval = new COSObject( null );
+ retval = new COSObject(null);
}
else
{
@@ -295,8 +295,8 @@ public class PDFStreamParser extends Bas
while( !(lastByte == 'E' &&
currentByte == 'I' &&
hasNextSpaceOrReturn() &&
- hasNoFollowingBinData(seqSource)) &&
- !seqSource.isEOF() )
+ hasNoFollowingBinData()) &&
+ !isEOF())
{
imageData.write( lastByte );
lastByte = currentByte;
@@ -344,10 +344,10 @@ public class PDFStreamParser extends Bas
* @return <code>true</code> if next bytes are probably printable ASCII
* characters starting with a PDF operator, otherwise <code>false</code>
*/
- 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 @@ public class PDFStreamParser extends Bas
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;
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFXrefStreamParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFXrefStreamParser.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFXrefStreamParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFXrefStreamParser.java Sun Jan 12 16:38:09 2020
@@ -118,7 +118,7 @@ public class PDFXrefStreamParser extends
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);
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Sun Jan 12 16:38:09 2020
@@ -25,7 +25,6 @@ import java.io.Closeable;
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.HashSet;
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.COSObject;
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 @@ public class PDDocument implements Close
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<COSObject> 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 @@ public class PDDocument implements Close
{
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.
*
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java Sun Jan 12 16:38:09 2020
@@ -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 java.nio.charset.StandardCharsets
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;
@@ -155,96 +150,6 @@ public class FDFDocument implements Clos
}
/**
- * 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.
*
* @param fileName The file to save as.
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java Sun Jan 12 16:38:09 2020
@@ -97,8 +97,7 @@ public class SignatureOptions implements
{
pdfSource = rar;
PDFParser parser = new PDFParser(pdfSource);
- parser.parse();
- visualSignature = parser.getDocument();
+ visualSignature = parser.parse().getDocument();
}
/**
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSignDesigner.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSignDesigner.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSignDesigner.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSignDesigner.java Sun Jan 12 16:38:09 2020
@@ -28,6 +28,7 @@ import java.io.InputStream;
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 class PDVisibleSignDesigner
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 @@ public class PDVisibleSignDesigner
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);
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSName.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSName.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSName.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSName.java Sun Jan 12 16:38:09 2020
@@ -18,7 +18,9 @@ package org.apache.pdfbox.cos;
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 class TestCOSName
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));
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java Sun Jan 12 16:38:09 2020
@@ -29,6 +29,7 @@ import javax.crypto.Cipher;
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<Integer> keyLengths()
{
return Arrays.asList(40, 128, 256);
}
@@ -134,7 +135,7 @@ public class TestPublicKeyEncryption
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 class TestPublicKeyEncryption
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,
@@ -318,4 +319,4 @@ public class TestPublicKeyEncryption
document.save(file);
return file;
}
-}
\ No newline at end of file
+}
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java Sun Jan 12 16:38:09 2020
@@ -36,6 +36,7 @@ import org.apache.pdfbox.cos.COSDictiona
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 class TestSymmetricKeyEncryption
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 class TestSymmetricKeyEncryption
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 @@ public class TestSymmetricKeyEncryption
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 @@ public class TestSymmetricKeyEncryption
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 @@ public class TestSymmetricKeyEncryption
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 @@ public class TestSymmetricKeyEncryption
// 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 @@ public class TestSymmetricKeyEncryption
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");
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/filter/TestFilters.java Sun Jan 12 16:38:09 2020
@@ -28,7 +28,7 @@ import junit.framework.TestCase;
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 class TestFilters extends TestCas
*/
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");
}
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java Sun Jan 12 16:38:09 2020
@@ -31,6 +31,7 @@ import org.apache.pdfbox.cos.COSDictiona
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 class MergeAcroFormsTest
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 class MergeAcroFormsTest
}
// 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 class MergeAcroFormsTest
}
// Test merge result
- try (PDDocument mergedPDF = PDDocument.load(pdfOutput))
+ try (PDDocument mergedPDF = PDFParser.load(pdfOutput))
{
assertEquals("There shall be 2 pages", 2, mergedPDF.getNumberOfPages());
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java Sun Jan 12 16:38:09 2020
@@ -29,6 +29,7 @@ import java.util.Map;
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 class MergeAnnotationsTest
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();
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFCloneUtilityTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFCloneUtilityTest.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFCloneUtilityTest.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFCloneUtilityTest.java Sun Jan 12 16:38:09 2020
@@ -19,7 +19,9 @@ import java.awt.Color;
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 class PDFCloneUtilityTest extends
// 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();
}
}
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java Sun Jan 12 16:38:09 2020
@@ -30,8 +30,6 @@ import java.util.Map;
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.cos.COSObject;
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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<PDStructureElement> srcIDTree = src.getDocumentCatalog().getStructureTreeRoot().getIDTree();
Map<String, PDStructureElement> srcIDTreeMap = PDFMergerUtility.getIDTreeAsMap(srcIDTree);
@@ -521,7 +528,7 @@ public class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
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 class PDFMergerUtilityTest extend
*/
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 @@ public class PDFMergerUtilityTest extend
{
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 @@ public class PDFMergerUtilityTest extend
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 @@ public class PDFMergerUtilityTest extend
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();
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PageExtractorTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PageExtractorTest.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
Binary files - no diff available.
Propchange: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PageExtractorTest.java
------------------------------------------------------------------------------
svn:mime-type = image/png
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/TestLayerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/TestLayerUtility.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/TestLayerUtility.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/TestLayerUtility.java Sun Jan 12 16:38:09 2020
@@ -25,6 +25,7 @@ import junit.framework.TestCase;
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 class TestLayerUtility extends Te
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 class TestLayerUtility extends Te
targetDoc.save(targetFile.getAbsolutePath());
}
- try (PDDocument doc = PDDocument.load(targetFile))
+ try (PDDocument doc = PDFParser.load(targetFile))
{
PDDocumentCatalog catalog = doc.getDocumentCatalog();
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/EndstreamOutputStreamTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/EndstreamOutputStreamTest.java?rev=1872678&r1=1872677&r2=1872678&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/EndstreamOutputStreamTest.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/EndstreamOutputStreamTest.java Sun Jan 12 16:38:09 2020
@@ -116,7 +116,7 @@ public class EndstreamOutputStreamTest
// 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();