Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0.11
-
None
Description
When applying protection to a PDF the resulting PDF shows weird background colors.
The following minimal sample program produces the observed behaviour in attached PDF "Zieldatei-mit-Schutz.pdf"
package protecttest; // $ java -version // openjdk version "1.8.0_181" // OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-0ubuntu0.18.04.1-b13) // OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode) // compile with // javac -cp pdfbox-2.0.11.jar protecttest/PdfProtector.java // execute with // java -cp pdfbox-2.0.11.jar:commons-logging-1.1.3.jar:. protecttest.PdfProtector import java.io.File; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.encryption.AccessPermission; import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy; public class PdfProtector { public static void main(String[] args) throws Exception { // load and save with no protection PDDocument d1 = PDDocument.load(new File("Quelldatei.pdf")); d1.save(new File("Zieldatei-ohne-Schutz.pdf")); d1.close(); // everything seems fine with the resulting PDF // load and save with protection PDDocument d2 = PDDocument.load(new File("Quelldatei.pdf")); AccessPermission ap = new AccessPermission(); ap.setCanAssembleDocument(false); ap.setCanModify(false); d2.protect(new StandardProtectionPolicy("foobar","",ap)); d2.save(new File("Zieldatei-mit-Schutz.pdf")); d2.close(); // resulting file is rendered with odd colors } }