Uncaught exception when saving to PDF via script

Adobe Community Professional ,
Dec 06, 2021 Dec 06, 2021

Copy link to clipboard

Copied

Hi All, I am having a problem programmatically saving a structured book to PDF with ExtendScript. I can run the code below repeatably on an unstructured book. But when I run it on my structured book, it runs fine the first time, but the second time it gives me an error and locks up FrameMaker.

Script Error : 
Error Message      : Uncaught exception 
Script, Line#   : C:\Users\rick\AppData\Roaming\Adobe\FrameMaker\15\WE-SaveActiveBookAsPdf.jsx,  22

I tried adding a try/catch block but it still fails without catching the error.

 

If you have a structured book and can test this on your machine, I would appreciate it. I am using FrameMaker 2019 15.8.979. Here is the code:

#target framemaker;

var book, name;

book = app.ActiveBook;
name = book.Name.replace (/[^\.]+$/, "pdf");

saveBookAsPdf (book, name);

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;

    FA_errno = 0;
    book.Save (name, params, returnParams);
	if (FA_errno !== 0) {
		PrintSaveStatus (returnParams);
	}
    return FA_errno;
}
TOPICS
Error , Scripting

Views

106

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
Enthusiast ,
Dec 06, 2021 Dec 06, 2021

Copy link to clipboard

Copied

Hi Rick,

with some litte improvements it works for me.

You also have to check, if all documents of the book can be opened.

I've just run it the third time.

#target framemaker;
#strict on
 "use strict";

var book, name;

book = app.ActiveBook;
name = book.Name.replace (/[^\.]+$/, "pdf");

    saveBookAsPdf (book, name);
 
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 = "Standard";// 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;
}

 

 

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
Enthusiast ,
Dec 06, 2021 Dec 06, 2021

Copy link to clipboard

Copied

Another hint:

You can use Constants.FS_PDFUseDistiller only for FM Versions > 14

 

 if (app.VersionMajor >14)
        {
        i = GetPropIndex (params, Constants.FS_PDFUseDistiller);
        params[i].propVal.ival = 0;
       }
    

 

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
Adobe Community Professional ,
Dec 06, 2021 Dec 06, 2021

Copy link to clipboard

Copied

I tried your code and I still get the error on the second run, even with all components open. There must be something with this book, although it happens with all books with this particular EDD applied. I will try stripping the book.

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
Enthusiast ,
Dec 06, 2021 Dec 06, 2021

Copy link to clipboard

Copied

I get another error in FrameMaker console:

"Password protected PDF functionality or API FS_PDFPassword has been deprecated."

But the script continues.

 

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
Adobe Community Professional ,
Dec 06, 2021 Dec 06, 2021

Copy link to clipboard

Copied

Are you running yours in 2019 or 2020?

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
Enthusiast ,
Dec 06, 2021 Dec 06, 2021

Copy link to clipboard

Copied

2020

I'll test it with 2019

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
Enthusiast ,
Dec 06, 2021 Dec 06, 2021

Copy link to clipboard

Copied

FrameMaker2019 doesn't respond on second try also. And it has a very high consume of internet bandwith all the time.

So your assumption about FM19 seems to be correct.

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
Adobe Community Professional ,
Dec 06, 2021 Dec 06, 2021

Copy link to clipboard

Copied

Thank you very much for confirming this for me Klaus. I appreciate your efforts.

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
Enthusiast ,
Dec 07, 2021 Dec 07, 2021

Copy link to clipboard

Copied

I did more tests today.
First I converted the script to jsxbin and called it from FrameMaker.
The book was a shortened version of the book for FrameMaker2020.
Result:
The first run was finished after about 10 minutes.
The second run took 15 minutes, but finished.
The file size of the shortened book was about 50 MB.
You just have to be very patient.

 

In FrameMaker2020 with the larger book it took only 7 minutes and the file size was 31 MB.

I hope these tests give you some hope.

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
Adobe Community Professional ,
Dec 07, 2021 Dec 07, 2021

Copy link to clipboard

Copied

LATEST

Thank you Klaus!

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
Adobe Community Professional ,
Dec 07, 2021 Dec 07, 2021

Copy link to clipboard

Copied

Rick, some years ago Jang posted a messaage concerning FA_errno:

  • FA_errno is read only, hence can not be set to 0 before a critical action which may give an error code.
  • Use a script such ass InitiateFA_erro () see hereafter.

 

...
findParams = GetFindParameters (2, null); // finding any variable, no wrap
InitFA_errno (); // reset - it is write protected
oTR = oDoc.Find(oTR.beg, findParams); // and do an initial find to get started.
while(FA_errno === Constants.FE_Success) {
  ...
  InitFA_errno ();
}

KLD_Z.InitFA_errno = function () { //====================================
/*            Reset FA_errno
Arguments     oDoc            Current document
              asNames         Array of xy-names
Returns       Function value is Modified constant
Called by     CollectVarsInDoc
Calling       -
Comment       FA_errno is write protected and hence can not be set to 0 programmatically
Usage         ...
              findParams = GetFindParameters (2, null);     // finding any variable, no wrap
              InitFA_errno ();                              // reset - it is write protected
              oTR = oDoc.Find(oTR.beg, findParams);         // and do an initial find to get started.
              while(FA_errno === Constants.FE_Success) {
                ...
Reference     https://forums.adobe.com/thread/962910
History       2020-12-29
*/
  app.GetNamedMenu("!MakerMainMenu");             //If this fails, you've got a bigger problem
  return;
} //--- end InitFA_errno ------------------------------------------

 

 

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