JavaScript to hide/show or change opacity of watermark / getOCGs() returns null

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Mickets
User
Posts: 17
Joined: Fri Dec 06, 2013 8:23 pm

JavaScript to hide/show or change opacity of watermark / getOCGs() returns null

Post by Mickets »

Hello,

First of all, I'm not 100% sure if this is the correct forum ("current" releases) as the version I have is 7.0 (build 323.0). Apologies if this is the incorrect forum.

I'm looking in to covering a document with a watermark (or optionally a layer with an image), and hide/show the watermark/layer via JavaScript.

I did some research and found that I can use getOCGs() to find a specific layer, or even the Watermark layer.

I added an image as a Watermark, but when I invoke getOCGs it returns null (no layers). In fact, the layers pane shows no layers.

I realize that although I can open a PDF with layers in version 7, there isn't an option to add a new layer.

Questions:

  • Are Watermarks not layers (or OCGs)? Or can one handle Watermarks via JavaScript as one can with layers?
  • Am I correct that "New layer" is not available in version 7?
For reference, this is one topic I found in the forums: https://forum.pdf-xchange.com/viewtopic.php?t=38201

Thanks in advance
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11385
Joined: Wed Jan 03, 2018 6:52 pm

Re: JavaScript to hide/show or change opacity of watermark / getOCGs() returns null

Post by Daniel - PDF-XChange »

Hello, Mickets

So, in PDF, layers are not quite the same as the well known implementation that image editing or CAD software's use, they are essentially optional visibility groups in pdf, having items on one "layer" does not ensure that it will be above/below anything on any other layers. The term layers is only used becuase that is what Adobe, one of the first prolific softwares to implement the handling, decided to use, despite the incorrect associations that name gives these items. JS can be used to show/hide these "layers", but that is about it, and unfortunately, version 7 did not have any layer functionality built in.

With that said, Watermarks are a type of base content, not a comment, which means that unfortunately JS alone will not be able to manipulate them, you would need a software development key to fiddle with those options.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com