PDF組件Spire.PDF 教程:在C#中切換PDF層的可見性

咱們能夠經過Spire.PDF 的幫助來切換PDF圖層的可見性,同時建立新的頁面層。html

Step 1:建立一個新的PDF文檔,並向PDF文檔添加一個新頁面。orm

PdfDocument pdf = new PdfDocument();
PdfPageBase page = pdf.Pages.Add();

Step 2:將一個名爲「藍線」的圖層添加到PDF頁面,並將圖層設置爲不可見。htm

PdfPageLayer layer = page.PageLayers.Add("Blue line", false);
layer.Graphics.DrawLine(new PdfPen(PdfBrushes.Blue, 1), new PointF(0, 30), new PointF(300, 30));

Step 3:將一個名爲「橢圓」的圖層添加到PDF頁面,並將圖層設置爲可見。blog

layer = page.PageLayers.Add("Ellipse", true);
PdfPen pen = new PdfPen(Color.Green, 1f);
PdfBrush brush = new PdfSolidBrush(Color.Green);
layer.Graphics.DrawEllipse(pen, brush, 50, 70, 200, 60);

Step 4:將文檔保存到文件。圖片

pdf.SaveToFile("LayerVisibility.pdf", FileFormat.PDF);

效果截圖:ip

圖片1

完整代碼:文檔

static void Main(string[] args)
{
 
    PdfDocument pdf = new PdfDocument();
    PdfPageBase page = pdf.Pages.Add();
 
    PdfPageLayer layer = page.PageLayers.Add("Blue line", false);
    layer.Graphics.DrawLine(new PdfPen(PdfBrushes.Blue, 1), new PointF(0, 30), new PointF(300, 30));
 
    layer = page.PageLayers.Add("Ellipse", true);
    PdfPen pen = new PdfPen(Color.Green, 1f);
    PdfBrush brush = new PdfSolidBrush(Color.Green);
    layer.Graphics.DrawEllipse(pen, brush, 50, 70, 200, 60);
     
    pdf.SaveToFile("LayerVisibility.pdf", FileFormat.PDF);
             
}

慧都控件網get

相關文章
相關標籤/搜索