Some pdfs have owner password to prevent user from copying, extracting or printing … etc …
By using pdf box, you can easily deciphere this kind of open and read only pdfs.
123456789101112131415161718
PDDocumentdocument=PDDocument.load(filePath,true);if(document.isEncrypted()){try{document.decrypt("");document.setAllSecurityToBeRemoved(true);}catch(Exceptione){thrownewUnableToDeciphereException("The document is encrypted, and we can't decrypt it.",e);}}ByteArrayOutputStreamoutStream=newByteArrayOutputStream();document.save(outStream);document.close();byte[]decipheredBytes=outStream.toByteArray();
or you can use a FileOutputStream to save it into a file. Actually, document.save() has a parameter filepath, so you can , for example : document.save(“/Users/User/Desktop/abc.pdf”) .