0

I have implemented functionality to allow user to draw a cloud shape on a pdf, using the PDPageContentStream class's curve methods.And, I am drawing each of this cloud on a separate layer(OCG). Now I want to implement functionality to delete this markup. I am using the following code to get the PDPage contents:

PDPage page = (PDPage)doc.getDocumentCatalog().getPages().get(pageNum);
PDFStreamParser parser = new PDFStreamParser(page);
parser.parse();
java.util.Collection tokens = parser.getTokens();

For the markup, I first get a COSName{OC} token, and then I get the BDC command. So, all I need to do is to detect, that to which layer does this OC tag belong. And then I will know that the following marked sequence belongs the layer.Hence, I can delete all the tokens between BDC and EMC to delete the markup. But how do I know, that to which layer does this OC tag belong?

V K
  • 1,645
  • 3
  • 26
  • 57
  • Not sure if I understood you... search the properties in the resources for the "OC" entry. i.e. `PDPage.getResources().getProperties(name)`. Is that what you need? – Tilman Hausherr Jul 12 '17 at 12:40
  • Somewhat. I saw the the entry below the OC is the resource name of the layer, hence I searched that resource name and got the OCG object. Thanks. – V K Jul 12 '17 at 12:48
  • Then please answer the question yourself :-) – Tilman Hausherr Jul 12 '17 at 12:49
  • I will answer both the questions, first I need to do some testing. – V K Jul 12 '17 at 12:56
  • Just to correct the obvious: *"I first get a COSName{OC} token, and then I get the BMC command"* - Not a **BMC** but instead a **BDC**; the latter one additionally has a *properties* argument which in case of optional content specifies either an optional content group or optional content membership dictionary to which the content belongs. – mkl Jul 12 '17 at 13:05
  • @mkl It was a typo.Thanks for letting me know. – V K Jul 13 '17 at 14:22

0 Answers0