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!
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.
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...
@+
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.
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.
Copy link to clipboard
Copied
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.
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.
@+
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...
@+
Copy link to clipboard
Copied
You can do it using the getPageBox method.
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?
@+