Here is a script that works on a book, but you could modify it to work on a folder. Or, you could put all of the folder's FM files into a temporary book. I originally wrote it for a client, and thus the AC_SCP namespace.
#target framemaker
var AC_SCP = AC_SCP || {}; // Save each component to PDF.
AC_SCP.version = "Version 0.1b January 11, 2022";
AC_SCP.file = $.fileName;
AC_SCP.main = function (book) {
var doc;
if ((book) && (book.ObjectValid () === 1)) {
AC_SCP.processBook (book);
}
else {
book = app.ActiveBook;
if (book.ObjectValid () === 1) {
AC_SCP.processBook (book);
}
}
};
AC_SCP.saveDocAsPdf = function (doc, name) {
var params, returnParams, i;
if (!name) {
name = doc.Name.replace (/[^\.]+$/, "pdf");
}
params = GetSaveDefaultParams();
returnParams = new PropVals();
i = GetPropIndex (params, Constants.FS_FileType);
params[i].propVal.ival = Constants.FV_SaveFmtPdf;
i = GetPropIndex (params, Constants.FS_PDFUseDistiller);
params[i].propVal.ival = 0;
FA_errno = 0;
doc.Save (name, params, returnParams);
if (FA_errno !== 0) {
PrintSaveStatus (returnParams);
}
return FA_errno;
};
AC_SCP.processBook = function (book) {
var bookComp, file;
// Loop through all of the components in the book.
bookComp = book.FirstComponentInBook;
while (bookComp.ObjectValid ()) {
if (bookComp.ComponentType === 512) {
file = new File (bookComp.Name);
// Get the document returned in a JavaScript object.
doc = CP.getDocument (bookComp.Name, undefined, true);
if ((doc) && (doc.ObjectValid () === 1)) {
book.StatusLine = "Processing " + file.name;
AC_SCP.saveDocAsPdf (doc);
// If the document was opened by the script, close it.
if (doc.openedByScript === true) {
doc.Close (true);
}
}
}
bookComp = bookComp.NextBookComponentInDFSOrder;
}
// Reset the book status line.
book.StatusLine = "";
};
... View more