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

How can I add a custom stamp to multiple files?

Community Beginner ,
Jun 06, 2019 Jun 06, 2019

Copy link to clipboard

Copied

I am trying to batch add stamps to the bottom right corner of a large number of files. The stamp only needs to include the filename (minus the file extension) and one value to be entered by the user at the start of the action. I see documentation to add the standard stamp and in the position I want, but I can't seem to get the dynamic stamp name to insert that in a batch.

My ultimate goal is to add a small amount of white space to the bottom of the first page of each document, insert the stamp with the user info and filename, flatten the pdf, and scale the document back to 8.5" x 11". Is this something I'll be able to actually get to?

Thanks all!

TOPICS
Acrobat SDK and JavaScript

Views

3.8K

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 ,
Jun 06, 2019 Jun 06, 2019

Copy link to clipboard

Copied

The document file name is the "documentFileName" property of the document object.

In a stamp script the document object being stamped is in "event.source.source" property

So your stamp script could look like this:

event.value = event.source.source.documentFileName.replace(/\.pdf$/i,"");

I haven't tested this in a batch process, but it will work in a regular dynamic stamp. But it should also work when the stamp is applied inside a batch processing script.

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

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 Beginner ,
Jun 07, 2019 Jun 07, 2019

Copy link to clipboard

Copied

HI Thom, thanks for the reply!

So my actual issue is finding a way to call the custom stamp during the Adobe action process. I can't seem to get the stamp name for each individual file without first placing the stamp. I spent most of the day yesterday and decided maybe a FreeText annotation would work better than a dynamic stamp.

The issue I am running into now is once i add the space for the footer and FreeText annotation, how do i "burn in" the annotation and resize the page back to 8.5" x 11"  is that something that can be done through the script or do i have to manually print each file to the virtual PDF printer and choose the fit option? I am trying to automate this process as much as possible.

Thanks again!

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 ,
Jun 07, 2019 Jun 07, 2019

Copy link to clipboard

Copied

The stamp name never changes. Its always the same.  But a free text annot works great and it's easy if all you want is text. Stamps are better if any graphics are involved.

You can flatten the document after applying the text annots.

So Page resizing and scaling are two different things. Sizing is done with the "setPageBoxes" function. Scaling is a different animal all together and much more difficult. As you've suggested, printing to a file, i.e. refrying the PDF is one technique, and somewhat representative of the options available in JavaScript. If you were writing a plug-in, Then the actual page content could be scaled.

So down to business. Yes, the easiest way to scale a PDF page is to print the doc to a file. This also flattens all interactive content. This does not always work when printing to a PDF. But since you are specifically scaling the PDF it might work. If not, print to PostScript, then open the post script file to convert it back to PDF.  

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

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 Beginner ,
Jun 07, 2019 Jun 07, 2019

Copy link to clipboard

Copied

i'm trying to automate this task as much as possible. basically i want to put a larger freetext box on the first page in newly added white space at the bottom so that none of the content of the document is covered by the freetext, and page numbers on all of the rest of pages also in newly created white space at the bottom and then flatten and resize the whole thing back to 8.5 x 11 and flatten. Printing each file to PDF after the process completes each time I do this seems a bit cumbersome, but it sounds like scaling the pages down through a script is also a bit tedious. Can you point me in the right direction on that?

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 ,
Jun 07, 2019 Jun 07, 2019

Copy link to clipboard

Copied

Yes, scaling a PDF is cumbersome. The Acrobat JS model has no built-in features for this, so you have to find a creative way to get around it. And I already told you how to do it. Look in the Acrobat JS Reference for the PrintParams object.

Look at the example for the "fileName" property, here:

Acrobat DC SDK Documentation

There are a couple of other ways to scale PDF pages. Both requires creating a new document with exactly the same number of pages, but blank. Then you apply the content of the original to the new blank page as either a watermark or a button. Both of these mechanisms control the scaling.

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

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
Participant ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

Hello,

then did you find a way to insert a text with the file name in batch??

I'm also looking for it!

Kindly waiting for a reply, thanks!!

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 ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

This can be achieved using a script. Where do you want the text to be added, and what should it look like?

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 ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

Also, should it change if the file is renamed?

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
Participant ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

Hi, to be honest, I'd like to put a little text line with the save date full file path as a footnote (or headnote). I've been able to create a stamp to do it, but I'm not able to set up an action for doing it in batch. I'm opened to whatever solution 🙂

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 ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

What do you mean by "save date", exactly?

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
Participant ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

event.value = util.printd("dd-MM-yyyy HH:mm", new Date);

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 ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

So the current date and time, then? Plus the file-name?

You can do it using a field, like the code above, but then you'll need to duplicate that field to all fields in your code, apply this text as its default value, etc.

Another option is to use a watermark, with the addWatermarkFromText method.

For example, this command will add the file name and current date to all the pages in the file, in the footer:

 

 

this.addWatermarkFromText({
	cText: this.documentFileName + " -- " + util.printd("dd-mm-yyyy HH:MM", new Date()),
	nHorizAlign: app.constants.align.center,
	nVertAlign: app.constants.align.bottom,
	nVertValue: 16, nFontSize: 10
});

 

 

Edited: Some small mistakes in the code were fixed

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
Participant ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

can I run that JS using an action?

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 ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

Yes.

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
Participant ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

Could you kindly tell me how to get the file path instead of this.documentFileName ?

 

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 ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

this.path

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
Participant ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

I'm not able to change the font size, even if I edit nTextSize value...

(It's always 24pt)

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 ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

Sorry, my mistake. It should be "nFontSize", not "nTextSize". Set it to "24", without the quotes.

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 ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

(ah, you mean it's always 24 by default... you can set it to whatever number you want)

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
Participant ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

THIS IS IT!!

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
Participant ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

How is it the it increments the month every time I run it?

Today is September...

Schermata 2021-09-17 alle 08.15.04.png

 

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 ,
Sep 17, 2021 Sep 17, 2021

Copy link to clipboard

Copied

I didn't notice you used "MM". That's incorrect, as it stands for "Minutes". Use "mm", instead.

I will fix it in the code above.

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 ,
Sep 17, 2021 Sep 17, 2021

Copy link to clipboard

Copied

And of course, you need to change "HH:mm" to "HH:MM"...

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
Participant ,
Sep 19, 2021 Sep 19, 2021

Copy link to clipboard

Copied

🤦🏻‍:male_sign:

I was relying on this one:

https://docs.microsoft.com/en-us/dotnet/api/system.globalization.datetimeformatinfo.getalldatetimepa...

I guess it's for something very different.

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