Question

Is is possible to remove or hide a layer from a PDF using ABCPdf or another framework?

No correct solution

OTHER TIPS

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);

Or perhaps you were looking for the Flatten() function?

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top