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

Stamps

New Here ,
May 19, 2017 May 19, 2017

Copy link to clipboard

Copied

Hello,

I read a lot on internet.
Who can help me or put me in the right direction.

I use Adobe Acrobat DC pro.
I've created a stamp. When a user put this stamp on a document the 'stamp' ask for some questions :

The user has to fill in the question. One question is the filename.
So I want that when the user has filled in the questions that document with stamp will be saved in a folder and filename the user has filled in.
I read a lot about mySaveAs and Adobe LiveCycle and buttons and Folder Level Scripts but it don't work.

How can I give the information filled in by the user in the stamp to the Folder Level Script so the document will be saved with the filename the user has filled in ?

And also for the folder. The folder : "/c/ " and then the company name the user has filled in.

Thanks and regards.

TOPICS
Acrobat SDK and JavaScript

Views

1.9K

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
Community Expert ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

This can be done, but it requires developing a custom-made script, as well as installing a script on the local machine.

Also, the folders will have to exist in advance. A script can't create a new folder, nor can it save a file to the root C:\ folder, as that is not considered a safe path.

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
New Here ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

Thx for the info.

Can you give me the code for the custom-made script as well as the script on the local machine ?

I used this script, I found on internet, but doesn't work.

1) This scripts save as file : mySaveAs.js

2) Your button code on the "calculate" button.

Can you help me ?

Your folder level function:

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

app.beginPriv();

doc.saveAs(path);

app.endPriv();

})

myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path) {

// Privileged and/or non-privileged code above

app.beginPriv();

mySaveAs(doc,path);

app.endPriv();

// Privileged and/or non-privileged code below

});

Your button code:

// build file name

var myFileName = doc.getField("LastName").value + doc.getField("FirstName").value + ".pdf";

// add folder name

myFileName = "/c/temp/" + myFileName

myTrustedSpecialTaskFunc(this, myFileName);

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
Community Expert ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

Your code is pretty much there, I think, but to access the parent document from a calculation script in a stamp you need to use event.source.source, not "doc" or "this".

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
New Here ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

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
New Here ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

So. I've a PDF document.

I open the PDF stamp.

Put the stamp on the document and will save this document with the stamp on it.
The stamp ask for "Filename". The user fill in a name. In the future I also want to ask for foldername.
So I'll that the document with the stamp will be saved under that name.

Stamp has name 'Filename' :

Code under Filename button under calculate :

var cAsk = "Give Filename";

var cTitle = "Filename";

if( event.source.forReal &&

(event.source.stampName == "#Filename")){

var cMsg = app.response(cAsk, cTitle);

event.value = cMsg;

event.source.source.info.DocumentState = cMsg;

var myFileName = event.source.source.Filename + ".pdf";

myFileName = "/c/temp/" + myFileName

myTrustedSpecialTaskFunc(event.source.source, myFileName);

}

So what's wrong in the code ?

It save a file in de c:/temp dir with the name undefined.pdf and the stamp is NOT visible.

Thx

If I understand you correctly I don't need the myTrustedSpecialTaskFunc script ?

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
Community Expert ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

The trusted function is needed to save, but the "app.trustedPropagatorFunction" is not necesary. That's all I as saying.

Now, to get a clearer idea of what is happening in your current script, and in the future, please open the console window and see if any errors are reported.

Let me know what you see and we'll go from there.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

Hello,

No errors in the console.

I open the console. Put the stamp. Fill in the name and that's it.

No error in the console and in the c:/temp/undefined.pdf file.

So can you help me with this info.

I changed the line myTrustedSpecialTaskFunc(event.source.source, myFileName);

into mySaveAs(event.source.source, myFileName);

And I changed the script.

Folder mySaveAs script : C:\Program Files\Adobe\Acrobat DC\Acrobat\Javascripts

PDF open = Adobe Acrobat DC Pro

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
Community Expert ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

Ok, so if the "undefined.pdf" file did not exist before you placed the stamp, then you have shown that you can in fact save a PDF from a stamp script. This is very interesting because it shouldn't happen. But you have also proved my first point.

Now please refer to my previous post:

A stamp script, i.e., the code in the calculate script on a field on the stamp is very limited. It is run before the stamp is applied to the document.  In order to save the file after the stamp has been applied requires a code to be run after the dynamic stamp has already finished running.

The reason the stamp is not in this saved file is because the stamp does not exists when the stamp script is run.  The save has to happen after the script is finished running. Hence the conundrum. 

The solution is to create an automation script that places the stamp on the PDF, then saves the file after the stamp is on the PDF.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

I'm not an expert but I put the save command at the end of the calculate script.
I added app.alert and I checked the folder when the file is generated.
I put the stamp and filled in the name.
Then an app.alert. The file is not generated.
When I push ok the file is generated without the stamp.

Do I write a code ?
Can you help me with that ?
I think I almost there.So a little push to the solution 🙂

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
Community Expert ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

The test you described is an excellent demonstration of how the stamp is applied to the document after the stamp calculate script is finished running. In fact, in your example the app.alert box prevents the script from finishing, thus ensuring that the file will be saved without the stamp on it.

Again the solution is to write an automation script that applies the stamp and then saves the document. Basically you need to extend the folder level script with a menu item or toolbar button to perform these two steps. I would suggest searching the internet for "how to make an Acrobat menu item", "Acrobat Automation Script" and "Automate PDF Stamp", "Apply PDF stamp with script", that sort of thing.

We can certainly help with the next step.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

OK. I've already a menu script that saves the file with stamp in de folder.

But I want to create a stamp (that ask for some question like filename, department, ...) and then, with a push on a button (or something like that) that saves the document with the name the user filled in the right folder.

I thought I read that on the internet that's also possible and handy for the customer.

Otherwise they have to go to the menu .....

I'll search on the internet for a script and keep you informed.

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
Community Expert ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

The best thing to do is to ask all the questions in the menu script. Place the collected values into something that is accessible to the stamp script, then place the stamp. The stamp script then pulls the values from the common storage location. A good candidate for this storage is the document "info" object on the PDF being stamped.  By default, the current document will be "this" when the menu item is selected. 

For example:

// In the menu script

this.info.myValue = app.response(cAsk, cTitle);

// in the a field calculation Script on the stamp

event.value = event.source.source.info.myValue;

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

Sorry Thom but know you lost me 😞

What you mean I don't understand !!

What I've right now is :

- The user opens a PDF document

- Goes to stamp

- Choose the 'filename' stamp

- Put that stamp somewhere the document

- Fill in some information

- Then goes to menu : File - Save the Filename doc (a menu item I created with MenuItem.js)

   But I've problems to put the value off some files to save that document (I didn't have the code to put the value from field Filename to     save the document with. You helped me to save the document with that name but without the stamp.)

- User go to File - Save Filename

- User filled again the filename

- Document with stamp is saved under the name the user filled in

But the has to fill in twice the filename.

My idea was to create a stamp that ask for the information. A "save" button on the stamp that save the document with stamp.

But that seems to be very difficult.

And now you telling me to use te menu script to ask for the information and to fill in the stamp ???

Sorry but that I don't understand.

Hopefully you'll still help me.

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
Community Expert ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

Your current strategy has two steps.

1. apply the stamp with the regular stamp tool

2. use menu driven automation script to save file

Let's stick with that for now. Forget what I said about putting it all in one script.

You want the file information to be collected in one location, and then used for both the stamp and the save script.

To do this,

   1. collect the information in the stamp script.

   2. save it to a common location, such as the document info.

   3. the save script then uses this info to rename the document.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

if I understand correctly :

   1. collect the information in the stamp script.

          That I do already under the calculate tab.

           Let's say I ask for the value of Filename and Department

                  

                         var cAsk = "Give Department";

                         var cTitle = "Department";

                         if( event.source.forReal &&

                         (event.source.stampName == "#Filename")){

                         var Department = app.response(cAsk, cTitle);

                         event.value = Department

                         event.source.source.info.DocumentState = Department;

  2. save it to a common location, such as the document info.

               How can I do that ?

   3. the save script then uses this info to rename the document.

                This code under a "save" button. This mean you fill all information and then you push on the "save" button and the document with stamp will be saved under filename and department

                var Filenaam = cMsg;

                var myFileName = Filenaam + ".pdf";

                myFileName = "/c/temp/" + myFileName

                mySaveAs(event.source.source, myFileName);

Is this correct ?

Thanks             

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
Community Expert ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

                       event.value = Department

                         event.source.source.info.DocumentState = Department;

  2. save it to a common location, such as the document info.

               How can I do that ?

Look at the line of code immediately above "2. save it to..."

This code creates a new entry in the document info called "DocumentState".  This new document info entry is accessed in the menu save script as "this.info.DocumentSate". Just as I showed in my previous post. You might want to go back and re-read what I've written.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
May 30, 2017 May 30, 2017

Copy link to clipboard

Copied

Hello,

Sorry but I can't figured out.

This is what I do now ?

Put the stamp on the document.

Stamp ask for some questions. One of the questions is "Give supplier" ?

(Because I want to save the document with stamp in the 'supplier' folder'.

This is the code in the Custom calculation script for field 'Supplier' :

var cAsk = "Supplier";

var cTitle = "Supplier";

if( event.source.forReal &&

(event.source.stampName == "#stamp")){

var Supplier = app.response(cAsk, cTitle);

     event.value = Supplier;

     event.source.source.info.DocumentState = Supplier;

}

Then I do File - 'Save mystamp' in the menu (created by MenuItem.js)

app.addMenuItem({

cName: "Save mystamp",

cParent: "File",

cExec: "mySaveProc();",

cEnable: "event.rc = (event.target != null);",

nPos: 7   

});

In the mySaveProc file:

var mySaveProc= app.trustedFunction(function(myDoc, myPath)

{

var myPath = "/c/" + Supplier + "/test.pdf";

     app.beginPriv();

    var myDoc = event.target; 

     myDoc.saveAs(myPath);

     app.endPriv();

return myDoc; 

});

But this doesn't work.
What is wrong in the code ?

How do I get the value of the 'Supplier' field to the mySaveProc file ?

So the document with stamp will be saved in the supplier folder.

Thanks.

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
Community Expert ,
May 30, 2017 May 30, 2017

Copy link to clipboard

Copied

You are very close, but your code has a couple of problematic spots.

1. In the code that creates the menu item =>  cExec: "mySaveProc();",

the function mySaveProc is called with no parameters, yet it has 2 inputs,  This is not an error, just neatness, get rid of the two inputs.

2. In the "mySaveProc" function the "Supplier" parameter is undefined.  What you want to use is the storage location for "Supplier", like this:

var mySaveProc= app.trustedFunction(function(myDoc, myPath)

{

     app.beginPriv();

    var myDoc = event.target;

    var myPath = "/c/" + myDoc.info.DocumentState + "/test.pdf";

     myDoc.saveAs(myPath);

     app.endPriv();

});

It also does not need to return a value.

This will work, but if you have issues, report back and I'll show you how to do some debug

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
May 30, 2017 May 30, 2017

Copy link to clipboard

Copied

Hello Thom,

I'm a little bit confused about question 1.

cExec: "mySaveProc();",   has no parameters. But in the mySaveProc I've two parameters myDoc and myPath.

But in the example you adapted I see stil myDoc and myPath ??

var mySaveProc= app.trustedFunction(function(myDoc, myPath)

So do I've to add these two parameters in the cExec: "mySaveProc();",  or do I've to delete in the mySavedoc.js script ?

a : cExec: "mySaveProc(myDoc, myPath);", 

b : var mySaveProc= app.trustedFunction(function()

Witch one is the correct one ?

Then the second question is myDoc.info.DocumentState

How does the script knows that it is the supplier field ?

Because I want to put several values to the mySaveProc script from the stamp to save the  file.

The supplier for the folder. And the filename to save the file. I think 5 field values from the stamp I want to put in the mySaveProc script to save the file.

Thanks for you answers and patience.

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
New Here ,
May 30, 2017 May 30, 2017

Copy link to clipboard

Copied

I test a lot and the Supplier value = undefined.

I added in the mySaveProc script :

var supplier = myDoc.info.DocumentState.Supplier;

app.alert(supplier);

The value is undefined.

When I do :

var supplier = myDoc.info.DocumentState;

app.alert(supplier);

The value is 'null'.

What do I wrong ?

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
Community Expert ,
May 30, 2017 May 30, 2017

Copy link to clipboard

Copied

First, My Bad.  I just copied your code for the "mySaveProc" and forgot to remove the inputs Here is the revised code

var mySaveProc= app.trustedFunction(function()

{

     app.beginPriv();

    var myDoc = event.target;

    var myPath = "/c/" + myDoc.info.DocumentState + "/test.pdf";

     myDoc.saveAs(myPath);

     app.endPriv();

});

Now, about the "Supplier" value.  In the stamp script you have this line:

   event.source.source.info.DocumentState = Supplier;

This code places the "Supplier" data value into "doc.info.DocumentState"

where "doc" is a pointer to the document object in question. In this case the document being stamped. 

Check on it. Open the Document Properties window and click on the custom tab. You'll see the value there.

"myDoc.info.DocumentState.Supplier" is not a thing. It does not exists, because the code only sets "myDoc.info.DocumentState". Go with the code for "mySaveProc" as I've written it above.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
May 30, 2017 May 30, 2017

Copy link to clipboard

Copied

Perfect. Perfect.  Thanks a lot

I have a file with stamp in the supplier folder.

But, hopefully :-), my last question.

I want also save the document with invoice number and company name and ....
I think I ask 5 questions in the stamp and I want to use all 5 values in the mySaveProc script.

How can I do that ?

Do I user for each field another command.
Example for company :

event.source.source.info.DocumentState1 = Supplier;

And

var myPath = "/c/" + myDoc.info.DocumentState1 + "/test.pdf";

I'll test it meanwhile.

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
New Here ,
May 30, 2017 May 30, 2017

Copy link to clipboard

Copied

When I use in the stamp the command (as test with 1)

event.source.source.info.DocumentState1 = Supplier;

And

var myPath = "/c/" + myDoc.info.DocumentState1 + "/test.pdf";

Then it works.

So, I think that's the solution.

If you've a better alternative then let me know ?

But I want to thank you for your help en patience.

But keep this post in mind want I'm going to finalize the stamp and maybe more questions

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
New Here ,
May 30, 2017 May 30, 2017

Copy link to clipboard

Copied

Here I'm with a quick question :

I've a dropdown question with 3 options.

When the user don't choose a option and press on OK button than one, standaard option, (= blanco line) must be displayed.

Three options B, 3 and 6. So, when the user press OK then a blanco line must be displayed but now it displayed B.
I added a 4 option, blanco line, but he want display the blanco line. Always displayed B.

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