Show/hide layers/OCG by name

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
pHol
User
Posts: 30
Joined: Mon May 08, 2017 9:47 am

Show/hide layers/OCG by name

Post by pHol »

Hi!

Is it possible to show/hide a layer/OCG by name, either with the push of a button or when a document is opened?
And what if the layer/OCG was inserted in a single page document and later merged into another document? Is it possible to access and hide it by the same name still?

Cheers,
Philip
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17906
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Show/hide layers/OCG by name

Post by Tracker Supp-Stefan »

Hello Philip,

I believe this is the place to start:
https://sdkhelp.pdf-xchange.com/vie ... _OCContext

You can then change it's visibility with this:
https://sdkhelp.pdf-xchange.com/vie ... SetOCState

Cheers,
Stefan
pHol
User
Posts: 30
Joined: Mon May 08, 2017 9:47 am

Re: Show/hide layers/OCG by name

Post by pHol »

Hi Stefan!


What is an IPXS_PDFVariant and how is it used? Is it possible for you to give an example to show this maybe?

Cheers,
Philip
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Show/hide layers/OCG by name

Post by Sasha - Tracker Dev Team »

Hello Philip,

You can use the JS to work with OCGs:
http://help.adobe.com/en_US/acrobat/acr ... 1_8_51_0_4

To do that the IPXV_Inst::ExecuteJS method should be used.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
pHol
User
Posts: 30
Joined: Mon May 08, 2017 9:47 am

Re: Show/hide layers/OCG by name

Post by pHol »

Hi Alex!

I have tested to get the ocgs with JS, but it does not seem to work. I use a PDF document where I know that there is an ocg in but the result is till null which indicated that there are no ocgs present.
Here is the code I'm using and the sample document. (I've used PdfCtl.Inst and PdfCtl.Doc to relate to your full demo)

Code: Select all

private void Button_Click(object sender, MouseButtonEventArgs e)
{
	string js =  "var ocgArray = this.getOCGs(); ocgArray;"  ;
	Console.WriteLine(RunJS(PdfCtl.Doc, js));
}
                
public string RunJS(IPXV_Document doc, string js) 
{            
	IString str = pxvInst.CreateString();
	try
	{
		PdfCtl.Inst.ExecuteJS(doc, js, PXV_ActionTriggerClass.PAEC_External, PXV_ActionTriggerSubclass.PAESC_Exec, null, str);
		return !str.IsEmpty ? str.Value : "EMPTY";
	}
	catch (Exception ex)
	{
		return ex.Message;
	}
}
Sample OCG decompressed.pdf
(11.33 KiB) Downloaded 100 times

Am I doing something wrong or do you have an explanation to why what is printed to the console says "null"?

Cheers,
Philip
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Show/hide layers/OCG by name

Post by Sasha - Tracker Dev Team »

Hello Philip,

Please open the End-User Editor and try there - I don't see any layers available. Also, you can try your JS in the Editor to see how they behave before putting them into code.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
pHol
User
Posts: 30
Joined: Mon May 08, 2017 9:47 am

Re: Show/hide layers/OCG by name

Post by pHol »

Hi Alex!

The decompressed PDF looks like this:

18 0 obj
<</Name(AppWriterStamps)/Type/OCG>>
endobj


<</Length 88>>
stream
Q
q
/OC /Xi0 BDC
0 0 0 rg
BT
1 0 0 1 188.16 787.14 Tm
/Xi1 12 Tf
(OCG test)Tj
ET
EMC
Q

endstream


is this not a valid OCG?

Cheers,
Philip
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Show/hide layers/OCG by name

Post by Sasha - Tracker Dev Team »

Hello Philip,

The Acrobat also does not show any layers available - only the OCGs. Sadly, we do not provide the API to work with OCGs directly. You will have to create a layer for this OCG for this to work.
We do provide the possibility to show\hide items (content and annotations) by using the OCContext. This means that you have to create a callback method that would tell the PagesView what to do with Nth content item or Annotation (to display or hide it). Though this will require for you to create your custom commands to provide user interaction possibilities. This method is purely visual and does not edit the document itself.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
pHol
User
Posts: 30
Joined: Mon May 08, 2017 9:47 am

Re: Show/hide layers/OCG by name

Post by pHol »

Hi Alex!

You say I have to create a later to the OCG to make it work but don't know how to do that through your API. Maybe this is a dumb question, but how do I create a layer?

Cheers,
Philip
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Show/hide layers/OCG by name

Post by Sasha - Tracker Dev Team »

Hello Philip,

Right now we do not provide a possibility to create a layer. It is possible to do on a structure level manually by specification. For that you will have to read the 4.10 Optional Content paragraph and implement this by yourself:
http://www.adobe.com/content/dam/Adobe/ ... G9.3858031

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply