Dynamic stamp - metadata from the file the stamp is placed on  SOLVED

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Post Reply
luidoltp
User
Posts: 3
Joined: Wed Jun 08, 2022 10:00 am

Dynamic stamp - metadata from the file the stamp is placed on

Post by luidoltp »

Hi,

First of all I wanted to thank you for making PDF-XChange Editor. I use it for several years now and it has become one of my most valued tools that I use multiple times each day. It saved me countless hours of work and many headaches.
I recently started to familiarize myself with dynamic stamps and I have one question that I didn't manage to figure out.

Goal to achieve:
Have a Stamp that has a text that states the filename of the document the stamp is placed on.

Example:
Open the file Testfile007.pdf in PDF-XChange editor. Place a dynamic stamp. The text on the dynamic stamp should read "Testfile007".

What I tried so far:
I tried two different ways that both return just the filename of the stamp-file.

try1:

Code: Select all

var filename = this.documentFileName.replace(/.pdf/,"");
event.value = filename;
try2:

Code: Select all

if (event.source.forReal && (event.source.stampName == "#g3Bsd7emS4gn7CbzZEVzv2"))
{
	var filename = this.documentFileName.replace(/.pdf/,"");
	event.value = filename;
}
Where I am currently stuck:
It seems that "this.xxx" has the scope of the stamp file. I was not able to figure out a way to access metadata of the file the stamp is placed on.

I tried to find something in the forum; If I missed a thread I apologize and kindly ask you to point me to it.
I also tried to dig into the Acrobat PDF Javascript documentation but wasn't able to find any useful guidance on this topic.

Can you point me towards a solution on how to access metadata from the file the stamp is placed on?
Any help is appreciated.

Thanks,
Peter

PDF-XChange Editor Plus Version 9.3 build 361.0 running on Windows 10 Pro Version 21H2
User avatar
Paul - Tracker Supp
Site Admin
Posts: 6901
Joined: Wed Mar 25, 2009 10:37 pm
Location: Chemainus, Canada
Contact:

Re: Dynamic stamp - metadata from the file the stamp is placed on  SOLVED

Post by Paul - Tracker Supp »

Hi Peter,

thanks for the post and excellent question.
The issue at hand here us that this.document in the context of the stamp script is ... the stamp filer itself, not the document on which you are applying the stamp.

Try this instead:

Code: Select all

if (event.source.forReal)
{
	var filename = event.source.source.documentFileName;
event.value = filename;

}
Best regards

Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
luidoltp
User
Posts: 3
Joined: Wed Jun 08, 2022 10:00 am

Re: Dynamic stamp - metadata from the file the stamp is placed on

Post by luidoltp »

Hi Paul,

thanks for that quick answer. It worked like a charm!! :D

Just to be sure: Can I omit the following part or should it stay?

Code: Select all

&& (event.source.stampName == "#g3Bsd7emS4gn7CbzZEVzv2")
Thanks,
Peter
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17948
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Dynamic stamp - metadata from the file the stamp is placed on

Post by Tracker Supp-Stefan »

Hello luidoltp,

You might need the stamp name to ensure that this code triggers only when that specific stamp is used, and not e.g. any other in the same stamp collection. For capturing the file name of the file where the stamp is going to land that check might not necessarily be needed - but it is definitely going to be better and stricter if you do leave it there.

Kind regards,
Stefan
luidoltp
User
Posts: 3
Joined: Wed Jun 08, 2022 10:00 am

Re: Dynamic stamp - metadata from the file the stamp is placed on

Post by luidoltp »

Hi,

just wanted to thank you for the fast support and the spot on help. I now was able to have my dynamic stamp exactly how I wanted.
Thanks a lot guys and keep up the good work! :D

Thanks,
Peter
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17948
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Dynamic stamp - metadata from the file the stamp is placed on

Post by Tracker Supp-Stefan »

Hello Peter,

Gad to hear it all worked out for you!

Kind regards,
Stefan
Post Reply