if(ap.isOwnerPermission()) document.setAllSecurityToBeRemoved(true); document.save( outfile );
doc.setAllSecurityToBeRemoved(true); for (COSObject cosObject : doc.getDocument().getObjects())
public static void main(String[] args){ PDDocument pd; try { File input = new File("p.pdf"); // password protected PDF file from where you would like to extract pd = PDDocument.load(input,"your_password"); pd.setAllSecurityToBeRemoved(true); //for printing pdf file data PDFTextStripper reader = new PDFTextStripper(); String pageText = reader.getText(pd); System.out.println(pageText); } catch (Exception e){ e.printStackTrace(); } }
public InputStream convertDocument(InputStream dataStream) throws Exception { // just acts as a pass through since already in pdf format PipedOutputStream os = new PipedOutputStream(); PipedInputStream is = new PipedInputStream(os); System.setProperty("org.apache.pdfbox.baseParser.pushBackSize", "2024768"); //for large files PDDocument doc = PDDocument.load(dataStream, true); if (doc.isEncrypted()) { //remove the security before adding protections doc.decrypt(""); doc.setAllSecurityToBeRemoved(true); } doc.save(os); doc.close(); dataStream.close(); os.close(); return is; }
private Object doAppend(Exchange exchange) throws IOException { LOG.debug("Got {} operation, going to append text to provided pdf.", pdfConfiguration.getOperation()); String body = exchange.getIn().getBody(String.class); PDDocument document = exchange.getIn().getHeader(PDF_DOCUMENT_HEADER_NAME, PDDocument.class); if (document == null) { throw new IllegalArgumentException(String.format("%s header is expected for append operation", PDF_DOCUMENT_HEADER_NAME)); } if (document.isEncrypted()) { document.setAllSecurityToBeRemoved(true); } ProtectionPolicy protectionPolicy = exchange.getIn().getHeader( PROTECTION_POLICY_HEADER_NAME, ProtectionPolicy.class); appendToPdfDocument(body, document, protectionPolicy); OutputStream byteArrayOutputStream = new ByteArrayOutputStream(); document.save(byteArrayOutputStream); return byteArrayOutputStream; }
PDDocument doc = PDDocument.load("filename"); doc.setAllSecurityToBeRemoved(true); PDDocumentCatalog docCatalog = doc.getDocumentCatalog(); PDAcroForm form = docCatalog.getAcroForm(); PDXFA xfa = form.getXFA(); COSBase cos = xfa.getCOSObject(); COSStream coss = (COSStream) cos; InputStream cosin = coss.getUnfilteredStream(); Document document = documentBuilder.parse(cosin); COSStream cosout = new COSStream(new RandomAccessBuffer()); OutputStream out = cosout.createUnfilteredStream(); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(xmlDoc); StreamResult result = new StreamResult(out); transformer.transform(source, result); PDXFA xfaout = new PDXFA(cosout); form.setXFA(xfaout);
if(ap.isOwnerPermission()) document.setAllSecurityToBeRemoved(true); document.save( outfile );
if(ap.isOwnerPermission()) document.setAllSecurityToBeRemoved(true); document.save( outfile );
document.setAllSecurityToBeRemoved(true); System.out.println(filePath + " Doc was decrypted");
doc.setAllSecurityToBeRemoved(true); for (COSObject cosObject : doc.getDocument().getObjects())
pdfDoc.setAllSecurityToBeRemoved(true); Blob result = Blobs.createBlobWithExtension(".pdf"); pdfDoc.save(result.getFile());