ColdFusion 8: Working with PDFs (Part 6)
Welcome to another installment in my series covering changes to PDF management in ColdFusion 8. If you haven't read the earlier stories, please see the links below in the Related Entries section. Todays entry is about security. This will just be a high level overview of what you can do. Check the documents for more specific information.
At a basic level, there are three basic things we can do with CFPDF:
- Set a password for opening the PDF
- Set restrictions on the document
- Set the encryption style for the document
All of these feature uses the Protect value for the action attribute of cfpdf. Let's start with the first one. Now you have always been able to set a password for a PDF when using cfdocument. But if you want to add a password to a document than you would need to use cfpdf. Here is a very simple example:
<cfdocument format="pdf" name="mydoc">
<h2>Wit and Wisdom of Paris Hilton</h2>
<p>
This space left intentionally blank.
</p>
</cfdocument>
<cfpdf action="protect" source="mydoc" newUserPassword="password" destination="test.pdf" overwrite="true">
Remember what I said above - you can set a password directly in the cfdocument tag. I'm just using this so folks can cut and paste directly into their editor. So as you can see - I create a simple PDF with cfdocument. Next I use cfpdf with the protection action. I specified a password and a destination to save the file. If I try to open this PDF I'll get prompted to enter a password.
Next lets look at a simple permissions example. Let's say we want to make a PDF, but we don't want people to copy from the document or print it. (And let's pretend we don't know what a screen capture program is.) All I have to do is specify an owner password and a set of permissions. The owner password allows an owner to modify the security of the PDF and the permissions detail what is allowed. Unfortunately you cannot specify what isn't allowed, you can only specify what is allowed. So in order to block printing and copying, I have to pass everything else.
<cfdocument format="pdf" name="mydoc">
<h2>Wit and Wisdom of Paris Hilton</h2>
<p>
This space left intentionally blank.
</p>
</cfdocument>
<cfpdf action="protect" source="mydoc" newOwnerPassword="opassword" destination="test2.pdf" overwrite="true"
permissions="AllowAssembly,AllowFillIn,AllowModifyAnnotations,AllowModifyContents,AllowScreenReaders,AllowSecure"
>
The permissions I left out were: AllowCopy,AllowDegradedPrinting,AllowPrinting. If I open this PDF and try to copy text, I'll get a warning beep. The print option is grayed out.
Now for the final example. When you secure PDF documents, ColdFusion will encrypt them using RC4 128-bit encryption. Frankly that could have been BattleStar Galatica encryption as I know next to nothing about the various types of encryption. But if you are concerned about the level of encryption, you can specify it using the encrypt attribute. Valid values are: AES_128, RC4_128M, RC4_128, RC4_40, and None.
What are some practical examples of this feature? Well obviously it is a good way to secure normally open PDF documents. You can image your source PDFs being 100% open, and then creating secured PDFs for download. Something else you could do is modify the encryption level if your web site user is outside the US. (Again, I know next to nothing about encryption, but I seem to remember that some levels of protection can't be exported. So you could have a lesser secure version for international visitors.)
Comments
Except - I used toBinary in cfcontent to serve up a PDF. That doesn't work on the labs version. This was a mistake on my part and someone else noted it. I pinged Adobe and they said this was fine.
Historically, Adobe has made editing of PDF files possible if you fill the form out and print it, but editing/saving of forms required expensive tools to do.
Has anything changed in this area?
Historically, what has precluded this from happening is that users use Acrobat Reader. For marketing/licensing reasons, Adobe requires users to have Acrobat to edit forms and save them in this way.
I'm wondering if, with the tighter integration of CF and PDF files, has Adobe made form editing possible to the masses who use Acrobat Reader, not Acrobat itself. My guess is no, which means web developers who don't control the client desktop still can't develop around the idea of users filling out PDF files online. But maybe I'm wrong - that is what lead to my post.
Kurt
http://www.cfquickdocs.com/cf8/?getDoc=cfpdfform#c...
And Peter, really, many people are writing openly about CF8 (myself included). Ray's right: beta participants are not to write about anything discussed on the beta forums. Everything else is fair game--and the fact that the docs are so publicly available further testifies to this.
Still, since so many people never read the docs, blog entries like this are a great way to get people to learn about what's new. There's certainly a LOT in CF8! :-)
As for CFPDFFORM, I'm sure Ray will be writing about it soon. It'll be a great continuation of this series. Thanks again, Ray.
"I'd *tried* that".
In other words, no, setting the newOwnerPassword or newUserPassword to the empty string does NOT remove the security setting. Seems a one way trip. :-)
Would love to hear if anyone learns otherwise. :-)
1- can you set the file to open for the password ONLY IF the date is less than or equal to [whatever I set it]?
2- can I restrict the user from 'saving' the file? [grey out the save button]?
Thanks in advance
William
2) Save is not an option as far as I know.
nice article. do you know a way to access a password protected file via cfcontent?
what i need to do is ...
deliver a pdf for viewing online (in the browsers window) but when the user downloads the pdf he should not be able to open it (because he doesn't know the password)
any ideas?
thx!
reinhard
i just need to have a possibility to pass the password to the pdf (programmatically with cf) when viewed with the browser ... any ideas?
Note that on my Mac, Firefox never views the PDF in browser. It _always_ downloads it.


They are very useful however and I hope you are on the CFWACK 8 team!