Welcome to the ASP.NET Core feedback portal. We’re happy you’re here! If you have feedback on how to improve the ASP.NET Core, we’d love to hear it!

  • Check out the features or bugs others have reported and vote on your favorites. Feedback will be prioritized based on popularity.
  • If you have feedback that’s not listed yet, submit your own.

Thanks for joining our community and helping improve Syncfusion products!

2
Votes

Minimum working example

//Load the existing PDF document

using var samplePdf = new FileStream("Sample.pdf", FileMode.Open, FileAccess.Read);

using var document = new PdfLoadedDocument(samplePdf);

// Clear each page's layers

foreach (PdfLoadedPage page in document.Pages)

    //Remove the layers 

    page.Layers.Clear();

}

//Save the document

using var samplePdf2 = new FileStream("Sample_ClearedLayers.pdf", FileMode.Create, FileAccess.Write);

document.Save(samplePdf2);

I have inspected the method and noticed that the m_page is set to null but used as an early return condition.

// Summary:

// Clears layers from the Syncfusion.Pdf.PdfPageLayerCollection.

public void Clear()

{

    int i = 0;

    for (int count = base.List.Count; i < count; i++)

    {

        PdfPageLayer layer = this[i];

        RemoveLayer(layer);

        m_page = null; // <- should probably be set after the for-loop

    }

    base.List.Clear();}

// Summary:

// Removes layer from the page.

// Parameters:

// layer:

// The layer.

private void RemoveLayer(PdfPageLayer layer)

{

    if (layer == null)

    {

        throw new ArgumentNullException("layer not to be null");

    }

    PdfDictionary pdfDictionary = null;

    if (m_page == null)

    {

        return; // <- early return that causes only the first layer being removed

    }

    // ...

}

After calling Clear() the layer collection itself thinks it has no layers, but the saved pdf at the end still has 2 layers.