Skip to content
Open
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.apache.pdfbox.multipdf.PDFMergerUtility;
import org.apache.pdfbox.multipdf.Splitter;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
import org.springframework.extensions.surf.util.I18NUtil;

import com.itextpdf.text.Document;
Expand Down Expand Up @@ -125,6 +126,9 @@ public NodeRef appendPDF(NodeRef targetNodeRef, Map<String, Serializable> params
pdf = PDDocument.load(is);
pdfTarget = PDDocument.load(tis);

pdf = decryptPdf(pdfTarget, is);
pdfTarget = decryptPdf(pdfTarget, tis);

// Append the PDFs
PDFMergerUtility merger = new PDFMergerUtility();
merger.appendDocument(pdfTarget, pdf);
Expand Down Expand Up @@ -216,6 +220,17 @@ public NodeRef appendPDF(NodeRef targetNodeRef, Map<String, Serializable> params

return destinationNode;
}

private PDDocument decryptPdf(PDDocument pdf, InputStream tis) throws IOException, InvalidPasswordException {
// if the document is encrypted, try to remove its protection by using the "" (EMPTY) password
// as an attempt before failing during the append operation
if(pdf.isEncrypted()) {
pdf.close();
pdf = PDDocument.load(tis, "");
pdf.setAllSecurityToBeRemoved(true);
}
return pdf;
}

@Override
public NodeRef encryptPDF(NodeRef targetNodeRef, Map<String, Serializable> params)
Expand Down