HI I tried to remove Layer in PDF and save it .
Before savinf the pdf i debugged and checked and lyer is gone .So while in memory i think it is deleted. But when i saved the file i can still see the layer.
Below is the code i used and i tried with multiple files .Its same .
Not sure if i need to accept changes or anything before saving file
private void RemoveLayers(Document document)
{
foreach (var page in document.Pages)
{
// Access the layers collection of the page
var layers = page.Layers;
// Iterate through the layers
for (var i = layers.Count - 1; i >= 0; i--)
{
var layer = layers[i];
// Remove specific layers by name
if (layer.Name == "Varnish 1")
{
layers.Remove(layer);
}
}
page.Accept();
}
var desitnatonPath = "C:\\Mac\\Home\\Desktop\\Projects\\ImpactAnalysis\\Files\\output.pdf";
if (File.Exists(desitnatonPath))
{
File.Delete(desitnatonPath);
}
// Save the updated document
document.Save(desitnatonPath);
}