/** * This will tell if the access permission corresponds to owner * access permission (no restriction). * * @return true if the access permission does not restrict the use of the document */ public boolean isOwnerPermission() { return (this.canAssembleDocument() && this.canExtractContent() && this.canExtractForAccessibility() && this.canFillInForm() && this.canModify() && this.canModifyAnnotations() && this.canPrint() && this.canPrintDegraded() ); }
/** * returns an access permission object for a document owner. * * @return A standard owner access permission set. */ public static AccessPermission getOwnerAccessPermission() { AccessPermission ret = new AccessPermission(); ret.setCanAssembleDocument(true); ret.setCanExtractContent(true); ret.setCanExtractForAccessibility(true); ret.setCanFillInForm(true); ret.setCanModify(true); ret.setCanModifyAnnotations(true); ret.setCanPrint(true); ret.setCanPrintDegraded(true); return ret; }
/** * Indicates if any revision 3 access permission is set or not. * * @return true if any revision 3 access permission is set */ protected boolean hasAnyRevision3PermissionSet() { if (canFillInForm()) { return true; } if (canExtractForAccessibility()) { return true; } if (canAssembleDocument()) { return true; } return canPrintDegraded(); } }
private void extract(String pdfFile, String password) throws IOException { try (PDDocument document = PDDocument.load(new File(pdfFile), password)) { AccessPermission ap = document.getCurrentAccessPermission(); if (!ap.canExtractContent()) { throw new IOException("You do not have permission to extract images"); } for (PDPage page : document.getPages()) { ImageGraphicsEngine extractor = new ImageGraphicsEngine(page); extractor.run(); } } }
PipedOutputStream os = new PipedOutputStream(); PipedInputStream is = new PipedInputStream(os); System.setProperty("org.apache.pdfbox.baseParser.pushBackSize", "2024768"); InputStream dataStream = secureData.data(); PDDocument doc = PDDocument.load(dataStream, true); AccessPermission ap = new AccessPermission(); //add what ever perms you need blah blah... ap.setCanModify(false); ap.setCanExtractContent(false); ap.setCanPrint(false); ap.setCanPrintDegraded(false); ap.setReadOnly(); StandardProtectionPolicy spp = new StandardProtectionPolicy(UUID.randomUUID().toString(), "", ap); doc.protect(spp); doc.save(os); doc.close(); dataStream.close(); os.close();
dicLength, encryptMetadata) ) currentAccessPermission = AccessPermission.getOwnerAccessPermission(); setCurrentAccessPermission(currentAccessPermission); dicLength, encryptMetadata) ) currentAccessPermission = new AccessPermission(dicPermissions); currentAccessPermission.setReadOnly(); setCurrentAccessPermission(currentAccessPermission);
System.arraycopy(envelopedData, 20, accessBytes, 0, 4); AccessPermission currentAccessPermission = new AccessPermission(accessBytes); currentAccessPermission.setReadOnly(); setCurrentAccessPermission(currentAccessPermission);
/** * Indicates if any revision 3 access permission is set or not. * * @return true if any revision 3 access permission is set */ protected boolean hasAnyRevision3PermissionSet() { if (canFillInForm()) { return true; } if (canExtractForAccessibility()) { return true; } if (canAssembleDocument()) { return true; } return canPrintDegraded(); } }
if (!ap.canExtractContent())
dicLength, encryptMetadata) ) currentAccessPermission = AccessPermission.getOwnerAccessPermission(); setCurrentAccessPermission(currentAccessPermission); dicLength, encryptMetadata) ) currentAccessPermission = new AccessPermission(dicPermissions); currentAccessPermission.setReadOnly(); setCurrentAccessPermission(currentAccessPermission);
System.arraycopy(envelopedData, 20, accessBytes, 0, 4); AccessPermission currentAccessPermission = new AccessPermission(accessBytes); currentAccessPermission.setReadOnly(); setCurrentAccessPermission(currentAccessPermission);
@Override Object[][] getFlagBits() { AccessPermission ap = new AccessPermission(encryptDictionary.getInt(COSName.P)); return new Object[][]{ new Object[]{3, "can print", ap.canPrint()}, new Object[]{4, "can modify", ap.canModify()}, new Object[]{5, "can extract content", ap.canExtractContent()}, new Object[]{6, "can modify annotations", ap.canModifyAnnotations()}, new Object[]{9, "can fill in form fields", ap.canFillInForm()}, new Object[]{10, "can extract for accessibility", ap.canExtractForAccessibility()}, new Object[]{11, "can assemble document", ap.canAssembleDocument()}, new Object[]{12, "can print degraded", ap.canPrintDegraded()}, }; } }
AccessPermission ap = new AccessPermission(); ap.setCanAssembleDocument(args[++i].equalsIgnoreCase( "true" )); ap.setCanExtractContent( args[++i].equalsIgnoreCase( "true" ) ); ap.setCanExtractForAccessibility( args[++i].equalsIgnoreCase( "true" ) ); ap.setCanFillInForm( args[++i].equalsIgnoreCase( "true" ) ); ap.setCanModify( args[++i].equalsIgnoreCase( "true" ) ); ap.setCanModifyAnnotations( args[++i].equalsIgnoreCase( "true" ) ); ap.setCanPrint( args[++i].equalsIgnoreCase( "true" ) ); ap.setCanPrintDegraded( args[++i].equalsIgnoreCase( "true" ) );
/** * Indicates if any revision 3 access permission is set or not. * * @return true if any revision 3 access permission is set */ protected boolean hasAnyRevision3PermissionSet() { if (canFillInForm()) { return true; } if (canExtractForAccessibility()) { return true; } if (canAssembleDocument()) { return true; } return canPrintDegraded(); } }
if( ! ap.canExtractContent() )
dicLength, encryptMetadata) ) currentAccessPermission = AccessPermission.getOwnerAccessPermission(); setCurrentAccessPermission(currentAccessPermission); dicLength, encryptMetadata) ) currentAccessPermission = new AccessPermission(dicPermissions); currentAccessPermission.setReadOnly(); setCurrentAccessPermission(currentAccessPermission);
System.arraycopy(envelopedData, 20, accessBytes, 0, 4); AccessPermission currentAccessPermission = new AccessPermission(accessBytes); currentAccessPermission.setReadOnly(); setCurrentAccessPermission(currentAccessPermission);
/** * This will tell if the access permission corresponds to owner * access permission (no restriction). * * @return true if the access permission does not restrict the use of the document */ public boolean isOwnerPermission() { return (this.canAssembleDocument() && this.canExtractContent() && this.canExtractForAccessibility() && this.canFillInForm() && this.canModify() && this.canModifyAnnotations() && this.canPrint() && this.canPrintDegraded() ); }
/** * returns an access permission object for a document owner. * * @return A standard owner access permission set. */ public static AccessPermission getOwnerAccessPermission() { AccessPermission ret = new AccessPermission(); ret.setCanAssembleDocument(true); ret.setCanExtractContent(true); ret.setCanExtractForAccessibility(true); ret.setCanFillInForm(true); ret.setCanModify(true); ret.setCanModifyAnnotations(true); ret.setCanPrint(true); ret.setCanPrintDegraded(true); return ret; }
document.getCurrentAccessPermission(); if (!ap.canExtractContent()) { throw new IOException( "You do not have permission to extract text.");