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

addWatermarkFromFile does not work for PDFs created via Microsoft: Print To PDF

New Here ,
Oct 13, 2021 Oct 13, 2021

Copy link to clipboard

Copied

Using the SDK and this.addWatermarkFromFile method works with the pdf supplied with the SDK, but when gererating a new PDF via Microsoft" Print To PDF or with Acrobat create new from file Word document it doesn't work.  It doesn't add the stamp at all.

The method addWatermarkFromText works fine, but I need to add an image.

If I do it manaully through Acrobat using the same files, it works fine.

Any suggestions?

TOPICS
Acrobat SDK and JavaScript

Views

284

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
community guidelines
LEGEND ,
Oct 13, 2021 Oct 13, 2021

Copy link to clipboard

Copied

Please share "before" and "after" files (ie after is the file which has no visible image)

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
community guidelines
New Here ,
Oct 13, 2021 Oct 13, 2021

Copy link to clipboard

Copied

SamplePDF01.pdf is the supplied file from SDK which works.
Sample2Portrait.pdf is the file generated from Word with Microsoft: Print To PDF

Test1.pdf is the resulting file from the below code using SamplePDF01.pdf as my input

Test2.pdf is the resulting file from the below code using Sample2Portrait.pdf

 

Here is my code:

 

$app = New-Object -ComObject AcroExch.App
$PDDoc = New-Object -ComObject AcroExch.PDDoC
$PDDoc.Open("C:\Users\100620\Documents\Derived Output\PDF Mastership\SamplePortrait.pdf")
$AVDoc = $PDDoc.OpenAVDoc("")
$AForm = New-Object -ComObject AFormAut.App
$AForm.Fields.ExecuteThisJavascript("this.addWatermarkFromFile('../../../../temp/Box.pdf');")


$NewDoc = $PDDoc.Save(1, "C:\Users\100620\Documents\Derived Output\PDF Mastership\Test2.pdf")

$app.CloseAllDocs();
$PDDoc.Close();
$ap

 




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
community guidelines
LEGEND ,
Oct 13, 2021 Oct 13, 2021

Copy link to clipboard

Copied

I've looked at test2.pdf and I'm pretty sure that, despite the larger file size, no image was added.

Did you check the JavaScript console after the apparent failure?

I am suspicious of the relative pathname, I don't think the current working directory is defined.

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
community guidelines
New Here ,
Oct 13, 2021 Oct 13, 2021

Copy link to clipboard

Copied

Thanks.
I'm running Acrobat standard, waiting to get pro installed.  I don't see a java console in standard.
The relative pathname works fine for the other input file.

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
community guidelines
LEGEND ,
Oct 13, 2021 Oct 13, 2021

Copy link to clipboard

Copied

You absolutely need the console. It is impossible to debug without it because it's the only place to which JavaScript error messages are written. And JavaScript always needs debugging. The console may well be in the Standard UI. It is also called "JavaScript debugger". Use tool search on "JavaScript" to see if it appears.

 

Otherwise, there is a JavaScript command which opens the console, so you can run that command first through the API.

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
community guidelines
New Here ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

I'm using Acrobat Standard 2017.  I don't see anything for a javascript console.
I'm hoping to get Pro installed today.

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
community guidelines
Enthusiast ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

I've also had a look at the PDFs. Like @Test Screen Name said there is no image added in Test2.pdf. Actually Sample2Portrait.pdf and Test2.pdf don't seem to be related at all, different content, different metadata, different everything.

Please check again whether Test2.pdf indeed is the output of your code or whether it merely is a file that already was in the location for the output of your code before and your code failed before saving.

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
community guidelines
New Here ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

I was trying multiple times and posted the wrong version of the test2.pdf, but the results are basically the same. I get the text from the original, but it doesn't add the watermarked file at all.

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
community guidelines
LEGEND ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

Basically the same doesn't really cut it. I spent some time doing a detailed analysis of the insides of the file to look to see what had happened. But I'll only do that once. 

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
community guidelines
Enthusiast ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

quote

I was trying multiple times and posted the wrong version of the test2.pdf, but the results are basically the same.

 

You probably do not understand why you were asked to share "before" and "after" files. That was not to to allow us to open some files in Acrobat to take a quick look and get a visual impression of what you see. That was to allow us to compare the internal structures of the PDF before and after. And for that basically the same is not enough.

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
community guidelines
New Here ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

Here is a before file which is SamplePDF01.pdf.  This is the file supplied with the SDK.
The stamp file is Box.pdf.

The resulting file is Test1.pdf.  This file genereates from the $NewDoc = $PDDoc.Save in the below code.
As you can see, the Test1.pdf has the box added as the watermark.


This is the code:

$app = New-Object -ComObject AcroExch.App
$PDDoc = New-Object -ComObject AcroExch.PDDoC
$PDDoc.Open("C:\Users\100620\Documents\Derived Output\PDF Mastership\SamplePDF01.pdf")
$AVDoc = $PDDoc.OpenAVDoc("")
$AForm = New-Object -ComObject AFormAut.App
$AForm.Fields.ExecuteThisJavascript("this.addWatermarkFromFile('../../../../temp/Box.pdf');")


$NewDoc = $PDDoc.Save(1, "C:\Users\100620\Documents\Derived Output\PDF Mastership\Test1.pdf")

$app.CloseAllDocs();
$PDDoc.Close();
$app.Exit();

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
community guidelines
New Here ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

This is an sample of what doesn't work.
The input file is Sample2Portrait.pdf which is generated from Acrobat Standard 2017 be selected create and choosing the Word file.
The stamp is Box.pdf
The output file Test2.pdf.   This file genereates from the $NewDoc = $PDDoc.Save in the below code.
As you can see, the Test2.pdf the box is NOT added as the watermark.

Here is the code:

$app = New-Object -ComObject AcroExch.App
$PDDoc = New-Object -ComObject AcroExch.PDDoC
$PDDoc.Open("C:\Users\100620\Documents\Derived Output\PDF Mastership\Sample2Portrait.pdf")
$AVDoc = $PDDoc.OpenAVDoc("")
$AForm = New-Object -ComObject AFormAut.App
$AForm.Fields.ExecuteThisJavascript("this.addWatermarkFromFile('../../../../temp/Box.pdf');")


$NewDoc = $PDDoc.Save(1, "C:\Users\100620\Documents\Derived Output\PDF Mastership\Test2.pdf")

$app.CloseAllDocs();
$PDDoc.Close();
$app.Exit();

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
community guidelines
Community Expert ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

It works using this.addWatermarkFromFile() in Adobe Acrobat.

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
community guidelines
New Here ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

Hi Bernd,

You were able to get the Sample2Portrait to watermark with file?
If it works for you, could it be the version I am using Acrobat Standard 2017?

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
community guidelines
New Here ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

I'm runnig this code inside of Windoews Powershell ISE if that matters.

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
community guidelines
Community Expert ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

The result was the document with the watermark.

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
community guidelines
Community Expert ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

Have you removed the text

 SNC Internal Information

from file Test2.pdf?

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
community guidelines
New Here ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

That extra text at the bottom is footer text from the original Word file.  I tried without any additional header or footer texts wiht same results.


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
community guidelines
New Here ,
Oct 14, 2021 Oct 14, 2021

Copy link to clipboard

Copied

If I do this in my powershell for the source PDF that works, then $temp returns System._ComObject.
If I do this for Sample2Portrait.pdf, then $temp is empty.


$AForm = New-Object -ComObject AFromAut.app

$temp = $AForm.Fields;

write-host($temp)

 

 

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
community guidelines
Enthusiast ,
Oct 15, 2021 Oct 15, 2021

Copy link to clipboard

Copied

Well, SamplePDF01.pdf contains a form definition (the PDF actually contains a text field with the text "This is the latest document submitted for review. 8/30/2004") but Sample2Portrait.pdf does not. This might explain your observation.

 

Interestingly, though, Test2.pdf does contain a form definition.

 

So it looks like $AForm.Fields implicitly creates a form definition (if none was there) but does not return an object representing it. Have you tried fetching $AForm.Fields a second time if it was empty the first time? Is the second result still empty?

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
community guidelines
New Here ,
Oct 15, 2021 Oct 15, 2021

Copy link to clipboard

Copied

I found the javascript console.  When using SampePortrait.pdf as my imput, it get this error in the console:

 

NotAllowedError: Security settings prevent access to this property or method.
Doc.addWatermarkFromFile:1:External undefined:Exec

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
community guidelines
Community Expert ,
Oct 15, 2021 Oct 15, 2021

Copy link to clipboard

Copied

Is the file secured or digitally signed, by any chance?

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
community guidelines
New Here ,
Oct 15, 2021 Oct 15, 2021

Copy link to clipboard

Copied

LATEST

I got it to work!
I had to add the folder for my source PDFs to the trusted folders.
Thanks everybody!  This is a very responsive forurm.

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
community guidelines