We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Add Print Date in PDF using Print Action


I am using Aspose PDF for JAVA to add text stamps in my pdf. I want to add a printed date stamp whenever pdf is printed.

The method that I thought to use was to create a text stamp that has a Javascript variable with no value while generating the pdf

Code for this:

private TextStamp generatePrintedDateStamp(float fontSize, double bottomMargin, Color color) {
TextState textState = new TextState();
TextStamp footerStamp = new TextStamp(${VAR}, textState);
return footerStamp;

Now this text stamp will have a variable VAR. I am unable to see any method in which I can pass a JS variable in textstamp
After this I wanted to embed JS code wich will populate the variable with current date and trigger on print action

public Document addPrintDateCodeInPDF(Document doc) {
    String code = "VAR=currentDate()";
    JavascriptAction javaScript = new JavascriptAction(code);
    return doc;

My question here is des text stamp support a method which will embed a JS variable in the PDF if not is there another way to add printed date in the pdf?


No, the TextStamp does not support any method to embed JS. However, you can add a text box filed in the PDF at desired location with ReadOnly mode and set its value using JS Action. In case you face any issues, please let us know.

Thanks for the help, this approach worked.