You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by St...@toyota-europe.com on 2011/09/16 15:00:22 UTC
PDF is wrongly password protected
I am using the code below to semi-protect the generated PDFs, hundreds of
these are being generated but in the past three months I have (just) two
instances where the PDF cannot be opened (in adobe or pdfxchange) because
it prompts for a password.
-----------------------------------------------------------------
public void lockDown(String owner_pwd) throws
BadSecurityHandlerException {
AccessPermission ap =
document.getCurrentAccessPermission();
logger.info("locking down ");
ap.setCanModify(false);
ap.setCanAssembleDocument(false);
ap.setCanExtractContent(false);
ap.setCanFillInForm(false);
ap.setCanModifyAnnotations(false);
ap.setReadOnly();
StandardProtectionPolicy policy = new
StandardProtectionPolicy(owner_pwd, null, ap);
//policy.
document.protect(policy);
logger.info("locked");
}
-----------------------------------------------------------------
I'm failrly sure (though I could be wrong) that the application is not
responsible for, as you can see, the user password is hard-coded and null.
Any ideas
Steve Lindsey
Re: PDF is wrongly password protected
Posted by Adam Nichols <mr...@gmail.com>.
I see. I haven't done any PDF generation, but I think you'd have to
take a look at the specific function calls for those particular PDFs.
Can you reproduce the issue consistently? It'd help you track it down
if you can provide the same inputs as production and then check at
various points to determine where the security is getting triggered.
As a short-term workaround, give the setAllSecurityToBeRemoved(true)
method (see PDFBOX-526) a try right before you encrypt it, and then
see if that works. I'm fairly certain it will. It's not the best
solution, but it should be the quickest one.
On Mon, Sep 19, 2011 at 5:01 AM, <St...@toyota-europe.com> wrote:
> Hi, thanks for the reply.
>
> These are new files, ie, i'm creating them from a memory structure using
> Apache FOP (legacy code), PDFBox was added recently to post-process the
> documents in order to make them read-only .
>
> The crucial point is that all of the pdfs (200-300 per day) are created
> and locked down in the same way and yet in the last couple of months I've
> had two instances of a file being password protected at the user level.
>
> Steve Lindsey
>
>
>
>
>
>
>
>
>
>
>
> Adam Nichols <mr...@gmail.com>
> 16/09/2011 17:15
> Please respond to
> users@pdfbox.apache.org
>
> To
> users@pdfbox.apache.org
> cc
>
> Subject
> Re: PDF is wrongly password protected
>
>
>
>
>
>
> Was the file password protected before you started? There's a method to
> remove all encryption (I think it's in PDDocument, if I recall
> correctly). If you start with that method, you can be certain that any
> old encryption was removed, and all that will remain is what is in your
> code below.
>
> On 09/16/2011 09:00 AM, Stephen.Lindsey@toyota-europe.com wrote:
>> I am using the code below to semi-protect the generated PDFs, hundreds
> of
>> these are being generated but in the past three months I have (just) two
>> instances where the PDF cannot be opened (in adobe or pdfxchange)
> because
>> it prompts for a password.
>>
>>
>> -----------------------------------------------------------------
>> public void lockDown(String owner_pwd) throws
>> BadSecurityHandlerException {
>> AccessPermission ap =
>> document.getCurrentAccessPermission();
>> logger.info("locking down ");
>> ap.setCanModify(false);
>> ap.setCanAssembleDocument(false);
>> ap.setCanExtractContent(false);
>> ap.setCanFillInForm(false);
>> ap.setCanModifyAnnotations(false);
>> ap.setReadOnly();
>> StandardProtectionPolicy policy = new
>> StandardProtectionPolicy(owner_pwd, null, ap);
>> //policy.
>> document.protect(policy);
>> logger.info("locked");
>> }
>> -----------------------------------------------------------------
>>
>> I'm failrly sure (though I could be wrong) that the application is not
>> responsible for, as you can see, the user password is hard-coded and
> null.
>>
>> Any ideas
>>
>> Steve Lindsey
>>
>
>
>
Re: PDF is wrongly password protected
Posted by St...@toyota-europe.com.
Hi, thanks for the reply.
These are new files, ie, i'm creating them from a memory structure using
Apache FOP (legacy code), PDFBox was added recently to post-process the
documents in order to make them read-only .
The crucial point is that all of the pdfs (200-300 per day) are created
and locked down in the same way and yet in the last couple of months I've
had two instances of a file being password protected at the user level.
Steve Lindsey
Adam Nichols <mr...@gmail.com>
16/09/2011 17:15
Please respond to
users@pdfbox.apache.org
To
users@pdfbox.apache.org
cc
Subject
Re: PDF is wrongly password protected
Was the file password protected before you started? There's a method to
remove all encryption (I think it's in PDDocument, if I recall
correctly). If you start with that method, you can be certain that any
old encryption was removed, and all that will remain is what is in your
code below.
On 09/16/2011 09:00 AM, Stephen.Lindsey@toyota-europe.com wrote:
> I am using the code below to semi-protect the generated PDFs, hundreds
of
> these are being generated but in the past three months I have (just) two
> instances where the PDF cannot be opened (in adobe or pdfxchange)
because
> it prompts for a password.
>
>
> -----------------------------------------------------------------
> public void lockDown(String owner_pwd) throws
> BadSecurityHandlerException {
> AccessPermission ap =
> document.getCurrentAccessPermission();
> logger.info("locking down ");
> ap.setCanModify(false);
> ap.setCanAssembleDocument(false);
> ap.setCanExtractContent(false);
> ap.setCanFillInForm(false);
> ap.setCanModifyAnnotations(false);
> ap.setReadOnly();
> StandardProtectionPolicy policy = new
> StandardProtectionPolicy(owner_pwd, null, ap);
> //policy.
> document.protect(policy);
> logger.info("locked");
> }
> -----------------------------------------------------------------
>
> I'm failrly sure (though I could be wrong) that the application is not
> responsible for, as you can see, the user password is hard-coded and
null.
>
> Any ideas
>
> Steve Lindsey
>
Re: PDF is wrongly password protected
Posted by Adam Nichols <mr...@gmail.com>.
Was the file password protected before you started? There's a method to
remove all encryption (I think it's in PDDocument, if I recall
correctly). If you start with that method, you can be certain that any
old encryption was removed, and all that will remain is what is in your
code below.
On 09/16/2011 09:00 AM, Stephen.Lindsey@toyota-europe.com wrote:
> I am using the code below to semi-protect the generated PDFs, hundreds of
> these are being generated but in the past three months I have (just) two
> instances where the PDF cannot be opened (in adobe or pdfxchange) because
> it prompts for a password.
>
>
> -----------------------------------------------------------------
> public void lockDown(String owner_pwd) throws
> BadSecurityHandlerException {
> AccessPermission ap =
> document.getCurrentAccessPermission();
> logger.info("locking down ");
> ap.setCanModify(false);
> ap.setCanAssembleDocument(false);
> ap.setCanExtractContent(false);
> ap.setCanFillInForm(false);
> ap.setCanModifyAnnotations(false);
> ap.setReadOnly();
> StandardProtectionPolicy policy = new
> StandardProtectionPolicy(owner_pwd, null, ap);
> //policy.
> document.protect(policy);
> logger.info("locked");
> }
> -----------------------------------------------------------------
>
> I'm failrly sure (though I could be wrong) that the application is not
> responsible for, as you can see, the user password is hard-coded and null.
>
> Any ideas
>
> Steve Lindsey
>