I have implemented functionality to delete the layer from pdf, but the problem is that, the content that I had drawn on the layer, does not get delete.Here is the code that I am using to delete the layer:
PDDocumentCatalog documentCatalog = doc.getDocumentCatalog();
PDOptionalContentProperties ocgProps = documentCatalog.getOCProperties();
PDOptionalContentGroup ocg = ocgProps.getGroup(markupLayerName);
COSDictionary ocgsDict = (COSDictionary)ocgProps.getCOSObject();
COSArray ocgs = (COSArray)ocgsDict.getItem(COSName.OCGS);
int indexToBeDeleted = -1;
for (int index = 0; index < ocgs.size(); index++)
{
COSBase o = ocgs.get(index);
COSDictionary ocgDict = ToCOSDictionary(o);
if (ocgDict.getString(COSName.NAME) == markupLayerName)
{
indexToBeDeleted = index;
break;
}
}
if (indexToBeDeleted >= 0)
{
cgs.remove(indexToBeDeleted);
ocgsDict.setItem(COSName.OCGS, ocgs);
documentCatalog.setOCProperties(new PDOptionalContentProperties(ocgsDict));
}
To delete the markup data , I hade to modify the PDPage's content.I just searched the contents for BDC and EMC pair, and then searched whether that pair belongs to the concerned layer, if so then I delete that part from the contents.Below is the C# code that I used: