pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1859744 - in /pdfbox/branches/2.0: debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java
Date Wed, 22 May 2019 17:11:31 GMT
Author: tilman
Date: Wed May 22 17:11:30 2019
New Revision: 1859744

URL: http://svn.apache.org/viewvc?rev=1859744&view=rev
Log:
PDFBOX-4551: prevent printing when not authorized

Modified:
    pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
    pdfbox/branches/2.0/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java

Modified: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java?rev=1859744&r1=1859743&r2=1859744&view=diff
==============================================================================
--- pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
(original)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
Wed May 22 17:11:30 2019
@@ -110,6 +110,7 @@ import org.apache.pdfbox.filter.FilterFa
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.common.PDPageLabels;
+import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
 import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
 import org.apache.pdfbox.pdmodel.font.PDType1Font;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK;
@@ -1122,6 +1123,12 @@ public class PDFDebugger extends JFrame
         {
             return;
         }
+        AccessPermission ap = document.getCurrentAccessPermission();
+        if (!ap.canPrint())
+        {
+            JOptionPane.showMessageDialog(this, "You do not have permission to print");
+            return;
+        }
 
         try
         {

Modified: pdfbox/branches/2.0/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java?rev=1859744&r1=1859743&r2=1859744&view=diff
==============================================================================
--- pdfbox/branches/2.0/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java (original)
+++ pdfbox/branches/2.0/tools/src/main/java/org/apache/pdfbox/tools/PrintPDF.java Wed May
22 17:11:30 2019
@@ -26,6 +26,7 @@ import java.util.Map;
 import javax.print.PrintService;
 
 import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
 import org.apache.pdfbox.printing.Orientation;
 import org.apache.pdfbox.printing.PDFPageable;
 
@@ -153,6 +154,12 @@ public final class PrintPDF
         {
             document = PDDocument.load(new File(pdfFile), password);
 
+            AccessPermission ap = document.getCurrentAccessPermission();
+            if (!ap.canPrint())
+            {
+                throw new IOException("You do not have permission to print");
+            }
+
             PrinterJob printJob = PrinterJob.getPrinterJob();
             printJob.setJobName(new File(pdfFile).getName());
 



Mime
View raw message