Get page number of dynamic stamp (not of page stamp is being applied to)

New Here ,
Jun 15, 2022 Jun 15, 2022

Copy link to clipboard

Copied

Hi, all,

 

  I'm wondering if it is possible, within the javaScript of a dynamic stamp, to get the page number of that particular stamp within the Dynamic stamp file.

 

  event.source appears to only have 3 properties (forReal, stampName, and source), based on the output of Object.getOwnPropertyNames.

 

  What I'm trying to accomplish: I have a dynamic stamp with some fields filled in via custom dialog. I'd like to be able to add extra fields to the side of the stamp for additional, optional text. If that optional text isn't used, the stamp would resize itself to crop off those extra fields (so that it doesn't end up covering any extra space on the target page). I'd like the js within the stamp to be able to get the page number for the call to setPageBoxes, as opposed to me having to specify it explicitly, in case I pass the file around and someone decides to remove one of the other stamps in the file.

 

  I know of 2 workarounds for the issue if I can't get that page number, but am curious if it's possible.

 

Thanks!

TOPICS
Acrobat SDK and JavaScript

Views

138

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

correct answers 1 Correct answer

Adobe Community Professional , Jun 16, 2022 Jun 16, 2022
I think you misunderstood. They are referring to the page in the stamp file, not the target file. In that case, the answer is yes, I believe. If you have a field with a calculation script you can access the page number it's on via event.target.page . I'm not sure that cropping the stamp's page while it's being applied is going to work, though. My guess is it won't.

Likes

Translate

Translate
Enthusiast ,
Jun 15, 2022 Jun 15, 2022

Copy link to clipboard

Copied

Hi,

To get the number of page of the source document, use this script:

 

event.value=event.source.source.numPages;

 

I never used "event.source" with the setPageBoxes method, so I don't know if that works.

Let me know after testing...

@+

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 ,
Jun 16, 2022 Jun 16, 2022

Copy link to clipboard

Copied

I think you misunderstood. They are referring to the page in the stamp file, not the target file.

In that case, the answer is yes, I believe. If you have a field with a calculation script you can access the page number it's on via event.target.page . I'm not sure that cropping the stamp's page while it's being applied is going to work, though. My guess is it won't.

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 ,
Jun 16, 2022 Jun 16, 2022

Copy link to clipboard

Copied

Thank you, event.target.page does indeed give me what I want.

 

I'm not overly familiar with javascript, so Object.getOwnPropertyNames not showing that as an option threw 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
Adobe Community Professional ,
Jun 17, 2022 Jun 17, 2022

Copy link to clipboard

Copied

LATEST

If you want to know the properties of an Acobat JavaScript object, then the Acrobat JavaScript Reference is the place to start. 

 

But, the size stamp file page does not need to be changed to change the size of the stamp. The natural size of the stamp is the BBox of the stamp file page. 

 

https://www.pdfscripting.com/public/PDF-Page-Coordinates.cfm

 

To change the BBox, all that is needed is to rearrange the fields. With the caveat that there isn't any other page content in the way. It would be much easier to simply hide/show and move extra fields in/out of side of the stamp.

 

I think this operation is also much safer than resizing pages, which can have strange affects in normal operation, and stamp scripts operate in an odd execution space. Best to stick with manipulating fields alone. 

 

 

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
Enthusiast ,
Jun 16, 2022 Jun 16, 2022

Copy link to clipboard

Copied

Sorry for my misunderstanding! My English is not fluent especially since I don't practice anymore for 2-3 years.

Indeed, by re-reading the request I understand that the goal is to read the page number of the stamp. I don't really understand what it can be used for... Knowing the page number or the number of pages of the target file seems much more interesting to 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
Enthusiast ,
Jun 16, 2022 Jun 16, 2022

Copy link to clipboard

Copied

I just did a test and cropping the stamp works fine.

However, I placed the initial width value in the script because I couldn't recover it directly.

@try67: If you have an idea...

@+

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 ,
Jun 16, 2022 Jun 16, 2022

Copy link to clipboard

Copied

You can do it using the getPageBox method.

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 ,
Jun 16, 2022 Jun 16, 2022

Copy link to clipboard

Copied

...of course! But he goal is to recover the initial width of the stamp.

So, when do we have to use setPageBox?

If I use getPageBox/setPageBox at the beginning of the script, the width is the one of the previoulsy cropped stamp.

If I use setPageBox at the end of the script to recover the initial dimensions, the stamp is applied not cropped!

In fact the stamp is applied when the script is completed, correct?

So, maybe we can use an other field in an other page to store the initial dimensions, but might as well write dimensions in the script... No?

@+

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