there’s quite a farcical discussion going on over at the InDesign forum — Is there really no way to export PDFs as separate pages? as is so often the case in these forums, a person asks HOW to do something and then there’s an extended, often heated, discussion about WHY you would/wouldn’t or should/shouldn’t do it that way.
but the argy-bargy is unnecessary because there are some truly legitimate workflows that would benefit from this capability — like the guy at comment 39 — and because exporting each InDesign page as a separate PDF is really easy with Applescript.
today we’ll be looking at a simplified version of the script from lessons 11 and 12. we start by collecting the filename and file path of the active document. then we shorten the filename to exclude the extension — so “this file.indd” becomes “this file” (mgShortName):
tell application id "com.adobe.InDesign" set mgFolder to file path of active document set mgName to name of active document set text item delimiters of AppleScript to {"."} set mgShortName to text item 1 of mgName set text item delimiters of AppleScript to "" end tell
next we’ll create a subfolder for the pdfs to be saved into. you do this through the finder by first checking if the subfolder already exists and, if not, creating it. we’re calling this subfolder “the pdfs” and it will be created in the same folder as the indesign file :
tell application "Finder" if (exists folder "the pdfs" of folder mgFolder) is false then make folder at mgFolder with properties {name:"the pdfs"} end if end tell
then it’s just a matter of a simple repeat loop, cycling through each page in the document. we’re using the page number (name of page) as part of the filename so, using the example above, we’ll end up with “this file_1.pdf”, “this file_2.pdf”, etc. and we complete the script with a simple dialog to let us know when it has done its thing :
tell application id "com.adobe.InDesign" repeat with x from 1 to count pages of active document set mgPageName to name of page x of active document set page range of PDF export preferences to mgPageName set mgFilePath to mgFolder & "the pdfs:" & mgShortName & "_" & mgPageName & ".pdf" as string tell active document export format PDF type to mgFilePath using "macgrunt offset" without showing options end tell end repeat display dialog "ALL DONE!" buttons {"OK"} default button 1 giving up after 2 end tell
notice that when we specify mgFilepath we add a colon to “the pdfs” — this is what designates it as a folder. the full file path might be something like this “Macintosh HD:Users:macgrunt:Documents:the pdfs:this file_1.pdf” — this shows a hierarchy of five folders — everything after that last colon is the name of the file. so, if we didn’t add the colon after “the pdfs” the filename would have been “the pdfsthis file_1.pdf” (hopefully that makes sense).
note also that “macgrunt offset” is the name of the PDF export preset — you would need to substitute your own preset name here.
so that’s the basic functionality for exporting every page as a separate PDF. copy those three sections into a single script in applescript editor and you’re away. there are a bunch of macgrunt lessons showing other PDF export workflows and considerations — just enter “export pdf” up there in the search field.
the next lesson will look at a couple of other, more complex, ways we could approach the naming of these separate page PDFs.
until then, keep grunting.