Skip to content

Commit

Permalink
replacing PDDocument.load by Loader.loadPDF
Browse files Browse the repository at this point in the history
  • Loading branch information
jstaerk committed Apr 29, 2024
1 parent d6eb58c commit 45ebb72
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
package org.mustangproject.ZUGFeRD;

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.cos.*;
import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.io.RandomAccessReadBuffer;
Expand Down Expand Up @@ -163,7 +164,7 @@ public DXExporterFromA3 addAdditionalFile(String name, byte[] content) {
*/
public DXExporterFromA3 load(byte[] pdfBinary) throws IOException {
ensurePDFIsValid((DataSource) new RandomAccessReadBuffer(pdfBinary));
doc = PDDocument.load(pdfBinary);
doc = Loader.loadPDF(pdfBinary);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
package org.mustangproject.ZUGFeRD;

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.cos.*;
import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.io.RandomAccessReadBuffer;
Expand Down Expand Up @@ -163,7 +164,7 @@ public OXExporterFromA3 addAdditionalFile(String name, byte[] content) {
*/
public OXExporterFromA3 load(byte[] pdfBinary) throws IOException {
ensurePDFIsValid((DataSource) new RandomAccessReadBuffer(pdfBinary));
doc = PDDocument.load(pdfBinary);
doc = Loader.loadPDF(pdfBinary);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
package org.mustangproject.ZUGFeRD;

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.cos.*;
import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.io.RandomAccessReadBuffer;
Expand Down Expand Up @@ -258,7 +259,8 @@ public IZUGFeRDExporter disableFacturX() {
*/
public ZUGFeRDExporterFromA3 load(byte[] pdfBinary) throws IOException {
ensurePDFIsValid((DataSource) new RandomAccessReadBuffer(pdfBinary));
doc = PDDocument.load(pdfBinary);

doc = Loader.loadPDF(pdfBinary);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
package org.mustangproject.ZUGFeRD;

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.common.PDMetadata;
Expand Down Expand Up @@ -79,7 +80,7 @@ protected byte[] inputstreamToByteArray(InputStream fileInputStream) throws IOEx
* @throws IOException
*/
private int getPDFAVersion(byte[] byteArrayInputStream) throws IOException {
PDDocument document = PDDocument.load(byteArrayInputStream);
PDDocument document = Loader.loadPDF(byteArrayInputStream);
PDDocumentCatalog catalog = document.getDocumentCatalog();
PDMetadata metadata = catalog.getMetadata();
// the PDF version we could get through the document but we want the PDF-A version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.apache.commons.io.IOUtils;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode;
Expand Down Expand Up @@ -120,7 +122,7 @@ private void extractLowLevel(InputStream inStream) throws IOException {
if (pad.equals(pdfSignature)) { // we have a pdf


try (PDDocument doc = PDDocument.load(pdfStream)) {
try (PDDocument doc = Loader.loadPDF(IOUtils.toByteArray(inStream))) {
// PDDocumentInformation info = doc.getDocumentInformation();
final PDDocumentNameDictionary names = new PDDocumentNameDictionary(doc.getDocumentCatalog());
//start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import junit.framework.Test;
import junit.framework.TestSuite;

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.common.PDMetadata;
import org.apache.xmpbox.XMPMetadata;
Expand Down Expand Up @@ -252,7 +253,7 @@ public void testEdgeExportIsPDFA3() throws Exception {
setupPdfUnderTest(SOURCE_PDF, TARGET_PDF);

// now check the contents
PDDocument doc = PDDocument.load(new File(TARGET_PDF));
PDDocument doc = Loader.loadPDF(new File(TARGET_PDF));
PDMetadata meta = doc.getDocumentCatalog().getMetadata();
assertNotNull("The pdf must contain XMPMetadata", meta);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import junit.framework.Test;
import junit.framework.TestSuite;

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.common.PDMetadata;
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
Expand Down Expand Up @@ -328,7 +329,7 @@ public void testMigratePDFA1ToA3Stream() throws IOException {
}

private void checkPdfA3B(File tempFile) throws IOException, InvalidPasswordException {
try (PDDocument doc = PDDocument.load(tempFile)) {
try (PDDocument doc = Loader.loadPDF(tempFile)) {
PDMetadata metadata = doc.getDocumentCatalog().getMetadata();
InputStream exportXMPMetadata = metadata.exportXMPMetadata();
byte[] xmpBytes = new byte[exportXMPMetadata.available()];
Expand Down

0 comments on commit 45ebb72

Please sign in to comment.