Save multiple books as single PDF with ExtendScript

New Here ,
Jan 11, 2022 Jan 11, 2022

Copy link to clipboard

Copied

Hi everyone,
being a newbie in terms of scripting, I can't figure out how to change some scripts I found in this group in order to get help with a repetitive task – maybe someone can help.

I often need to implement small changes in translated manuals in several languages and then save the books as single PDF (one for each language), but need also to bypass occasional error messages if single files are saved in a former Frame version.

I created a book containing the single books (book in a book) for all languages and tried to use this script, but I didn't find the way to open files 'no questions' and the end result is a single PDF with all subordinate books together.

Thanks in advance for any help.

 

 

––––––––––––––––––––––––––––––––––––––––––––

#target framemaker;
#strict on
 "use strict";
 
var doc;
doc = app.ActiveDoc;
 
    openBookFiles(book); 
 
saveDoc (doc);
doc.Close (true);
 
 
function openBookFiles(book) {
    var doc, component, compName;
    var openParams, openReturnParams;
    
    openParams = getOpenPrefs ();
    openReturnParams =  new PropVals();
 
    component =book.FirstComponentInBook;
    while(component.ObjectValid() ){     
        compName = component.Name;
        doc = Open(compName, openParams, openReturnParams);
        component =  component.NextComponentInBook;
    }    
}
 
 
function saveDoc (doc) {
    
    var params, returnParams, i;
    
    params = GetSaveDefaultParams ();
    returnParams = new PropVals ();
 
    i = GetPropIndex (params, Constants.FS_FileType);
    params[i].propVal.ival = Constants.FV_SaveFmtBinary150;
    i = GetPropIndex (params, Constants.FS_AutoBackupOnSave);
    params[i].propVal.ival = Constants.FV_SaveNoAutoBackup;
    i = GetPropIndex (params, Constants.FS_FileIsInUse);
    params[i].propVal.ival = Constants.FV_ResetLockAndContinue;
 
FA_errno = 0;
    doc.Save (doc.Name, params, returnParams);
    if (FA_errno !== 0) {
PrintSaveStatus (returnParams);
}
}
 
var book, name;
 
book = app.ActiveBook;
name = book.Name.replace (/[^\.]+$/, "pdf");
 
    saveBookAsPdf (book, name);
 
 
function getOpenPrefs() {
    var params, i;
   
    params = GetOpenDefaultParams();
    
    i = GetPropIndex(params, Constants.FS_RefFileNotFound);
    params[i].propVal.ival = Constants.FV_AllowAllRefFilesUnFindable;        
    i = GetPropIndex(params, Constants.FS_FileIsOldVersion);
    params[i].propVal.ival = Constants.FV_DoOK;
    i = GetPropIndex(params, Constants.FS_FontChangedMetric);
    params[i].propVal.ival = Constants.FV_DoOK;   
    i = GetPropIndex(params, Constants.FS_FontNotFoundInCatalog);
    params[i].propVal.ival = Constants.FV_DoOK;    
    i = GetPropIndex(params, Constants.FS_FontNotFoundInDoc);
    params[i].propVal.ival = Constants.FV_DoOK;    
    i = GetPropIndex(params, Constants.FS_LockCantBeReset);
    params[i].propVal.ival = Constants.FV_DoOK;        
    i = GetPropIndex(params, Constants.FS_FileIsInUse);
    params[i].propVal.ival = Constants.FV_OpenViewOnly;      
    return (params);
}
 
function saveBookAsPdf (book, name) {
    
    var params, returnParams, i;
    
    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;
    
    i = GetPropIndex(params, Constants.FS_FileIsInUse);  
    params[i].propVal.ival = Constants.FV_ResetLockAndContinue;     
 
    book.PDFJobOption = "PDFX3 2002";// NEW
    
   // FA_errno = 0;     // this is readonly and throws an error if #strict is on
    book.Save (name, params, returnParams);
 
    
if (FA_errno !== 0) {
PrintSaveStatus (returnParams);
}
    return FA_errno;
}

 

Views

53

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation