views:

592

answers:

3

So I am trying to batch convert a bunch of PDFs to JPEG files as part of a larger Applescript, and I'm finding that some of the parameters in "PDF Open Options" are ignored. Namely, the "height", "width" and "constrain proportions" parameters.

This code is lifted directly from the Photoshop CS3 Scripting Guide (with filename changed, of course):

tell application "Adobe Photoshop CS3"
set myFilePath to alias "WABEL0457937:Users:Charles:Desktop:8925.pdf"
with timeout of 10000 seconds
open myFilePath as PDF with options {class:PDF open options, height:pixels 100, width:pixels 200, mode:RGB, resolution:72, use antialias:true, page:1, constrain proportions:false}
end timeout
end tell

In the resulting file, the "resolution" is correct, but the height and width are calculated using the PDF's original height and width multiplied by the resolution, and the image is constrained to the original proportions.

I thought it might be a collision with specifying the resolution and the height/width in pixels, so I tried omitting the resolution, but then it just defaults to 300.

Anyone else create a script that opens PDFs and run into this?

A: 

In looking at the AS Dictionary for Photoshop CS3, it states that the height, width, and constrain proportions properties for PDF open options have all been deprecated since CS2. (But leave it to Adobe to not clean up after themselves and thus furthering the inconsistencies of their interfaces.)

Philip Regan
A: 

The way I worked out to do this was to determine the resolution of the PDF at 72DPI using a shell script, and then calculate the optimal resolution to rasterize to arrive at the desired dimensions.

(FYI: "str_replace" is a custom function to find and replace text in a string -- it's not a built-in Applescript function.)

set pageHeight to do shell script "/usr/bin/mdls -name kMDItemPageHeight " & quoted form of (POSIX path of this_item as string)
set pageHeight to my str_replace("kMDItemPageHeight = ", "", pageHeight)
set pageWidth to do shell script "/usr/bin/mdls -name kMDItemPageWidth " & quoted form of (POSIX path of this_item as string)
set pageWidth to my str_replace("kMDItemPageWidth = ", "", pageWidth)

if (pageHeight as number) is greater than (pageWidth as number) then
set pdf_resolution to round (1000 / (pageHeight as number) * 72) rounding up
else
set pdf_resolution to round (1000 / (pageWidth as number) * 72) rounding up
end if

open this_item as PDF with options {class:PDF open options, resolution:pdf_resolution, mode:RGB, use antialias:true, suppress warnings:false, use page number:true, page:1, crop page:media box}

I used "rounding up" to ensure that the result is equal to or slightly over my target resolution. It's only ballpark accurate, but it's better than what I started with.

Photoshop opens the PDF at the correct dimensional proportions, so I'm not sure what it is that you are trying to accomplish here. You could just as easily open the PDF at the desired resolution (or even something larger and then lower the resolution of the resulting image within Photoshop itself).--ditch all of the preceding code and just use this...open this_item as PDF with options {class:PDF open options, resolution:72, mode:RGB, use antialias:true, suppress warnings:false, use page number:true, page:1, crop page:media box}
Philip Regan
Also, PDFs, in of themselves, are mostly vector in nature and resolution only applies to any raster art contained inside. Resolution only applies to the entire PDF when rasterizing pages like you are here. From what I can tell, what you're doing is overkill and not giving you anything that Photoshop isn't already doing. Sorry
Philip Regan
I'm trying to get "master" JPEGs of about 1000 pixels that I can use for on-the-fly resizing to use on a website. Keeping them at "correct" size is unimportant. Some PDFs will be larger than actual, and some will be smaller.If I ditch the shell scripts and rasterize everything at a much greater resolution (to make the smallest PDFs yield JPGs large enough to use) then my largest PDFs take a LOT of time to render, wasting processing power and time.The shell scripts solve that. That's the whole point.
A: 

Thanks zanseattle I was having the same problem!

@ Philip Regan: lol for completely missing the point, especially ending your misdirected discussion of zanseattle's great solution with "sorry" haha.

gleam
Well, sometimes it can be hard to understand what someone is after. I don't think I really mentioned *why* I was trying to do what I was doing, which might have made it clearer from the start.Glad this helped you! I've had this solution in use for quite some time now on the site I wrote it for, and after including a few catches for errors, now it's rock solid.