I am trying to load a pdf and remove layers from it. I use the code below.
The layer is removed from the layers panel but the layer content still mains visible on the page.
- Code: Select all
doc.Layers.RemoveLayer("LIMITS",true);
doc.Layers.RemoveLayer("LIMITS",true);
PdfDocument doc = new PdfDocument();
string virtualFolder1 = "~/content/templatefiles/";
string physicalFolder1 = System.Web.HttpContext.Current.Server.MapPath(virtualFolder1);
string NewFileName1 = physicalFolder1 + "\\CAD.pdf";
doc.LoadFromFile(NewFileName1);
string[] layerNames = new string[] { "LIMITS", "HYD", "HYDLINE" };
for (int i = 0; i < doc.Layers.Count; i++)
{
if (layerNames.Contains(doc.Layers[i].Name))
{
doc.Layers.RemoveLayer(doc.Layers[i], true);
}
}
string virtualFolder = "~/temp/";
string physicalFolder = System.Web.HttpContext.Current.Server.MapPath(virtualFolder);
string FileID = Guid.NewGuid().ToString();
string NewFileName = physicalFolder + "\\temp_" + FileID + ".pdf";
doc.SaveToFile(NewFileName);
doc.SaveToHttpResponse(NewFileName, System.Web.HttpContext.Current.Response, HttpReadType.Open);
doc.Dispose();
return NewFileName;