Pages to PDF using Automator and JavaScript

preview_player
Показать описание
This is an example of using using OS X's Automator and JavaScript for Automation (in Yosemite) to convert Pages documents to PDF's en masse. The process is quite simple:

1. Add an Automator "Ask for Finder Items" action to get a list of files.
2. Add a "Run JavaScript" action with the following script to convert each Pages file to PDF (note that I don't actually double check that I receive a Pages document, that's an exercise for you).

Here's the JavaScript:

function convertToPDF(pages, input) {
var inFile = Path( input );

}

function run(input, parameters) {
var pages = Application("Pages")
var result = [];
var documentList = input instanceof Array ? input : [ input ];

for (var i in documentList) {
}

return result;
}
Рекомендации по теме
Комментарии
Автор

That worked and helped much. Thank you.

herrenschnitzel
Автор

Thanks. yo dont know how big of a help this is.

sombd
Автор

it worked for me just fine on El Capitan. Thank you James for the code!!

omarinspain
Автор

@Akash: You write DOCX just like you would PDF, just change 'PDF' to 'Microsoft Word', like so

function convertToDOCX(pages, input) {
var inFile = Path( input );
var outFile = Path( input.toString().replace(/\.[^\.]+$/, '.docx') );

var document = pages.open( inFile );

pages.export(document, {to: outFile, as: 'Microsoft Word'});
pages.close(document, {saving: 'no'});

return outFile.toString();
}

jamesmcininch
Автор

Hi and thanks for the script! Is there an option to set the quality of export like you do when using the export function within pages?

MarkusEhehalt
Автор

For El Capitan and Pages 5.6.1 it crashes on the line "pages.export(document, {to: outFile, as: 'PDF'});". Have an idea why? Thank you!!!

hugomontesskertchlylc
Автор

Is there a way to convert the pages document to a PDF without having to open and close the pages file?

billiehaas
visit shbcf.ru