Author Topic: PDF Optimization  (Read 7029 times)

0 Members and 1 Guest are viewing this topic.

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
PDF Optimization
« on: October 29, 2009, 09:06:33 AM »
Recently, I got challenged to find a solution for batch processing PDF documents. In this process, each PDF document had to be cropped, optimize for the web and saved as individual pages.

To my biggest surprise, the "optimize for the web" part proved to be the most elusive. After searching the Net, the only thing I was able to find were third party solution costing upwards of $500.

But then, an Adobe employee told me that since version 9.1 you could could make javascript calls to trigger a specific Preflight Profile. Up until then, I thought those profile were only there to "check" things up in my PDF documents but after reading up on them and playing with them, I realize they can do much more than that. Acrobat ships with quite a few of those Profiles pre-installed, furthermore, we can all create custom profiles that better suit our needs for any given situation.

To make everything work, I had to make the proper Javascript call. For this I referred to the Javascript 9.1 SDK where I searched for the keyword "Preflight". While I think that those reference pages are generally light on description and working examples, I was able to achieve what I set out to do using the following construct:

Quote
001     tell application "Adobe Acrobat Pro"
002          activate
003          tell document 1
004               -- Optimize for web
005               with timeout of (1 * hours) seconds
006                    set RunPreflight_JS to ""
007                    set RunPreflight_JS to RunPreflight_JS & "var oProfile = Preflight.getProfileByName(\"" & ProfileName & "\")" & return
008                    set RunPreflight_JS to RunPreflight_JS & "if( oProfile != undefined ) {" & return
009                    set RunPreflight_JS to RunPreflight_JS & tab & "var oThermometer = app.thermometer;" & return
010                    set RunPreflight_JS to RunPreflight_JS & tab & "var myPreflightResult = this.preflight( oProfile, false, oThermometer);" & return
011                    set RunPreflight_JS to RunPreflight_JS & tab & "if( myPreflightResult.numErrors > 0 ) {" & return
012                    set RunPreflight_JS to RunPreflight_JS & tab & tab & "var theResult = 'Error';" & return
013                    set RunPreflight_JS to RunPreflight_JS & tab & "} else {" & return
014                    set RunPreflight_JS to RunPreflight_JS & tab & tab & "var theResult =  'OK';" & return
015                    set RunPreflight_JS to RunPreflight_JS & tab & "}" & return
016                    set RunPreflight_JS to RunPreflight_JS & "} else {" & return
017                    set RunPreflight_JS to RunPreflight_JS & tab & tab & "var theResult =  'Profile Missing';" & return
018                    set RunPreflight_JS to RunPreflight_JS & "}" & return
019                    set RunPreflight_JS to RunPreflight_JS & "theResult;"
020                    
021                    set ProfileCheck to do script RunPreflight_JS
022               end timeout
023          end tell
024     end tell

Here, ProfileName refers to the Preflight Profile I wish to run on the current document.

This Javascript, or  ProfileCheck has 3 possible outcomes:
  • Profile Missing: The Preflight Profile referenced in getProfileByName is not installed;
  • Error: There were errors while running the specified Preflight Profile;
  • OK: The Preflight Profile ran without errors.

Enjoy!

P.S. I know that the tab are not needed in the above script, I just like putting them in for readability.
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5

Offline Glenn

  • Full Member
  • ***
  • Posts: 139
  • Karma: 4
  • Gender: Male
Re: PDF Optimization
« Reply #1 on: October 29, 2009, 10:34:05 AM »
Preflight Profiles have been around since Acrobat InProduction (equivalent to Acrobat 4) I used this very crudely to fix troublesome PDFs that would'nt RIP on an old level2 imagesetter, this was before I'd used Pitstop. The problem is that the interface for these Profiles is scarily complicated and I don't find it at all intuitive. I'm always impressed by forum posters who suggest fixing things using these tools but even Pitstop's v8 disaster of a GUI is streets ahead. I'm under the impression that a lot of Acrobat Pro's Profiles and FixUps are written by Callas and that their PDFToolbox is a user friendly GUI into it.

Anyway I'm glad you found your solution.

By The way, what does optimize for the web do?

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: PDF Optimization
« Reply #2 on: October 29, 2009, 10:40:24 AM »
optimize for web makes a multi page PDF document only download data on a page by page request from a browser.

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: PDF Optimization
« Reply #3 on: October 29, 2009, 11:27:09 AM »
By The way, what does optimize for the web do?

Well, there is two side to this question.

To make a PDF web friendly your first try would be to save your PDF without linearize (or is it WITH I can't remember). This reduce the file size somewhat while flattening form I believe and other nebulous stuff. This is akin to choosing the Optimize for Fast Web View option when optimizing a PDF. I believe this option allows you to streem the PDF to the end user (allowing the end user to view pages before the whole thing has finished downloading).

In my situation however I needed to compress images as well. Acrobat comes with the "Online Publishing (optimize for size)" Preflight Profile that does that pretty well but I needed to tweak it somewhat for my needs. So I created the necessary "fixups" and setup my own customized profile.

HTH
« Last Edit: October 29, 2009, 11:29:41 AM by Publi-Script »
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: PDF Optimization
« Reply #4 on: October 29, 2009, 11:42:12 AM »
I do very little for web usage myself but lots of PDF repurposing though so this will become very handy indeed. (hence the karma)  ;)

Offline Glenn

  • Full Member
  • ***
  • Posts: 139
  • Karma: 4
  • Gender: Male
Re: PDF Optimization
« Reply #5 on: October 29, 2009, 12:24:41 PM »
PDFs on the Web seem to Jam my Safari and I need to Force Quit after Saving them, does this happen to you?

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: PDF Optimization
« Reply #6 on: October 29, 2009, 12:35:41 PM »
PDFs on the Web seem to Jam my Safari and I need to Force Quit after Saving them, does this happen to you?
Can't tell you, I have all my browsers (I never use Safari) open PDF in Acrobat.... I never got used to watching PDF "online"
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: PDF Optimization
« Reply #7 on: October 30, 2009, 03:17:40 AM »
PDFs on the Web seem to Jam my Safari and I need to Force Quit after Saving them, does this happen to you?
It often happens to me but I couldn't say more about as what kind of PDFs fail to launch properly or in what circumstances. You'd probably better open them outside of Safari (Ctrl-click and save it to the Desktop for instance). HTH.
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =