Skip to main content
rakeshk21205956
Inspiring
May 5, 2019
Question

Generate Random Number with conditions (watermark pdfs)

  • May 5, 2019
  • 2 replies
  • 1602 views

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

This topic has been closed for replies.

2 replies

Bernd Alheit
Community Expert
Community Expert
May 6, 2019

3. Use the saveAs method.

rakeshk21205956
Inspiring
May 6, 2019

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

try67
Community Expert
Community Expert
May 5, 2019

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.

rakeshk21205956
Inspiring
May 5, 2019

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.

try67
Community Expert
Community Expert
May 5, 2019

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.