0
votes

I am new to this topic.

What i have done so far,

1) I have read existing pdf document

2) I have created copy of existing pdf using pdfStamper of iTextSharp

3) and create three layer on new pdf using iTextSharp.

Now i want to open this pdf in adobe reader and i want to add comments on these three layer separately as regular pdf commenting option.

But problem is, it is not saving on respective layer, it is saving on pdf.

On/Off action of pdf layer for comment is not working.

can you guide me how to proceed further.

Thank You all

1
What does your code look like? Does the existing PDF already have Optional Content Groups (OCG)? - Bruno Lowagie
Hi, Thank You for your response... Existing pdf dont have any OCG. My requirement is Step1: Create Three Layer program ally (using iTextSharp). (Completed) Step 2: Then use that layer as OCG in Acrobat Reader & add comment on different layer separately. (Problem) Step3: Show the comment based on radio layer open. (Pending) - Mahesh

1 Answers

1
votes

Your problem can not be reproduced. Please look at the AddOCG to find out how I tried to reproduce the problem and failed. Which is a good thing, because it means that there is no problem.

I took the example from my book OptionalContentExample.cs and I changed it so that it doesn't create a new document from scratch, but instead adds optional content to an existing document.

This involves using PdfStamper and using the getPdfLayers() method:

PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
Map<String, PdfLayer> layers = stamper.getPdfLayers();
PdfWriter writer = stamper.getWriter();
PdfContentByte cb = stamper.getOverContent(1);
PdfLayer group = PdfLayer.createTitle("Grouped layers", writer);
PdfLayer layer1 = new PdfLayer("Group: layer 1", writer);
PdfLayer layer2 = new PdfLayer("Group: layer 2", writer);
group.addChild(layer1);
group.addChild(layer2);
cb.beginLayer(layer1);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase(
            "layer 1 in the group"), 50, 700, 0);
cb.endLayer();
cb.beginLayer(layer2);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase(
            "layer 2 in the group"), 50, 675, 0);
cb.endLayer();
stamper.close();
reader.close();

The resulting PDF hello_OCG.pdf has all the layers as expected and all layers work the same way the layers work in the book example. That is: the layers work when viewed in PDF Viewers that support this functionality. Some PDF viewers completely ignore OCG.