Wednesday, March 14, 2012

Adobe Acrobat: Adding JavaScript Addons; Flattening Form Fields

I was using Acrobat 9. I combined some PDFs into one.  One or more of those PDFs was a form, with blanks to be filled out by users.  Thus, my combined PDF also looked like a form.  Specifically, it had a purple banner across the top that read,

Please fill out the following form. If you are a form author, choose Distribute Form in the Forms menu to send it to your recipients.
I wanted to get rid of that banner. One way would have been to print the whole document to PDF, but that would have made it much larger. Among other suggestions, I liked the one pointing to the Flatten Page Content Tool.  It sounded like this would provide what I needed.

To make that tool work, I needed to install a Java script.  The instructions told me that installation simple required me to copy the script into an appropriate folder.  The folder could be Acrobat’s App folder or its User folder, but not both.  The difference was that scripts in the App folder would be available to all users, while scripts in the User folder would be available only to the individual user.
The writer of the instructions said that, on his/her machine, the App folder (which I intended to use) was located at C:\Program Files\Adobe\Acrobat 8.0\Acrobat\JavaScripts.  My system was apparently different from theirs.  The original tipster said that, on her machine, the folder was at C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Javascripts folder.  I suspected (but was not sure) that mine was at C:\Program Files (x86)\Adobe\Acrobat 9.0\Acrobat\Javascripts.

The instructions indicated that there was a way to find the location of the App folder for sure.  I just needed to type “app.getPath("app","javascript");” in the Acrobat JavaScript Console.  The instructions said I could find that by going into Acrobat and hitting Ctrl-J.  But when I did that, I got a JavaScript Debugger that didn’t seem to have any way to do anything with the console.  I could type “app.getPath("app","javascript");” into the open space, but there was no Enter or Run button.  A guide said that, to “evaluate” (presumably meaning “execute”) a single line of Java code, I should put the cursor on that line and press Enter on the numeric keypad or Ctrl-Enter on the regular keyboard.

That worked.  I got “/C/Users/Ray/AppData/Roaming/Adobe/Acrobat/9.0/JavaScripts”.  So apparently my guess was wrong:  this was the folder where I needed to put the Flatten Page Content Tool script.  So I downloaded and unzipped that tool.  From the resulting folder, I moved the PDFScript_FlattenPages.js file to that C:\Users\Ray ... JavaScripts folder.  I had Acrobat running at the time, which was probably completely inappropriate.  I closed it, reopened the offending PDF, right-clicked on its toolbar, and chose More Tools.  There was an apparently new addition:  Add-on Tools Toolbar.  It was already selected.  And now, as I looked more closely at the toolbar, I saw that, indeed, I did have an icon for a hammer hitting  piece of paper – perfect for flattening a document.

The original tipster said this would permanently flatten the fields, but that they could still be edited in Illustrator, Photoshop, etc.  I didn’t care about that; I just wanted to lose the purple banner.  I hit the hammer icon.  It said, “Select Pages to Flatten.”  I chose all.  It was a large document, but the process was almost instantaneous.

About this time, I discovered that I could have just hit the button at the top left to hide that purple banner.  I really knew that already.  I'm sure of it.  Flattening didn’t reduce the PDF size for my purposes either.  OK, futile gesture.

2 comments:

Anonymous

Hi Ray,

The Flatten Page Content tool is published by my company, and I may well have been the one to respond to your post at AUC. Just wanted to point out that while you can turn off the Purple bar for the PDF on your machine does not mean it won't show up when someone else on another machine opens it. Turning it off is a user choice and saving it while turned off does not make that option "stick" for anyone else.
Also, a comment on the file size not being reduced- Did you do a "Save-As" or a "Save" after flattening? Save-As should reduce the file size nicely. Doing just a straight Save appends a lot of information and all changes you've made to the underlying structure of the PDF. Not stuff you can see unless you have a tool that shows the structure (guts) of a PDF, but under the covers stuff.

Best wishes,

Dimitri
WindJack Solutions
www.pdfscripting.com
www.windjack.com

raywood

Good information. I'm not sure, now, which option I chose. I'll have to take another look at it. Thanks!