Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to support PDFBox 3.0.3 #316

Merged
merged 7 commits into from
Dec 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
code updated for support PDFBox3, #311
Intelligent2013 committed Dec 24, 2024
commit dfc285bda3ee8d74e7cf31d326be9c16cf8ccc2c
16 changes: 12 additions & 4 deletions src/main/java/org/metanorma/fop/annotations/Annotation.java
Original file line number Diff line number Diff line change
@@ -376,9 +376,17 @@ private void fixAnnotationTags(COSArray oArray, COSObject parentObject, int leve

if (oArray != null) {
for(int i = 0; i < oArray.size(); i++) {
COSObject oArrayItem = (COSObject) oArray.get(i);
COSBase oBaseItem = oArrayItem.getObject();
COSDictionary dArrayItem = (COSDictionary) oBaseItem;
COSObject oArrayItem = null;
COSDictionary dArrayItem;
if (oArray.get(i) instanceof COSDictionary) {
//oArrayItem = (COSObject) oArray.get(i).getCOSObject();
dArrayItem = (COSDictionary) oArray.get(i);
} else {
oArrayItem = (COSObject) oArray.get(i);
COSBase oBaseItem = oArrayItem.getObject();
dArrayItem = (COSDictionary) oBaseItem;
}

COSName cName = (COSName) dArrayItem.getItem(COSName.S);

if (cName != null) {
@@ -466,7 +474,7 @@ private void fixAnnotationTags(COSArray oArray, COSObject parentObject, int leve
COSArray oA_K = (COSArray) dArrayItem.getItem(COSName.K);
fixAnnotationTags(oA_K, oArrayItem, ++level);
} catch (Exception e) {
//
//System.out.println(e.toString());
}
}
}
Original file line number Diff line number Diff line change
@@ -86,11 +86,12 @@ public void process(File pdf) throws IOException {
}


/*finally {
if( document != null ) {
finally {
/*if( document != null ) {
document.close();
}
}*/
}*/
Files.deleteIfExists(pdf_tmp);
}

}

11 changes: 5 additions & 6 deletions src/test/java/org/metanorma/fop/mn2pdfTests.java
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.cos.COSName;

import org.apache.pdfbox.io.RandomAccessReadBufferedFile;
import org.apache.pdfbox.pdmodel.*;
import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification;
import org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
@@ -264,7 +263,7 @@ public void checkResultedPDF() throws ParseException {
String PDFkeywords = "";

//PDDocument doc;
try (PDDocument doc = Loader.loadPDF(new RandomAccessReadBufferedFile(pdf.toFile().getAbsoluteFile()))) {
try (PDDocument doc = Loader.loadPDF(pdf.toFile())) {
//doc = PDDocument.load(pdf.toFile());

PDPageTree pages = doc.getDocumentCatalog().getPages();
@@ -328,12 +327,12 @@ public void checkResultedEncryptedPDF() throws ParseException {
boolean encryptMetadata = false;

//PDDocument doc;
try (PDDocument doc = Loader.loadPDF(new RandomAccessReadBufferedFile(pdf.toFile().getAbsoluteFile()), "userpass")) {
try (PDDocument doc = Loader.loadPDF(pdf.toFile(), "userpass")) {
//doc = PDDocument.load(pdf.toFile(), "userpass");

AccessPermission ap = doc.getCurrentAccessPermission();
allowPrint = ap.canPrint();
allowPrintHQ = ap.canPrintFaithful();// canPrintDegraded() in 2.0.27;
allowPrintHQ = ap.canPrintFaithful();// ap.canPrintDegraded();
allowCopyContent = ap.canExtractContent();
allowEditContent = ap.canModify();
allowEditAnnotations = ap.canModifyAnnotations();
@@ -401,7 +400,7 @@ public void checkSpacesInPDF() throws ParseException {

String pdftext = "";
//PDDocument doc;
try (PDDocument doc = Loader.loadPDF(new RandomAccessReadBufferedFile(pdf.toFile().getAbsoluteFile()))) {
try (PDDocument doc = Loader.loadPDF(pdf.toFile())) {
//doc = PDDocument.load(pdf.toFile());
pdftext = new PDFTextStripper().getText(doc);
} catch (IOException ex) {
@@ -428,7 +427,7 @@ public void checkAttachments() throws ParseException {
//PDDocument doc;
int countFileAttachmentAnnotation = 0;
int countFileAttachmentEmbedded = 0;
try (PDDocument doc = Loader.loadPDF(new RandomAccessReadBufferedFile(pdf.toFile().getAbsoluteFile()))) {
try (PDDocument doc = Loader.loadPDF(pdf.toFile())) {
//doc = PDDocument.load(pdf.toFile());

int numberOfPages = doc.getNumberOfPages();