Is is possible to remove or hide a layer from a PDF using ABCPdf or another framework?
            Asked
            
        
        
            Active
            
        
            Viewed 2,471 times
        
    3 Answers
3
            
            
        The following C# example shows how layer 2 of page 1 can be deleted:
Doc theDoc = new Doc();
theDoc.Read("source.pdf");
int thePages = theDoc.GetInfoInt(theDoc.Root, "Pages");
int thePage = theDoc.GetInfoInt(thePages, "Page 1");
int theLayer = theDoc.GetInfoInt(thePage, "Content 2");
theDoc.Delete(theLayer);
        AffineMesh
        
- 1,025
 - 8
 - 14
 
0
            
            
        ABCpdf contains an Example project called OCGLayers. This project shows you how to identify and redact all the items in a layer.
For example:
        Properties props = Properties.FromDoc(_doc, false);
        Page page = (Page)_doc.ObjectSoup[_doc.Page];
        Reader reader = Reader.FromPage(props, page);
        List<OptionalContent.Layer> layers = reader.GetLayers();
        foreach (OptionalContent.Layer layer in layers) {
            if (layer.Visible == false) {
                if (reader == null)
                    reader = Reader.FromPage(props, page);
                Reader.Redact(ref reader, layer);
            }
        }
        UpdateLayers();
        UpdatePreview();
        OnceUponATimeInTheWest
        
- 1,164
 - 8
 - 9