Subjects of Dynamic Stamps  SOLVED

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

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

TheHipshaker
User
Posts: 8
Joined: Tue Aug 17, 2021 11:59 am

Subjects of Dynamic Stamps

Post by TheHipshaker »

Hello there,
I am struggling with the subject of a dynamic stamp I am creating.
The stamp receives user input for its visual representation.
In our case it is a BoQ number in some alphanumeric format like "10.10.0250".
Now this works like a charm with this code:

Code: Select all

if((event.source.forReal)&&(event.source.stampName == "#X1csF23c_6cU88RQPEZjO0"))
{
this.getField("UserText").value = app.response(
	{
		cQuestion: "Positionsnummer",
		cTitle: "Eingabe Stempelinhalt",
		cDefault: "",
		cLabel: "Positionsnummer:"
	}
) || "";

}
Admittedly I used AI for that already...

But now I would like to have this identifier "10.10.0250" as the subject of the stamp here
image(1).png
so we can export that later on as a csv to import it in the QTO tool.

Sadly AI is not helping anymore and I grit my teeth because I feel like I am so very close.
It seems to come down to timing but no delay in the code did anything to the outcome.

I hope you guys can help me figure this out.

Thanks a lot already!

Best regards
You do not have the required permissions to view the files attached to this post.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19856
Joined: Mon Jan 12, 2009 8:07 am

Re: Subjects of Dynamic Stamps

Post by Stefan - PDF-XChange »

Hello TheHipshaker,

I've just searched, however it seems like the Stamp's subject is determined by the name of that stamp in the collection, and while you can rename it in the Stamps Palette:
image.png
That is a manual process and I could not see a way to do it with JS from the stamp instance itself that is just being placed on the page.

Kind regards,
Stefan
You do not have the required permissions to view the files attached to this post.
TheHipshaker
User
Posts: 8
Joined: Tue Aug 17, 2021 11:59 am

Re: Subjects of Dynamic Stamps

Post by TheHipshaker »

Hi Stefan,
thanks for your reply. It indeed is the name of the stamp that I want to set parallel to the visible content of the stamp. I just want the user to only have to type the subject/content once.
I was exploring possibilities with JavaScript Add-on Tools but didn't get far. Does anyone have ideas on how to combine scripts to pass on a userinput from a Add-On Tool to a stamp?
The subject - or any other attribute of the annotation - is a valuable piece of information with which we can go forward in our processes.

Thanks to all considering this!

Best regards!
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19856
Joined: Mon Jan 12, 2009 8:07 am

Re: Subjects of Dynamic Stamps

Post by Stefan - PDF-XChange »

Hello TheHipshaker,

You can set up variables - and some of those can persist during the current session or even over different editor launches.

Please find attached a sample document that uses those as counters, but the same can probably be applied if you e.g. need to transfer info between tools.

Kind regards,
Stefan
You do not have the required permissions to view the files attached to this post.
Mathew
User
Posts: 570
Joined: Thu Jun 19, 2014 7:30 pm

Re: Subjects of Dynamic Stamps  SOLVED

Post by Mathew »

The way I would set the subject is to set up a timeout that looks for the newly created stamp, and assigns the property. In the tool I just posted, it uses the following code. First I set up a function that is saved the the javascripts folder, so is already loaded. This step is not entirely necessary as I explain at the end:

Code: Select all

xutil.setStampProperty = function( properties ) {
    // get current document and 'this' doesn't work
    const doc = app.doc;
    // may also work to get selectedAnnots (?) Not sure what's better
    const [newStamp] = doc.getAnnots({
        'nPage': doc.pageNum,
        'nSortBy': ANSB_ModDate, // jshint ignore:line
        'bReverse': false});

    if ('Stamp' !== newStamp.type) return console.println("The new stamp wasn't found.");
    
    newStamp.setProps( properties );
};
Then you call that function through a timeout at the end of your stamp script:

Code: Select all

app.setTimeOut("xutil.setStampProperty(" + JSON.stringify({subject: myNewSubject}) + ")",250);
Supply the callback function directly
PXCE from build 393 onwards supports supplying functions to setTimeOut so you could do away with the xutil.setStampProperty and supply it directly.

... come to think of it, for earlier builds you could do the same thing by converting the function into a string. Something like (not tested):

Code: Select all

{
// the function to set the property
const setStampProperty = function( properties ) {
    // get current document and 'this' doesn't work
    const doc = app.doc;
    // may also work to get selectedAnnots (?) Not sure what's better
    const [newStamp] = doc.getAnnots({
        'nPage': doc.pageNum,
        'nSortBy': ANSB_ModDate, // jshint ignore:line
        'bReverse': false});

    if ('Stamp' !== newStamp.type) return console.println("The new stamp wasn't found.");
    
    newStamp.setProps( properties );
};

// property: value pair to set
let prop = {subject: "my new subject"};

// set up the timeout
app.setTimeOut(`(${setStampProperty.toString()})(${JSON.stringify(prop)})`, 250);
}
Mathew
User
Posts: 570
Joined: Thu Jun 19, 2014 7:30 pm

Re: Subjects of Dynamic Stamps

Post by Mathew »

... or if you want to use the tool I posted, the dialog as well as setting the subject could be accomplished with:

Code: Select all

xutil.stampDialog("#X1csF23c_6cU88RQPEZjO0",
{description: "Positionsnummer:"},
{field: "UserText", description: "", setProp: 'subject'});
Last edited by Mathew on Thu Apr 03, 2025 2:32 pm, edited 1 time in total.
TheHipshaker
User
Posts: 8
Joined: Tue Aug 17, 2021 11:59 am

Re: Subjects of Dynamic Stamps

Post by TheHipshaker »

Mathew, you are a wizard!
At first I didn't get it right... I tried with just the snippet you posted in here.
With the whole xutil library from your referenced post and the additional app.setTimeOut line in the stamp it works like a charm with minimal setup.
My colleagues and I will sing your praise!
Thanks a million!
Mathew
User
Posts: 570
Joined: Thu Jun 19, 2014 7:30 pm

Re: Subjects of Dynamic Stamps

Post by Mathew »

TheHipshaker wrote: Thu Apr 03, 2025 6:54 am Mathew, you are a wizard!
At first I didn't get it right... I tried with just the snippet you posted in here.
With the whole xutil library from your referenced post and the additional app.setTimeOut line in the stamp it works like a charm with minimal setup.
My colleagues and I will sing your praise!
Thanks a million!
:)
If using the whole xutil the timeout is built in so you should only have to use is setProp: 'subject' to set the subject to the field value

Code: Select all

 xutil.stampDialog("#X1csF23c_6cU88RQPEZjO0",
{description: "Positionsnummer:"},
{field: "UserText", description: "", setProp: 'subject'});
If that does not work I’d like to know because for some reason it isn’t working right

Really glad it helps!
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19856
Joined: Mon Jan 12, 2009 8:07 am

Subjects of Dynamic Stamps

Post by Stefan - PDF-XChange »

:)