Dynamic stamps – My ultimate guide – Timestamps as example (JavaScript form textboxes)

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

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

Post Reply
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Dynamic stamps – My ultimate guide – Timestamps as example (JavaScript form textboxes)

Post by MedBooster »

%appdata%\Tracker Software\PDFXEditor\3.0\Stamps
As we have discussed this many times, creating dynamic stamps can be quite confusing, as you have to move files the correct way, and you can't really edit dynamic stamp folders that are in appdata.

So before I think to film a video on it I thought I would practise by making this post first, also for me to have this to refer back to myself (as I keep forgetting the order of which things should be done in)

As an example you can download this dynamic timestamp

about creating multiple pages I added a 2nd and 3rd duplicate page which you can delete or modify

The information lost if you try and import "from file" is the form field (JavaScript) code, this is what makes it difficult to combine collections with dynamic stamps, this you have to do by moving the PDF collection file out of the appdata folder, insert and move around the pages, and only then move it back into the appdata folder. It is unfortunately the same with importing a stamp "from selection", this also gets rid of its dynamic properties and basically just converts it into a static "image" stamp
Hence...
STEP 1 (if premade dynamic stamp)
You have to first move the dynamic stamp collection outside of %appdata%\Tracker Software\PDFXEditor\3.0\Stamps – e.g. to your Desktop/Document folder.

STEP 2 – editing an existing or new PDF file outside of the appdata folder Skip step 1 if you are making a new one from scratch
You can open the stamp collection file when it is NOT in the appdata folder
If you are creating your own, you can start with a new blank PDF file of your desired size (File → New Document → with blank pages)

Add shapes and non-dynamic text (textboxes/typewriter etc...)

STEP 3 - ADDING THE DYNAMIC PARTS with form fields (JavaScript)

Form (tab) → select fields is used to edit the form field ("Text" under the "Form"-tab)

Then you can
1) move and resize the form textboxes
2) change the JavaScript code by going into the properties as shown in the attached screenshot
image.png
Double click here and you will in this case get the code:

Code: Select all

var d = new Date;
event.value = util.printd("dd.mm.yyyy HH:MM:ss", d);
STEP 4 – FINAL STEP
AFTER you're done editing shapes, text and the form field in PDF-XCE, while it is not in the appdata folder, you can close PDF-XCE, wait a few seconds, and then move it back into the APPDATA folder path – this is because you can't move files open in any program (in this case PDF-XCE)

Then you can open PDF-XCE again and you'll have your dynamic stamp collection.
(You can rename your stamp either in the appdata folder with PDF-XCE closed, or in PDF-XCE itself when the PDF is placed somewhere else on your disk (PC).)

Related posts:

Feel free to share your own dynamic stamps in this thread: :!: :D
viewtopic.php?t=44637

Question from my side
Hoping to see further integration with dynamic stamps in the future – I am not sure if you are currently able to create dynamic stamps with all JavaScript function under "add new" → "add custom stamp" ?

LMK if there is anything to add or elaborate in my instructions
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: Dynamic stamps – My ultimate guide – Timestamps as example (JavaScript form textboxes)

Post by MedBooster »

For adding a new form field

Select "Text" → make a new textbox → open properties and go undervalue calculation → custom action
image.png
image(1).png
Then double-click on "run a javascript"
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: Dynamic stamps – My ultimate guide – Timestamps as example (JavaScript form textboxes)

Post by MedBooster »

More advanced instructions – example with 3 letter month

Important:
1) The font size and type is changed under "text field properties" – not the format tab (width and color can be changed from the format tab though)
2) I recommend setting alignment to center
3) If the amount of text varies by a lot, you can set font size to "auto"
image.png

Code: Select all

var d = new Date();
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var year = d.getFullYear();
var month = months[d.getMonth()];
event.value = month + " " + year;

I still haven't figured out
1) whether you can group form fields viewtopic.php?t=44675
2) desync form fields from each other – as of now it seems you have to create a new form field each time you want to add new/different JavaScript code viewtopic.php?t=44676
3) aligning to other form fields / base content viewtopic.php?t=44677
4) Form field default formatting / applying/copying formatting viewtopic.php?p=187316#p187316

Good fonts;
TrebuchetMS
Arial
Carlito
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: Dynamic stamps – My ultimate guide – Timestamps as example (JavaScript form textboxes)

Post by MedBooster »

Example of adding stamp to collection

Let's say I would like to add this single stamp (alone in a stamp collection PDF) – to another collection with many stamps This is in my document folder on the right – and the appdata stamp folder on the left

1)
I copy over the stamp collection from appdata to the document folder
image.png
2)
Open the large stamp collection I want to import into in PDF-XCE, and choose Organize → "insert pages"
image(1).png
3) import the PDF page (stamps you want to add) that is NOT in the appdata folder (this is what has tripped me up many times)

4) save the new collection PDF in your document folder

5) close PDF-XCE and move the new collection PDF to the appdata PDF folder %appdata%\Tracker Software\PDFXEditor\3.0\Stamps

6) Open PDF-XCE and enjoy your new collection, delete single stamps or collections if needed


make sure to have backups of your stamp collections just to be on the safe side




ehm... I might have made a mistake somewhere along the process... The last 3 pages (stamps) in the collection do not appear in the stamp tool palette. IDK what happened. Maybe someone could download it at see if they are able to see these last 3 stamps. ↓
NewDiskReceivedMedBoosterDateStamps.pdf
(33.47 KiB) Downloaded 39 times
image(2).png
The form field still contain the javascript scripts... There are no comments, only base content, so it's really strange that the 3 stamps I circled in the screenshot don't appear in the stamps palette. (I've tried restarting my PC)

edit:
another option (viewtopic.php?p=187319#p187319v)
maybe you can "add from file"

The JavaScript fields would break for sure if you use the merge tool according to Paul-tracker support viewtopic.php?t=44644

Please don't quote me in replies to this post about combining stamps, as I would like to edit it to be correct once I've figured it out or gotten feedback
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10935
Joined: Wed Jan 03, 2018 6:52 pm

Re: Dynamic stamps – My ultimate guide – Timestamps as example (JavaScript form textboxes)

Post by Daniel - PDF-XChange »

Hello, MedBooster

Thank you very much for this, we have tried to explain the whole process in this article and the two others it refers to:
https://www.pdf-xchange.com/knowledgeba ... p-Creation

We do also have a YouTube video detailing the simpler aspects of the process:
https://www.youtube.com/watch?v=7mTnX6uXYOA

Also to try and answer some of your questions in this thread (I am carefully only quoting the questions you have asked, to avoid any later issues with your edits):
MedBooster wrote: Thu Nov 28, 2024 12:28 pm I am not sure if you are currently able to create dynamic stamps with all JavaScript function under "add new" → "add custom stamp" ?
No, The "add custom stamp" function is limited in this area, as it is both a free feature (granting access to dynamic stamp creation even for unlicensed users) and it is intended as a simplified process. Granting access to JS control and expecting their use in that area would be quite involved, especially as some items like the stamp ID, cannot be known until after the stamp is created.
MedBooster wrote: Thu Nov 28, 2024 12:49 pm I still haven't figured out
1) whether you can group form fields viewtopic.php?t=44675
2) desync form fields from each other – as of now it seems you have to create a new form field each time you want to add new/different JavaScript code viewtopic.php?t=44676
3) aligning to other form fields / base content viewtopic.php?t=44677
4) Form field default formatting / applying/copying formatting viewtopic.php?p=187316#p187316
  1. Yes, simply give the form fields the same name, and they will contain and mirror the same data, including their JS. This can be handy in cases where you are making a collection, and every stamp needs the "user name" field for example, since you only need to enter the script once.
  2. it is possible to make use of "document JavaScript" for more complex field interactions, with direct reference to the requisite field names, but it is not strictly necessary in many cases. I am not entirely sure how this related to "desync"-ing the fields however?
  3. To other fields, this would be done with the arrange tools, much the same as any other content type. Note that since you cannot select a form field and base content at the same time, it is not possible to directly align them to one another.
  4. I have answered this in the cited post, however for anyone skimming this post, that option is available in the right click context menu when using the "select fields" tool.
Regarding your very last post, to my knowledge, it is not possible in any way to merge two disparate Dynamic-Stamp PDF files. The process of creating the stamps, and why it is so important to extract and directly utilize the originally created Stamp file is because there is document specific metadata included in the stamp document that is not present in a normal PDF.
By Extension, it should be noted that any modification/insertion of the pages, page positions, etc, should NEVER be done in a Stamp file, as it could damage that metadata, and render your stamps unusable. This data cannot be carried over or modified through normal PDF editing processes. As such, you will need to manually add the non-dynamic content to the stamp.
This process would include:
  1. Create stamp from file > Choose the collection you plan to move into another, note that the dynamic content WILL be removed.
  2. Choose the target collection you wish for those pages to be added to.
  3. Proceed with normal dynamic stamp editing processed, copying the dynamic content items from the original stamp, into the new one.
    **IMPORTANT - If any of your stamps used a Stamp ID to limit when its JS runs, you WILL need to update that, as the stamp ID has changed in this process. If you simply copy/paste the field without editing the JS to use the new ID, your JS will not execute.
I hope this (and the article I linked above) helps!
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: Dynamic stamps – My ultimate guide – Timestamps as example (JavaScript form textboxes)

Post by MedBooster »

Yes it might be easier to use custom stamp for more simple date timestamps
https://www.pdf-xchange.com/knowledgeba ... nge-Editor

I tested it out a bit, and it works pretty well, however not all comment types are available in this simplified tool :-) , so it depends what you want to do ...
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: Dynamic stamps – My ultimate guide – Timestamps as example (JavaScript form textboxes)

Post by MedBooster »

Check out page 595 in the manual if something isn't working out for you.
Here dynamic stamp creation is also well explained
https://downloads.pdf-xchange.com/PDFXE10_MAN.pdf


I think my guide here still contains some mistakes,
– especially when it comes to "combining" stamp collections which isn't really possible for dynamic stamps like it is for static stamps (unfortunately)
Discussions on this:

You can't duplicate/insert new dynamic stamps viewtopic.php?t=44725

dynamic stamp reorder and change location – without losing the original stamp titles
viewtopic.php?t=42084
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19825
Joined: Mon Jan 12, 2009 8:07 am
Contact:

Re: Dynamic stamps – My ultimate guide – Timestamps as example (JavaScript form textboxes)

Post by Stefan - PDF-XChange »

Hello MedBooster,

We do appreciate you spending the time to create this guide, and are happy to see you are getting the results you want.
As Daniel pointed out we also have some articles of our own, and hope that all of it combined will be useful to other people looking at creating new dynamic stamps themselves too!

Kind regards,
Stefan
Mathew
User
Posts: 564
Joined: Thu Jun 19, 2014 7:30 pm

Re: Dynamic stamps – My ultimate guide – Timestamps as example (JavaScript form textboxes)

Post by Mathew »

MedBooster wrote: Tue Dec 03, 2024 12:23 pm I think my guide here still contains some mistakes,
@MedBooster, as discussed, your guide about adding stamps to a collection won't work: We can't add or delete pages from a stamp file directly.

My procedure to add a stamp (static or dynamic) to a collection:
  1. Use 'Add New Stamp from File...' to add the stamp to a collection from a pdf file
  2. If it's not a dynamic stamp, you're done.
  3. If it's a dynamic stamp, apply the newly added stamp to a blank document and note the Stamp ID from the stamp properties:
    image.png
    image.png (3.93 KiB) Viewed 2645 times
  4. Close PDF-XChange
  5. Move the stamp collection file out of the stamps folder and open it in PDF-XChange
  6. Go to the page with the new stamp in the collection file, and with the content editing tool delete everything that is either a form field or an annotation (comment) in your original pdf
  7. Open the original pdf and using the Edit Form > Select Fields tool select all fields and copy them
  8. Go back to the collection file and paste the fields
  9. Edit the custom actions and change the Stamp ID to the one you noted in step 3 above
  10. If there are annotations in the original pdf, copy those with the Select Comments tool from the original pdf and paste them into the collection file page.
  11. Quit PDF-XChange and move the collection file back into the stamps folder
I cannot fathom why PDF-XChange decided it needs to flatten all content when it inserts a stamp from a file or the active document: It adds so much effort to dealing with dynamic stamps and I think is maybe a remnant of old code. The flattening should happen on stamp placement only, after all actions and calculations. Other software allows people to just import a pdf and the only action needed is to edit the Stamp ID. Even that step would not be difficult for PXCE to handle: A user could enter a string to replace in the source pdf actions and PXCE could find/replace that string with the new stamp ID in all actions.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19825
Joined: Mon Jan 12, 2009 8:07 am
Contact:

Re: Dynamic stamps – My ultimate guide – Timestamps as example (JavaScript form textboxes)

Post by Stefan - PDF-XChange »

Hello Mathew,

Thanks for the detailed steps.
Indeed I am doing the same ones when I need to move a stamp to another collection (which is not too often for me to be honest).

I will ask my colleagues from the dev team to comment on why everything is flattened when you create a new stamp from file. It might be possible that this process can be improved, which would then save quite a bit of the above steps :)

Kind regards,
Stefan
Post Reply