Batch convert Pages files to PDF
I'm trying to convert a LOT of Pages files to pdf so I can create an index. I've found scripts from VikingOSX, but they are for older versions. I'm using Pages 13 on Ventura. Can anyone help?
MacBook Air, macOS 13.5
I'm trying to convert a LOT of Pages files to pdf so I can create an index. I've found scripts from VikingOSX, but they are for older versions. I'm using Pages 13 on Ventura. Can anyone help?
MacBook Air, macOS 13.5
The Automator application solution that is posted here was tested with Pages v13.2 and the newly released v14.0, both with macOS Sonoma 14.4.1, and Ventura 13.6.6. Once the application is saved to your Desktop, you double-click to run it, and it will prompt you for the folder containing your Pages documents. It will only process ".pages" documents and will write the exported PDF of the same name back to that folder. It will pop a dialog indicating when it is complete.
Automator solutions are a cascade of purposeful actions that pass the output of one action on to the next.
Click on the Desktop to get Finder focus and then press shift+command+A to open the Applications folder. Automator will be the robot icon near the top of the list of applications. Double-click Automator to open it.
A file chooser will appear on which you select New Document, then Application, then click the Choose button. This will expose a Library column, an action column associated with the selected Library, and large Workflow window where one drags and drops, then configures each Library action.
In the following list, drag and drop each action below each other in the Workflow window:
JavaScript (Select the default content in the existing Run JavaScript action and remove it. Then, copy/paste the following content just below here into the Run JavaScript action and click the associated hammer icon)
function convertToPDF(pages, infx) {
var inFile = Path(infx);
var outFile = Path(inFile.toString().replace(/\.[^\.]+$/,'.pdf'));
var document = pages.open(inFile);
pages.export(document, {to: outFile, as: 'PDF'});
pages.close(document, {saving: 'no'});
return outFile.toString();
}
function run(input, parameters) {
var pages = Application("Pages");
pages.includeStandardAdditions = true;
var result = [];
var documentList = input instanceof Array ? input : [ input ];
for (var i in documentList) {
result.push(convertToPDF(pages, documentList[i]));
}
return result.pop;
}
AppleScript (Select the default content in the Run AppleScript window and backspace to remove. Then copy/paste the following content into the Run AppleScript action window. Click the hammer icon.)
use scripting additions
on run {input, parameters}
-- reveal hidden extensions on the exported PDFs
tell application "Finder"
activate
set PDFList to (every item of folder (item 2 of input) whose kind contains "PDF") as alias list
if PDFList = {} then return
repeat with apdf in PDFList
set extension hidden of apdf to false
end repeat
end tell
display dialog "Processing Complete." with title "Pages to PDF Export"
return
end run
Now, save the Automator application to your Desktop with a meaningful name (e.g. Pages2PDF) and quit Automator.
It is customary for Pages to open each document momentarily while exporting to PDF. There is no means to conceal this visual behavior.
The Automator application solution that is posted here was tested with Pages v13.2 and the newly released v14.0, both with macOS Sonoma 14.4.1, and Ventura 13.6.6. Once the application is saved to your Desktop, you double-click to run it, and it will prompt you for the folder containing your Pages documents. It will only process ".pages" documents and will write the exported PDF of the same name back to that folder. It will pop a dialog indicating when it is complete.
Automator solutions are a cascade of purposeful actions that pass the output of one action on to the next.
Click on the Desktop to get Finder focus and then press shift+command+A to open the Applications folder. Automator will be the robot icon near the top of the list of applications. Double-click Automator to open it.
A file chooser will appear on which you select New Document, then Application, then click the Choose button. This will expose a Library column, an action column associated with the selected Library, and large Workflow window where one drags and drops, then configures each Library action.
In the following list, drag and drop each action below each other in the Workflow window:
JavaScript (Select the default content in the existing Run JavaScript action and remove it. Then, copy/paste the following content just below here into the Run JavaScript action and click the associated hammer icon)
function convertToPDF(pages, infx) {
var inFile = Path(infx);
var outFile = Path(inFile.toString().replace(/\.[^\.]+$/,'.pdf'));
var document = pages.open(inFile);
pages.export(document, {to: outFile, as: 'PDF'});
pages.close(document, {saving: 'no'});
return outFile.toString();
}
function run(input, parameters) {
var pages = Application("Pages");
pages.includeStandardAdditions = true;
var result = [];
var documentList = input instanceof Array ? input : [ input ];
for (var i in documentList) {
result.push(convertToPDF(pages, documentList[i]));
}
return result.pop;
}
AppleScript (Select the default content in the Run AppleScript window and backspace to remove. Then copy/paste the following content into the Run AppleScript action window. Click the hammer icon.)
use scripting additions
on run {input, parameters}
-- reveal hidden extensions on the exported PDFs
tell application "Finder"
activate
set PDFList to (every item of folder (item 2 of input) whose kind contains "PDF") as alias list
if PDFList = {} then return
repeat with apdf in PDFList
set extension hidden of apdf to false
end repeat
end tell
display dialog "Processing Complete." with title "Pages to PDF Export"
return
end run
Now, save the Automator application to your Desktop with a meaningful name (e.g. Pages2PDF) and quit Automator.
It is customary for Pages to open each document momentarily while exporting to PDF. There is no means to conceal this visual behavior.
A self-created index of some sort, as Pages itself provides no means of indexing in the MS Word sense?
Are your (LOT) of Pages documents in one folder, or scattered about? Do you want the exported PDF to bear the original document's name and be written to the same location, or a different location?
The code is already written and may need to be finessed per the second paragraph requirement(s).
WilmaP wrote:
Thanks for your quick attention. All the Pages files are in one folder, and the exported PDFs will be in the same location with the same names.
Well, that simplifies things. Hope to have something for you here by this afternoon with instructions. Need time to tweak and test with Pages v13.2 on both Sonoma (my daily driver) and Ventura.
Since posts are restricted to content amount here, here is some additional relevant info. When you first run the above Automator application, you will see a couple of dialogs that you need to click OK (whatever you do, don't click Cancel) in order for current and subsequent processing to complete normally. You application name will replace the "JXA_PagesToPDF" string.
And that the entire Automator application looks like when complete.
Thank you, thank you, thank you! You're amazing! This worked perfectly and converted over 350 files in just a few minutes. I really appreciate your help - and an added perk is that now I've discovered Automator and can play with it.
You are welcome. Glad you could follow the instructions… 😎
Apple will eventually phase out Automator for Apple Shortcuts workflows that are available on macOS Monterey and later. The macOS Shortcuts application can even convert some Automator workflows to Shortcuts.
Automator User Guide for Mac - Apple Support
Shortcuts User Guide for Mac - Apple Support
Thanks for your quick attention. All the Pages files are in one folder, and the exported PDFs will be in the same location with the same names.
Batch convert Pages files to PDF