How to turn layers on programatically in the PDFViewWPF viewer using C# .NET 4.0

76 views
Skip to first unread message

John Ritchie

unread,
Jul 25, 2014, 10:51:05 AM7/25/14
to pdfne...@googlegroups.com
I have followed the documentation and examples:
1) I can dump layers out to BMP - nice but not what I need
2) I can see and access all my layers by cycling through the Optional Content Groups.

What I can't do and is an absolute must is to be able to turn on a layer of my choosing in the viewer. I have tried to set the states on the config context, tried setting current and initial state on each OC group. And of course with each of my attempts I, at the end, update the PDFViewWPF viewer to reset to the document and to Update the Page Layout.

All I get is still just the initial drawing with no layers turned on. I also saw mention of a layers panel with the viewer, yet I can not find how to turn this on either.

Aaron

unread,
Jul 25, 2014, 1:50:15 PM7/25/14
to pdfne...@googlegroups.com
Hello John,

You should be able to call Current_View.SetOCGContext() within PDFViewControl.xaml.cs.  Please let me know if this is not working for you.

John Ritchie

unread,
Jul 25, 2014, 4:07:00 PM7/25/14
to pdfne...@googlegroups.com
On Friday, July 25, 2014 12:50:15 PM UTC-5, Aaron wrote:
> Hello John,
>
> You should be able to call Current_View.SetOCGContext() within PDFViewControl.xaml.cs.  Please let me know if this is not working for you.

That worked! Thank you very much!!

Shai Zaban

unread,
Feb 1, 2015, 12:48:46 PM2/1/15
to pdfne...@googlegroups.com
Hi, It does not work for me.
How did you refresh the viewer?
Can you please post a sample code to show how to do that?

Thanks,
Shai


Ryan

unread,
Feb 2, 2015, 1:44:11 PM2/2/15
to pdfne...@googlegroups.com
After calling SetOCGContext, you will want to call Update method to refresh the viewer.

Along with the PDFNet SDK for .Net there is also the regular PDFViewCtrl class, and samples, and these samples include a layers ui from which you can turn on/off layers. If you are having problems you may want to try the sample and verify exactly what each OCG layer is doing for the particular file(s) you are using.

Shai Zaban

unread,
Feb 3, 2015, 3:08:44 PM2/3/15
to PDFTron PDFNet SDK on behalf of Ryan
Thanks, it is now working for me.
what I did is as follows, the order before might have been wrong:

Config init_cfg = doc.GetOCGConfig();

Context ctx = new Context(init_cfg);

ctx.SetState(group, state);

Current_View.SetOCGContext(ctx);

Current_View.Update();

 

On Mon, Feb 2, 2015 at 8:44 PM, Ryan via PDFTron PDFNet SDK <pdfnet-sdk+APn2wQeLvqS1aDfDhWC9f...@googlegroups.com> wrote:
After calling SetOCGContext, you will want to call Update method to refresh the viewer.

Along with the PDFNet SDK for .Net there is also the regular PDFViewCtrl class, and samples, and these samples include a layers ui from which you can turn on/off layers. If you are having problems you may want to try the sample and verify exactly what each OCG layer is doing for the particular file(s) you are using.

--
You received this message because you are subscribed to the "PDFTron PDFNet SDK" group (http://www.pdftron.com/pdfnet/forum.html).
---
You received this message because you are subscribed to a topic in the Google Groups "PDFTron PDFNet SDK" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pdfnet-sdk/nLxPoUh2zWA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pdfnet-sdk+...@googlegroups.com.
To post to this group, send email to pdfne...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages