2

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

Tobias Kienzler
  • 21,611
  • 21
  • 111
  • 204
Junior Developer
  • 151
  • 1
  • 1
  • 4

3 Answers3

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
  • 987
  • 7
  • 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();
0

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

Joshua Drake
  • 2,581
  • 2
  • 34
  • 53