Skip to main content
Participant
Jun 15, 2022 10:41 PM UTC
Answered

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

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!

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Jun 16, 2022 8:17 AM UTC

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.

8 replies

bebarth
Community Expert
Community Expert
Jun 16, 2022 1:29 PM UTC

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...

@+

Translate
try67
Community Expert
Community Expert
Jun 16, 2022 3:27 PM UTC

You can do it using the getPageBox method.

Translate
bebarth
Community Expert
Community Expert
Jun 16, 2022 6:58 PM UTC

...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?

@+

Translate
bebarth
Community Expert
Community Expert
Jun 16, 2022 10:11 AM UTC

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.

@+

Translate
bebarth
Community Expert
Community Expert
Jun 16, 2022 6:15 AM UTC

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...

@+

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Jun 16, 2022 8:17 AM UTC

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.

Translate
Phil.MAuthor
Participant
Jun 16, 2022 10:02 PM UTC

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.

Translate