Easiest way to programatically determine if a PDF is encrypted?

B

Brian Parker

I'm reading PDF files in C#. I read them in using a TextReader then I parse out the pieces I want
like the CreationDate, Author, etc.

Sometimes, the PDF file is encrypted and I get binary junk in my parsed strings.

Is there a real simple way to determine that a PDF file is using encryption besides checking if the
individual pieces of data have binary junk in them?

-BEP
 
S

Simon Dahlbacka

Brian said:
I'm reading PDF files in C#. I read them in using a TextReader then I parse out the pieces I want
like the CreationDate, Author, etc.

Sometimes, the PDF file is encrypted and I get binary junk in my parsed strings.

Is there a real simple way to determine that a PDF file is using encryption besides checking if the
individual pieces of data have binary junk in them?

-BEP

- use a pdf library with appropriate functionality

or

- read the PDF spec and figure out where to check for encryptedness
 
R

rpresser

Bruno said:
In a recent blogpost Matt Stephens called iText
'one of Java's best-kept secrets':
http://www.adtmag.com/blogs/blog.aspx?a=19226
Maybe iTextSharp is one of .NET's best-kept secrets.
There is no need to write a PDF library in .NET,
you can just use iTextSharp (it's free!)
http://itextsharp.sourceforge.net/
br,
Bruno

Bruno,

iTextSharp doesn't sound entirely appropriate for his needs. He's not
trying to build PDFs, he's trying to glean information about them. I
know iText has some primitives that read through PDF internals but
they're a bear to use.
 
B

bruno

rpresser said:
Bruno,

iTextSharp doesn't sound entirely appropriate for his needs. He's not
trying to build PDFs, he's trying to glean information about them. I
know iText has some primitives that read through PDF internals but
they're a bear to use.

I know, you need a degree in rocket science to know
how to invoke the method PdfReader.isEncrypted() ;-)
br,
Bruno
 
R

rpresser

bruno said:
I know, you need a degree in rocket science to know
how to invoke the method PdfReader.isEncrypted() ;-)

D'oh! Yet another thrilling instance of Ross Is Wrong! :-/

Sorry...
 
T

Tim Wallace

Go to the Adobe site and download the spec for PDF. The file is really just
a bunch of markup. There is an element that gets set to indicate usage of
encryption (I forget, as it's been a while since I was coding for PDFs).

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top