You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Ad...@swmc.com on 2009/11/02 16:59:32 UTC

Re: PDF Permissions

I'm not sure that I know enough about PDF encryption and how PDFBox 
decrypts files to be of much more help here.  A NullPointerException 
should be easy to track down though.  About the only workaround I can 
think of would be to open & remove all encryption, save, open unencrypted 
file and do what you need to do.  Of course, this would be a performance 
hit, but it's a quick & dirty solution which might be good enough to get 
you by for now.  I've never wanted to open an encrypted PDF and then save 
it without stripping out the encryption, so I don't know much about saving 
encrypted PDFs.  Trace through the SecurityHandler classes, and hit the 
PDF reference from Adobe.  That's your best bet.

Good luck,
Adam




"Hesham G." <he...@gmail.com> 
10/31/2009 02:40
Please respond to
pdfbox-users@incubator.apache.org


To
<pd...@incubator.apache.org>
cc

Subject
Re: PDF Permissions






Hi ,

Thanks for your help Adam.

Today I have tried to change the permissions of my PDF, and your code 
worked 
fine ... I access the PDF using 'Owner Password'.
My problem is I want to write to the encrypted PDF ... This works fine, 
until the line of saving the PDF, I get this Exception :

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
                 at 
org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.prepareDocumentForEncryption(StandardSecurityHandler.java:261)
                 at 
org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1002)


This exception just appears even if I don't write anything in the PDF ... 
Just when I try to save it, ex :
pdfFile = PDDocument.load( file );  // Open this pdf to edit.// Decrypt 
the pdf if it's encrypted :
if( pdfFile.isEncrypted() ) {                StandardDecryptionMaterial dm 
= new StandardDecryptionMaterial( "1234" );
                 pdfFile.openProtection( dm );
}

pdfFile.save( file );  // Exception here.
pdfFile.close();


Best regards ,
Hesham

--------------------------------------------------
From: <Ad...@swmc.com>
Sent: Friday, October 30, 2009 5:53 PM
To: <pd...@incubator.apache.org>
Cc: <pd...@incubator.apache.org>
Subject: Re: PDF Permissions

> Here are the basics:
>        PDDocument doc = null;
>        try {
>            doc = PDDocument.load(someFile);
>            StandardDecryptionMaterial sdm = new
> StandardDecryptionMaterial("yourPasswordGoesHere");
>            doc.openProtection(sdm);
>            // use the document like normal
>        } catch(...) {
>            // decryption error
>        } finally {
>            if(doc != null)
>                doc.close();
>        }
>
>
>
>
> "Hesham G." <he...@gmail.com>
> 10/30/2009 04:37
> Please respond to
> pdfbox-users@incubator.apache.org
>
>
> To
> <pd...@incubator.apache.org>
> cc
>
> Subject
> Re: PDF Permissions
>
>
>
>
>
>
> I am having problems with encrypted PDFs too. I don't know but I think
> there
> are things wrong with the Encryption / Decryption classes.
>
> Best regards ,
> Hesham
>
>
>
>
> ?  Click here to submit conditions
>
> This email and any content within or attached hereto from  Sun West 
> Mortgage Company, Inc.  is confidential and/or legally privileged. The 
> information is intended only for the use of the individual or entity 
named 
> on this email. If you are not the intended recipient, you are hereby 
> notified that any disclosure, copying, distribution or the taking of any 

> action in reliance on the contents of this email information is strictly 

> prohibited, and that the documents should be returned to this office 
> immediately by email. Receipt by anyone other than the intended 
recipient 
> is not a waiver of any privilege. Please do not include your social 
> security number, account number, or any other personal or financial 
> information in the content of the email. Should you have any questions, 
> please call  (800) 453 7884.   = 



?  Click here to submit conditions  

This email and any content within or attached hereto from  Sun West Mortgage Company, Inc.  is confidential and/or legally privileged. The information is intended only for the use of the individual or entity named on this email. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on the contents of this email information is strictly prohibited, and that the documents should be returned to this office immediately by email. Receipt by anyone other than the intended recipient is not a waiver of any privilege. Please do not include your social security number, account number, or any other personal or financial information in the content of the email. Should you have any questions, please call  (800) 453 7884.   

ExtractText.java doesn't work and a question about field charactersByArticle in PDFTextStripper

Posted by Shen Wang <fe...@gmail.com>.
Hi guys,

I am trying to use ExtractText.java to extract the text from a pdf file. 
However, it only gives me an empty .txt file. I tracked down the source 
code, and get confused by PDFTextStripper.

So, the ExtractText.java calls stripper.writerPage which in turn calls 
processPage method. In processPage method, it plays with the 
charactersByArticle field and my understanding is that it wants to put 
the articles information into the field charactersByArticle. However, 
when it sets charactersByArticle's value, it actually set it to empty 
ArrayList ("charactersByArticle.set( i, new ArrayList() );"). And this 
line seems to be the only place that the field charactersByArticle is 
ever modified. As a result charactersByArticle is nothing but a vector 
of empty ArrayList. Then, when the writePage method is called, it 
iterates through charactersByArticle and finds no text. This is my 
understanding of the reason why the ExtractText example doesn't work for 
me. Please do let me know if I get something wrong or you guys have any 
suggestions.

Thanks!

Felix

Re: PDF Permissions

Posted by "Hesham G." <he...@gmail.com>.
Thanks a lot Adam.

The solution you mentioned is the same thing I did in my last message, and 
that's why it caused that Exception ... I opened the pdf, decrypted it, 
saved it without doing any action, then close it. But the Exception occurred 
in the save step.


I have tried a solution that worked fine for me.
I opened the file, decrypted it, did all the writing stuff I wanted, then 
before saving it I encrypted it again with null owner / user passwords ... 
Then saved and closed it.

That did the trick.


Best regards ,
Hesham




--------------------------------------------------
From: <Ad...@swmc.com>
Sent: Monday, November 02, 2009 5:59 PM
To: <pd...@incubator.apache.org>
Cc: <pd...@incubator.apache.org>
Subject: Re: PDF Permissions

> I'm not sure that I know enough about PDF encryption and how PDFBox
> decrypts files to be of much more help here.  A NullPointerException
> should be easy to track down though.  About the only workaround I can
> think of would be to open & remove all encryption, save, open unencrypted
> file and do what you need to do.  Of course, this would be a performance
> hit, but it's a quick & dirty solution which might be good enough to get
> you by for now.  I've never wanted to open an encrypted PDF and then save
> it without stripping out the encryption, so I don't know much about saving
> encrypted PDFs.  Trace through the SecurityHandler classes, and hit the
> PDF reference from Adobe.  That's your best bet.
>
> Good luck,
> Adam
>
>
>
>
> "Hesham G." <he...@gmail.com>
> 10/31/2009 02:40
> Please respond to
> pdfbox-users@incubator.apache.org
>
>
> To
> <pd...@incubator.apache.org>
> cc
>
> Subject
> Re: PDF Permissions
>
>
>
>
>
>
> Hi ,
>
> Thanks for your help Adam.
>
> Today I have tried to change the permissions of my PDF, and your code
> worked
> fine ... I access the PDF using 'Owner Password'.
> My problem is I want to write to the encrypted PDF ... This works fine,
> until the line of saving the PDF, I get this Exception :
>
> Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
>                 at
> org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.prepareDocumentForEncryption(StandardSecurityHandler.java:261)
>                 at
> org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1002)
>
>
> This exception just appears even if I don't write anything in the PDF ...
> Just when I try to save it, ex :
> pdfFile = PDDocument.load( file );  // Open this pdf to edit.// Decrypt
> the pdf if it's encrypted :
> if( pdfFile.isEncrypted() ) {                StandardDecryptionMaterial dm
> = new StandardDecryptionMaterial( "1234" );
>                 pdfFile.openProtection( dm );
> }
>
> pdfFile.save( file );  // Exception here.
> pdfFile.close();
>
>
> Best regards ,
> Hesham
>
> --------------------------------------------------
> From: <Ad...@swmc.com>
> Sent: Friday, October 30, 2009 5:53 PM
> To: <pd...@incubator.apache.org>
> Cc: <pd...@incubator.apache.org>
> Subject: Re: PDF Permissions
>
>> Here are the basics:
>>        PDDocument doc = null;
>>        try {
>>            doc = PDDocument.load(someFile);
>>            StandardDecryptionMaterial sdm = new
>> StandardDecryptionMaterial("yourPasswordGoesHere");
>>            doc.openProtection(sdm);
>>            // use the document like normal
>>        } catch(...) {
>>            // decryption error
>>        } finally {
>>            if(doc != null)
>>                doc.close();
>>        }
>>
>>
>>
>>
>> "Hesham G." <he...@gmail.com>
>> 10/30/2009 04:37
>> Please respond to
>> pdfbox-users@incubator.apache.org
>>
>>
>> To
>> <pd...@incubator.apache.org>
>> cc
>>
>> Subject
>> Re: PDF Permissions
>>
>>
>>
>>
>>
>>
>> I am having problems with encrypted PDFs too. I don't know but I think
>> there
>> are things wrong with the Encryption / Decryption classes.
>>
>> Best regards ,
>> Hesham
>>
>>
>>
>>
>> ?  Click here to submit conditions
>>
>> This email and any content within or attached hereto from  Sun West
>> Mortgage Company, Inc.  is confidential and/or legally privileged. The
>> information is intended only for the use of the individual or entity
> named
>> on this email. If you are not the intended recipient, you are hereby
>> notified that any disclosure, copying, distribution or the taking of any
>
>> action in reliance on the contents of this email information is strictly
>
>> prohibited, and that the documents should be returned to this office
>> immediately by email. Receipt by anyone other than the intended
> recipient
>> is not a waiver of any privilege. Please do not include your social
>> security number, account number, or any other personal or financial
>> information in the content of the email. Should you have any questions,
>> please call  (800) 453 7884.   =
>
>
>
> ?  Click here to submit conditions
>
> This email and any content within or attached hereto from  Sun West
> Mortgage Company, Inc.  is confidential and/or legally privileged. The
> information is intended only for the use of the individual or entity named
> on this email. If you are not the intended recipient, you are hereby
> notified that any disclosure, copying, distribution or the taking of any
> action in reliance on the contents of this email information is strictly
> prohibited, and that the documents should be returned to this office
> immediately by email. Receipt by anyone other than the intended recipient
> is not a waiver of any privilege. Please do not include your social
> security number, account number, or any other personal or financial
> information in the content of the email. Should you have any questions,
> please call  (800) 453 7884.   =