Skip to main content
Participating Frequently
October 13, 2021
Question

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

  • October 13, 2021
  • 4 replies
  • 7716 views

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?

This topic has been closed for replies.

4 replies

Participating Frequently
October 15, 2021

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.

Participating Frequently
October 15, 2021

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

try67
Community Expert
Community Expert
October 15, 2021

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

Participating Frequently
October 14, 2021

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)

 

 

MikelKlink
Participating Frequently
October 15, 2021

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?

Legend
October 13, 2021

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

Participating Frequently
October 13, 2021

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

 




Legend
October 14, 2021

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.


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.