• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to catch a generated pdf doc at runtime? (javascript)

New Here ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

Hi,

i use Acrobat XI/Windows.- the methods used are app.trustedFunction.

 

The script generates a pdf doc through the Adobe PDF printer to be used subsequently in the same script, however, despite seeing how it has been stored in the local folder, at runtime app.openDoc () does not recognize it as [doc object]: JavaScript Debugger console returns "Invalid location. The file or folder does not exist".

 

The Adobe PDF printer settings allow you to display or not the printed pdf document. I have tried both ways. When it shows it, I try to select it with app.activeDocs, but it doesn't detect it either.

 

I am being forced to break into two action button scripts with user intervention (so the script works correctly), when I want the process to be completely silent and unattended.

 

I hope my question catches your attention.
Thank you.

TOPICS
Acrobat SDK and JavaScript

Views

650

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
Community Expert ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

What script does you use?

Votes

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
New Here ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

hi, Bernd_Alheit, Thanks for your interest

the work scheme is as follows: 

FORM-MODEL-BLANK.PDF --> FORM-FILLED.PDF --> FORM-FLATTED.PDF --->send email.

 

*****This is the function in mouse-up botton event*************

 

// script function process button in FORM-MODEL-BLANK.pdf (this)

function process()

{
var cpathform = "/D/TMAS/FILLINGFORMS/form-filled.pdf";
var cpathformflat = "/D/TMAS/FLATTENFORMS/form-flat.pdf";
var cTo = this.getField("email_To_TMAS");

myTrustedSaveAs(this, cpathform); //function <mySaveAs.js> in the application Javascripts folder

var pp = this.getPrintParams ();
pp.interactive = pp.constants.interactionLevel.silent;
pp.printerName = "Adobe PDF Converter TMAS";
pp.bUI = false;
pp.bSilent = true;

this.print(pp);

this.closeDoc();

//HERE is where the printed pdf document "form-flat.pdf" does not recognize
myTrustedOpenDoc(cpathformflat); //function < myOpenDoc.js > in the application Javascripts folder

// would wait for the return of the printed document as a [doc object] oDocx

/*send email:
oDocX.mailDoc({
bUI: true,
cTo: cTo.value,
cCC: "",
cSubject: " ",
cMsg: " "
});

oDocX.closeDoc();
*/
}

 

************Function <mySaveAs.js> in the application Javascripts folder

mySaveAs = app.trustPropagatorFunction(function(doc,path)

{

app.beginPriv();

doc.saveAs(path);

app.endPriv();

})

myTrustedSaveAs = app.trustedFunction(function(doc,path)

{

app.beginPriv();

mySaveAs(doc,path);

app.endPriv();

});

 

 

************Function <myOpenDoc.js> in the application Javascripts folder

myOpenDoc = app.trustPropagatorFunction(function(path)

{
try {
app.beginPriv();

app.openDoc({cPath: path});

app.endPriv();

} catch (e) {};
})

myTrustedOpenDoc = app.trustedFunction(function(path)

{
try {
app.beginPriv();

myOpenDoc(path);

app.endPriv();

} catch (e) {};
});

 

Thank you.

 

Votes

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
Community Expert ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

this.print() will start the print job in background

You must wait until the print job is finished.

 

Why does you print the document.

Votes

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
New Here ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

The print job is finished. In fact I can see how the PDF document was created.

I want to print the form to get a flat file and be able to send it by email. It is the most effective method that I have found: the doc.flattenpages method preserves the javaScript document-level and its size is very heavy.

Votes

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
LEGEND ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

You don't set oDocX anywhere. Doesn't seem likely it will work even if you do, to be fair. This is not expected or supposed to work.

Votes

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
New Here ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

Hi, Test_Screen_Name, thanks for your attention.

You may not have explained me clearly.

Actually I want to focus my question on the main question: the same script cannot retrieve a pdf document it has generated (Adobe PDF printer).

That is why I have cleared the code by assuming the non-problematic steps. Simplification includes variables, which are built from form fields.

In the header I already said that the code works correctly when I do it in two phases: 2 buttons, 2 scripts. I need 1 button, 1 script.

Now I include in it the lines of code and the function that involve oDocx:

 

// script function process button in FORM-MODEL-BLANK.pdf (this)

function process()

{
var cpathform = "/D/TMAS/FILLINGFORMS/form-filled.pdf";
var cpathformflat = "/D/TMAS/FLATTENFORMS/form-flat.pdf";
var cTo = this.getField("email_To_TMAS");

myTrustedSaveAs(this, cpathform); //function <mySaveAs.js> in the application Javascripts folder

var pp = this.getPrintParams ();
pp.interactive = pp.constants.interactionLevel.silent;
pp.printerName = "Adobe PDF Converter TMAS";
pp.bUI = false;
pp.bSilent = true;

this.print(pp);

//----->>> If done in two 2 scripts, this is the cut line (including the variables in the second script again) <<------

this.closeDoc();

//----->>> if done in 1 script, HERE is where the printed pdf "form-flat.pdf" is not recognized (openDoc):

myTrustedOpenDoc(cpathformflat); //function < myOpenDoc.js > in the application Javascripts folder

//Selection between active pdfs by file name to assign oDocx as [doc object]
var fnformflat = "form-flat.pdf"
myTrustedSelectXfileName(fnformflat); //funcion < mySelActiveDocXfileName.js > in the application Javascripts folder

//send email:
oDocX.mailDoc({
bUI: true,
cTo: cTo.value,
cCC: "",
cSubject: " ",
cMsg: " "
});

oDocX.closeDoc();

}
//************End Function*********************

//************Function <mySelActiveDocXfileName.js> in the application Javascripts folder

mySelActiveDocXfileName = app.trustPropagatorFunction(function(filename)

{
app.beginPriv();
var len = app.activeDocs.length;
for (var i=len-1; i>=0; i--) {
try{
oDocX = app.activeDocs[i];
var fn = oDocX.documentFileName;

if (fn !== filename) {
}
else {
break;
}
} catch (e){}
}
app.endPriv();
})

myTrustedSelectXfileName = app.trustedFunction(function(filename)
{
app.beginPriv();
mySelActiveDocXfileName(filename);
app.endPriv();
});
//************End Function*********************

 

Regards, 

Kasan

Votes

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
LEGEND ,
May 13, 2020 May 13, 2020

Copy link to clipboard

Copied

LATEST

I think your question was already answered, but you may not have welcomed the answer. "You must wait until the print job is finished." Since there is no "wait" function in JavaScript, you cannot write a script that will pick up a PDF that is not yet created.

Votes

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