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

Posted on Apr 1, 2024 6:50 PM

Reply
Question marked as Top-ranking reply

Posted on Apr 2, 2024 12:01 PM

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:


  1. Files & Folders : Ask for Finder Items action
    1. Leave Start At: Desktop as is
    2. Set Type to Folders , do not check Allow multiple Selection
  2. Utilities : Set Value of Variable
    1. Leave it set to Storage default
  3. Files & Folders : Get Folder Contents
  4. Files & Folders : Filter Finder Items
    1. [ All ] of the following are true
    2. [ File extension ] [ contains ] pages
  5. Utilities : Run JavaScript (source code for this action below marked as JavaScript)
  6. Utilities : Get Value of Variable (Storage)
  7. Utilities : Run AppleScript (source code for this action below marked as AppleScript)


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.

7 replies
Question marked as Top-ranking reply

Apr 2, 2024 12:01 PM in response to WilmaP

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:


  1. Files & Folders : Ask for Finder Items action
    1. Leave Start At: Desktop as is
    2. Set Type to Folders , do not check Allow multiple Selection
  2. Utilities : Set Value of Variable
    1. Leave it set to Storage default
  3. Files & Folders : Get Folder Contents
  4. Files & Folders : Filter Finder Items
    1. [ All ] of the following are true
    2. [ File extension ] [ contains ] pages
  5. Utilities : Run JavaScript (source code for this action below marked as JavaScript)
  6. Utilities : Get Value of Variable (Storage)
  7. Utilities : Run AppleScript (source code for this action below marked as AppleScript)


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.

Apr 2, 2024 5:29 AM in response to WilmaP

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).



Apr 2, 2024 6:40 AM in response to WilmaP

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.

Apr 2, 2024 12:11 PM in response to VikingOSX

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.


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Batch convert Pages files to PDF

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.