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

Generate Random Number with conditions (watermark pdfs)

Engaged ,
May 05, 2019 May 05, 2019

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
1.6K
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 ,
May 05, 2019 May 05, 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.

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
Engaged ,
May 05, 2019 May 05, 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.

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 ,
May 05, 2019 May 05, 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.

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 ,
May 06, 2019 May 06, 2019

3. Use the saveAs method.

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
Engaged ,
May 06, 2019 May 06, 2019

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

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
Engaged ,
May 06, 2019 May 06, 2019

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

var fileName = this.documentFileName; 

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

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 ,
May 06, 2019 May 06, 2019

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

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
Engaged ,
May 06, 2019 May 06, 2019

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);

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 ,
May 06, 2019 May 06, 2019

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.

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
Engaged ,
May 06, 2019 May 06, 2019
LATEST

Thanks

/C/Users/RAKESH/Desktop/watermark/

this worked..

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