Generate Random Number with conditions (watermark pdfs)

Contributor ,
May 05, 2019

Copy link to clipboard

Copied

Requirements:

Watermark around 100 pdf file of around 100 pages each  with below conditions:

1.   5 Pages to be watermarked for each file excluding Pages 1 - 5

2.  All 5 pages for each file should be different .. ex- if File1  was watermarked on page nos. 11, 22, 49, 80, 95 then second file2 should be watermarked with different set of pages ex- page nos. 14, 18, 49, 90,99 and so.. on

3. Each file must close automatically without prompting to save dialog box everytime.

        I am using the below script to save file but still prompting the save dialog box

var oMyDoc = this.documentFileName;

app.execMenuItem("Save", oMyDoc);

this.closeDoc(true);

I have the following script for watermarking and generating random number:

var cMyText = util.printd("mm/dd/yyyy", new Date);

var r = Math.floor(Math.random() * 100) ;

if (r > 10){var first = r; }

this.addWatermarkFromText({

cText: cMyText,

nRotation: 45,

cFont: "Helvetica-Bold",

nFontSize:20,

aColor: color.gray,

nStart: this.pageNum=first

nOpacity:0.5});

Thanks in advance

TOPICS
Acrobat SDK and JavaScript, Windows

Views

434

Likes

Translate

Translate

Report

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

Generate Random Number with conditions (watermark pdfs)

Contributor ,
May 05, 2019

Copy link to clipboard

Copied

Requirements:

Watermark around 100 pdf file of around 100 pages each  with below conditions:

1.   5 Pages to be watermarked for each file excluding Pages 1 - 5

2.  All 5 pages for each file should be different .. ex- if File1  was watermarked on page nos. 11, 22, 49, 80, 95 then second file2 should be watermarked with different set of pages ex- page nos. 14, 18, 49, 90,99 and so.. on

3. Each file must close automatically without prompting to save dialog box everytime.

        I am using the below script to save file but still prompting the save dialog box

var oMyDoc = this.documentFileName;

app.execMenuItem("Save", oMyDoc);

this.closeDoc(true);

I have the following script for watermarking and generating random number:

var cMyText = util.printd("mm/dd/yyyy", new Date);

var r = Math.floor(Math.random() * 100) ;

if (r > 10){var first = r; }

this.addWatermarkFromText({

cText: cMyText,

nRotation: 45,

cFont: "Helvetica-Bold",

nFontSize:20,

aColor: color.gray,

nStart: this.pageNum=first

nOpacity:0.5});

Thanks in advance

TOPICS
Acrobat SDK and JavaScript, Windows

Views

435

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 05, 2019 0
Most Valuable Participant ,
May 05, 2019

Copy link to clipboard

Copied

Add 5 to the value of generated random number...

PS. This line is not correct:

nStart: this.pageNum=first

Replace it with just:

nStart: r

And drop the "first" variable declaration. It's not needed.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2019 0
Contributor ,
May 05, 2019

Copy link to clipboard

Copied

Thanks for reply , but how to watermark 5 random different pages ,it is watermarking only 1 random page. Also different files should have different set of random pages   like file 1 :  page no. 20,26,45,58,98 then file 2 should be page nos. 20,34,63,95  something like this.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2019 0
Most Valuable Participant ,
May 05, 2019

Copy link to clipboard

Copied

Put the code in a loop, generating a new page number each time. If you want to make sure that the same page number is not selected twice you'll need to save them into an array and then put the random command inside a loop that generates numbers until a new one appears.

The chances of two documents getting the exact same 5 results are very small. If it happens you should go and fill out a lottery form.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2019 0
Adobe Community Professional ,
May 06, 2019

Copy link to clipboard

Copied

3. Use the saveAs method.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 06, 2019 0
Contributor ,
May 06, 2019

Copy link to clipboard

Copied

I used saveAs method but they didnot worked.....

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 06, 2019 0
Contributor ,
May 06, 2019

Copy link to clipboard

Copied

i used the below script  but didnot worked ... it still prompts to save dialog box

var fileName = this.documentFileName; 

this.saveAs("../Desktop/NewFolder/" + fileName);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 06, 2019 0
Most Valuable Participant ,
May 06, 2019

Copy link to clipboard

Copied

You have to specify a full path, not a relative one.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 06, 2019 0
Contributor ,
May 06, 2019

Copy link to clipboard

Copied

Well, i used the full path also but still prompting "Do you want to save Changes"  dialog box.

var fileName = this.documentFileName; 

this.saveAs("C/Users/RAKESH/Desktop/watermark/" + fileName);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 06, 2019 0
Most Valuable Participant ,
May 06, 2019

Copy link to clipboard

Copied

Add another forward slash at the very beginning of the file-path. Also, you must run it form a privileged context, as is documented in the API Reference.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 06, 2019 0
Contributor ,
May 06, 2019

Copy link to clipboard

Copied

Thanks

/C/Users/RAKESH/Desktop/watermark/

this worked..

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 06, 2019 0