Skip to main content
Participant
June 15, 2022
Answered

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

  • June 15, 2022
  • 3 replies
  • 1708 views

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 has been closed for replies.
Correct answer try67

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.

3 replies

bebarth
Community Expert
Community Expert
June 16, 2022

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

@+

try67
Community Expert
Community Expert
June 16, 2022

You can do it using the getPageBox method.

bebarth
Community Expert
Community Expert
June 16, 2022

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

@+

bebarth
Community Expert
Community Expert
June 16, 2022

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.

@+

bebarth
Community Expert
Community Expert
June 16, 2022

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

@+

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 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.

Phil.MAuthor
Participant
June 16, 2022

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.