You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (Jira)" <ji...@apache.org> on 2021/02/04 17:16:00 UTC

[jira] [Commented] (PDFBOX-5096) Is there a way for PDFBox to decrypt encrypted pdf files without providing the password?

    [ https://issues.apache.org/jira/browse/PDFBOX-5096?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17278986#comment-17278986 ] 

Tilman Hausherr commented on PDFBOX-5096:
-----------------------------------------

It isn't possible, because PDFBox decrypts while parsing. {{document.setAllSecurityToBeRemoved(true)}} should work but then of course the saved PDF is no longer encrypted.

You could try PDFBox 1.8.*, that one has the decryption as an extra step. Open the file with {{loadNonSeq()}}, not {{load()}}. (I haven't tried that myself)

> Is there a way for PDFBox to decrypt encrypted pdf files without providing the password?
> ----------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-5096
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5096
>             Project: PDFBox
>          Issue Type: Wish
>            Reporter: Ling Hock Hin, Daniel
>            Priority: Major
>
> My application needs to remove metadata of pdf files when uploaded. When attempting to  load and remove metadata of encrypted pdf files, I get the logs below.
>  
>  at java.lang.Thread.run(Thread.java:748) [?:1.8.0_275] at java.lang.Thread.run(Thread.java:748) [?:1.8.0_275]Caused by: java.lang.IllegalStateException: PDF contains an encryption dictionary, please remove it with setAllSecurityToBeRemoved() or set a protection policy with protect() at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1367) ~[pdfbox-2.0.22.jar:2.0.22] at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1319) ~[pdfbox-2.0.22.jar:2.0.22] at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1357) ~[pdfbox-2.0.22.jar:2.0.22]
>  
> Tried to use the code below but it does not seem to work.
> PDDocument document = PDDocument.load(documentBytes);
>  if (document.isEncrypted()) {
>  document.setAllSecurityToBeRemoved(true);
>  }
>  
> Appreciate your advice.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org