Replacing Automator's "Render PDF Pages as Images"

Hi,

I’ve been trying to build a workflow for a while now, the goal being to take a 236page InDesign document, and render out all the pages as images, so they can be put into a fixed-layout EPUB.

For various reasons, I’m using CS5 versions of InDesign etc, so there’s no direct PNG or Fixed-Layout EPUB output.

I had created a nice Automator workflow, with help from here, which when combined with an InDesign script that output the document as individual pages in PDF format, let me select all (or any of) those PDFs, right click, and within a couple of minutes, I’d have a folder full of PNG files of the pages. The applescripts turn off the system’s sub-pixel antialiasing (which was putting red/blue halos around text) then re-enable it.

Quick and efficient.

The problem, is that Render PDF Pages as Images seems to use some iffy maths when rendering out those images. If I open the PNGs in Photoshop, they show up as 215.11dpi, and more problematically, images that bleed across the book’s spine don’t match up perfectly - there’s some sort of cropping or scaling by ~1pixel going on.

I have an alternative InDesign script, which generates a multipage pdf, then feeds that a page at a time into Photoshop, which saves the pages out as PNG.

It creates perfect PNG images, the dpi reports as exactly what you set it to, the cross-spine bleeds match up, and the antialiasing quality is better… BUT it takes 12 seconds per page to process, so the whole book is a 50+ minute export.


tell application "Adobe InDesign CS5"
	activate
	if (count documents) is equal to 0 then
		display dialog "Please open a document" buttons " OK " default button 1 with icon caution
		return -128
	end if
	set myPageNumPref to page numbering of general preferences
	set page numbering of general preferences to absolute
	set myDocument to active document
	set myFileName to name of myDocument
	--strip the ext
	if myFileName ends with "indd" then
		set myFileName to (text 1 thru -6 of myFileName)
	end if
	--pages to convert and folder
	set NumberOfPage to pages per document of document preferences of myDocument
	set myFolder to (choose folder with prompt "Please select the folder you want to save your PNG pages in") as string
	
	--show dialog
	set myLabelWidth to 200
	set myDialog to make dialog with properties {name:"PNG Export"}
	tell myDialog
		tell (make dialog column)
			tell (make dialog row)
				make static text with properties {static label:"Resolution:"}
				set myResField to make real editbox with properties {edit contents:"300"}
			end tell
			tell (make dialog row)
				set myAACheckbox to make checkbox control with properties {static label:"Antialias", checked state:false}
			end tell
		end tell
	end tell
	
	set myResult to show myDialog
	if myResult = true then
		--+1 gets the correct name because list starts at 0
		set myRes to edit value of myResField as integer
		--set mySpreads to checked state of mySpreadsCheckbox
		set myAA to checked state of myAACheckbox
		--use pdfx4 for transparency
		set myPDFPreset to "SDL-PDF-Test"
	else
		return
	end if
	destroy myDialog
	
	tell myDocument
		set pcount to pages per document of document preferences
		set thePath to (myFolder & myFileName & ".pdf")
		tell application "Adobe InDesign CS5"
			set page range of PDF export preferences to all pages
			export myDocument format PDF type to thePath using PDF export preset myPDFPreset
		end tell
		tell application "Adobe Photoshop CS5"
			activate
			set display dialogs to never
			repeat with i from 1 to pcount
				open file thePath as PDF with options {class:PDF open options, mode:RGB, resolution:myRes, use antialias:myAA, page:i, crop page:crop box}
				tell current document
					set pngnum to i as string
					if (count of items in pngnum) is less than 2 then
						set pngnum to "0" & pngnum
					end if
					set pngPath to (myFolder & myFileName & "_" & pngnum & ".png")
					save in file pngPath as PNG with options {class:PNG save options, interlaced:false}
					close
				end tell
			end repeat
			set display dialogs to always
		end tell
	end tell
end tell

So the question comes down to: is there a way to do the Render PDF Pages as Images step with a better / more configurable image processing option, or failing that, can I adapt a section of the applescript above that’s driving Photoshop, to have Photoshop do the image processing in place of the Render PDF Pages as Images step?

If using photoshop to process the images takes longer, I can handle that, it’s the utility of being able to select individual (or arbitrary numbers of) PDFs and run them through the system that I want to preserve at a minimum.

Any thoughts or solutions would be appreciated.

Thanks.

A followup - I remembered Photoshop’s Image Processor script, and am able to use that to automate the conversion of PDF into TIFF, then can use Automator to create a folder action to convert the generated TIFFs into PNGs…

But Photoshop still takes 35 minutes to do that processing run.

I tried using Affinity Photo, but it can’t render the PDFs correctly (creates boxes around feathered effects).

I looked into SIPS, but it seems to have the same problem Render PDF Pages as Images and Preview display - for some reason, they appear to cut around 1/2 a pixel off each side of the image, so the images they produce are 1 pixel smaller in width and height, but it’s not just a scaling thing, cross-spine bleed graphics don’t match up, so it’s seemingly a cropping problem.

Replying again to my message, I spent the past couple of days installing ImageMagick and Ghostscript to see if I could make the commandline work for converting the files - after much futzing about, it was successful.

Unlike SPIS, ImageMagick/Ghostscript gets the math correct for rasterising the pdf - the left and right pages of the book match up perfectly in the middle.

Unfortunately, while Photoshop takes around 8-12 seconds per page to process the images, ImageMagick takes around 30seconds each.

It’s a shame SPIS / Automator / Preview’s rendering math is so broken, because they’re SO much faster.