您的位置:首页 > 其它

Spire.PDF 教程:在C#中显示或隐藏PDF图层

2017-11-01 00:00 786 查看
摘要: Spire.PDF 是一个专业的PDF组件,能够独立地创建、编写、编辑、操作和阅读PDF文件,支持 .NET、WPF和Silverlight三个版本,本文介绍了如何在C#中显示或隐藏PDF图层。

创建PDF图层时,Spire.PDF允许开发人员为图层设置初始的可见性状态。 同时它还支持更改PDF文档中现有图层的可见性。 本文介绍如何使用Spire.PDF显示或隐藏现有图层。

PdfLayer.Visibility属性用于更改PDF图层的可见性,要显示隐藏层,请将PdfLayer.Visibility属性设置为PdfVisibility.On。 要隐藏现有图层,请将PdfLayer.Visibility设置为PdfVisibility.Off.

以下示例显示如何隐藏特定的PDF图层:

using (PdfDocument doc = new PdfDocument("AddLayers.pdf"))
{
//Hide the layer by index
doc.Layers[1].Visibility = PdfVisibility.Off;

//Hide the layer by Name
//doc.Layers["BlueLine"].Visibility = PdfVisibility.Off;

//Save the file
doc.SaveToFile("HideLayer.pdf");
}

显示或隐藏所有图层:

using (PdfDocument doc = new PdfDocument("AddLayers.pdf"))
{
for (int i = 0; i < doc.Layers.Count; i++)
{
//Show all of the layers
//doc.Layers[i].Visibility = PdfVisibility.On;

//Hide all of the layers
doc.Layers[i].Visibility = PdfVisibility.Off;
}
//Save the file
doc.SaveToFile("HideAllLayers.pdf");
}

示例PDF文档的屏幕快照:



隐藏所有图层后的屏幕截图:



慧都控件网
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息