September 05, 2010, 08:51:35 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: PDF Optimization  (Read 584 times)
0 Members and 1 Guest are viewing this topic.
Publi-Script
Administrator
Hero Member
*****

Karma: 16
Offline Offline

Gender: Male
Posts: 544


Automate your Life!


WWW
« on: October 29, 2009, 06: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.

Logged

Michel Lemieux
Forum Administrator
-------------------------
OS X 10.5.8
Quark 6.5 / 7.5 / 8.01
Illustrator CS / CS2 / CS3 / CS4
Photoshop CS / CS2 / CS3 / CS4
InDesign CS / CS2 / CS3 / CS4
Dreamweaver 8 / 9 / CS4
Script Debugger 3
Glenn
Full Member
***

Karma: 4
Offline Offline

Gender: Male
Posts: 138



« Reply #1 on: October 29, 2009, 07: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?

Logged
larsen67
Sr. Member
****

Karma: 10
Offline Offline

Gender: Male
Posts: 457



« Reply #2 on: October 29, 2009, 07:40:24 AM »

optimize for web makes a multi page PDF document only download data on a page by page request from a browser.

Logged
Publi-Script
Administrator
Hero Member
*****

Karma: 16
Offline Offline

Gender: Male
Posts: 544


Automate your Life!


WWW
« Reply #3 on: October 29, 2009, 08: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, 08:29:41 AM by Publi-Script » Logged

Michel Lemieux
Forum Administrator
-------------------------
OS X 10.5.8
Quark 6.5 / 7.5 / 8.01
Illustrator CS / CS2 / CS3 / CS4
Photoshop CS / CS2 / CS3 / CS4
InDesign CS / CS2 / CS3 / CS4
Dreamweaver 8 / 9 / CS4
Script Debugger 3
larsen67
Sr. Member
****

Karma: 10
Offline Offline

Gender: Male
Posts: 457



« Reply #4 on: October 29, 2009, 08: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)  Wink

Logged
Glenn
Full Member
***

Karma: 4
Offline Offline

Gender: Male
Posts: 138



« Reply #5 on: October 29, 2009, 09:24:41 AM »

PDFs on the Web seem to Jam my Safari and I need to Force Quit after Saving them, does this happen to you?

Logged
Publi-Script
Administrator
Hero Member
*****

Karma: 16
Offline Offline

Gender: Male
Posts: 544


Automate your Life!


WWW
« Reply #6 on: October 29, 2009, 09:35:41 AM »

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"

Logged

Michel Lemieux
Forum Administrator
-------------------------
OS X 10.5.8
Quark 6.5 / 7.5 / 8.01
Illustrator CS / CS2 / CS3 / CS4
Photoshop CS / CS2 / CS3 / CS4
InDesign CS / CS2 / CS3 / CS4
Dreamweaver 8 / 9 / CS4
Script Debugger 3
Jean-Marie Schwartz
Sr. Member
****

Karma: 6
Offline Offline

Gender: Male
Posts: 336


Well, anything personal is... personal.


« Reply #7 on: October 30, 2009, 12: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.

Logged

Jean-Marie Schwartz
Create tastier... book :-)

> Apple G5 • Mac OS 10.4.11 • 1.8 GHz Power PC • 2 Go DDR SDRAM • Quark 7.5 • Adobe CS <
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!