当我们创建pdf图层时,spire.pdf允许开发人员将该层设置初始可见性状态。同时它还支持设置pdf图层可见属性。本文将详细介绍如何使用c#显示或隐藏现有的pdf图层。
我们可以通过设置pdflayer.visibility 属性来设置图层隐藏或显示. 显示图层需要将 pdflayer.visibility 设置为 pdfvisibility.on. 隐藏图层需要将pdflayer.visibility 设置为pdfvisibility.off.
按索引或名称隐藏图层:
c#
//加载示例文档
pdfdocument doc = new pdfdocument();
doc.loadfromfile("addlayers.pdf");
//隐藏第一个图层
doc.layers[0].visibility = pdfvisibility.off;
//隐藏名为blue line的图层
doc.layers["blue line"].visibility = pdfvisibility.off;
//保存文档
doc.savetofile("hidelayer.pdf");
vb.net
'加载示例文档
dim doc as new pdfdocument()
doc.loadfromfile("addlayers.pdf")
'隐藏第一个图层
doc.layers(0).visibility = pdfvisibility.off
'隐藏名为blue line的图层
doc.layers("blue line").visibility = pdfvisibility.off
'保存文档
doc.savetofile("hidelayer.pdf")
显示或隐藏所有图层:
c#
//加载示例文档
pdfdocument doc = new pdfdocument();
doc.loadfromfile("addlayers.pdf");
for (int i = 0; i < doc.layers.count; i )
{
//显示所有图层
//doc.layers[i].visibility = pdfvisibility.on;
//隐藏所有图层
doc.layers[i].visibility = pdfvisibility.off;
}
//保存文档
doc.savetofile("hidealllayers.pdf");
vb.net
'加载示例文档
dim doc as new pdfdocument()
doc.loadfromfile("addlayers.pdf")
for i as integer = 0 to doc.layers.count - 1
'显示所有图层
'doc.layers[i].visibility = pdfvisibility.on;
'隐藏所有图层
doc.layers(i).visibility = pdfvisibility.off
next
'保存文档
doc.savetofile("hidealllayers.pdf")