Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dynamic watermarking with Javascript

New Here ,
Oct 29, 2024 Oct 29, 2024

I am trying to create a Javascript string that can apply a watermark based on user input. I need it to say something along the lines of "this document is licensed to ____. Cannot be reproduced/resold, etc." It needs to appear on every page and I would like to avoid it asking every time the document is opened. I have never worked with Javascript, but I have been able to come close to a solution by following various tutorials. Unfortunately, none of them are quite right. I am still missing how to add static text around the dynamic name. Below is what I have so far, any help would be greatly appreciated! 

 

 

var dialogTitle = "Purchaser Name";
var PurchaserName = app.response("Please enter your name",
dialogTitle);


event.target.addWatermarkFromText({
	cText: PurchaserName,
	nTextAlign:app.constants.align.center,
	cFont: "Arial",
	nRotation: 0,
	nScale: -1,
	nOpacity: 0.06,
	nFontSize: 5
});

 

TOPICS
Create PDFs , JavaScript , PDF
582
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Oct 29, 2024 Oct 29, 2024
var dialogTitle = "Purchaser Name";
var PurchaserName = app.response("Please enter your name",
dialogTitle);
var fullText;
if(PurchaserName)
{
fullText="This document is licensed to "+ PurchaserName;
}
 
this.addWatermarkFromText({
cText: fullText,
nTextAlign:app.constants.align.center,
cFont: "Arial",
nRotation: 0,
nScale: -1,
nOpacity: 0.06,
nFontSize: 5
});

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 29, 2024 Oct 29, 2024
var dialogTitle = "Purchaser Name";
var PurchaserName = app.response("Please enter your name",
dialogTitle);
var fullText;
if(PurchaserName)
{
fullText="This document is licensed to "+ PurchaserName;
}
 
this.addWatermarkFromText({
cText: fullText,
nTextAlign:app.constants.align.center,
cFont: "Arial",
nRotation: 0,
nScale: -1,
nOpacity: 0.06,
nFontSize: 5
});
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 30, 2024 Oct 30, 2024

Thank you so much! I am very close. Is there a way to "lock in" the watermark after the first time the pdf is opened? Ideally, I would love to have the purchaser open the document, enter their name once, then have the watermark stay from then on. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2024 Oct 30, 2024
LATEST

Your should start by only running the script if the document has not been watermarked yet (assuming the one you are adding will be the only watermark.  Do this by putting your entire script inside the curly brackets of this:

if(!this.getOCGs())

{

//your script here

}

 

To answer your question, the document would have to be saved after the user adds the watermark by entering the name.  You could pop up a SaveAs window but you can't force the user to save the document.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines