溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

C# 在PDF頁面添加打印按鈕

發(fā)布時(shí)間:2020-04-06 14:48:36 來源:網(wǎng)絡(luò) 閱讀:1115 作者:E_iceblue 欄目:編程語言

簡(jiǎn)述

在文檔中設(shè)置按鈕給我們提供了一種快速操作文檔的方式,簡(jiǎn)潔省事,應(yīng)用于程序中能夠有效的提升客戶滿意度。在前一篇文章中講述了如何在PDF文檔中設(shè)置頁面的跳轉(zhuǎn)按鈕,包括跳轉(zhuǎn)至指定頁,包括首頁、下一頁、上一頁、最后一頁,同時(shí)也可以自定義跳轉(zhuǎn)頁。本篇文章將介紹如何在PDF文檔頁面中添加打印按鈕。

使用工具

  • Spire.PDF for .NET 版本 4.0
    :安裝該類庫后,注意在項(xiàng)目程序中添加引用Spire.Pdf.dll。dll文件可以在安裝路徑下的Bin文件夾中獲取。

C# 在PDF頁面添加打印按鈕

代碼示例(供參考)
步驟 1 :添加using指令

using Spire.Pdf;
using Spire.Pdf.Fields;
using Spire.Pdf.Graphics;
using System.Drawing;

步驟 2 :加載文檔,獲取指定頁

//加載PDF文檔
PdfDocument doc = new PdfDocument("test.pdf");
doc.AllowCreateForm = true;
//獲取第一頁
PdfPageBase page = doc.Pages[0];

步驟 3 :設(shè)置打印按鈕及其屬性

//在第一頁創(chuàng)建一個(gè)PdfButtonField實(shí)例,并為按鈕設(shè)置屬性
PdfButtonField button = new PdfButtonField(page, "Print");
button.Bounds = new RectangleF(450, 600, 50, 20);
button.BorderColor = new PdfRGBColor(Color.White);
button.BorderStyle = PdfBorderStyle.Solid;
button.ForeColor = new PdfRGBColor(Color.White);
button.BackColor = new PdfRGBColor(Color.LightGray);
button.ToolTip = "Print";
button.Text = "Print";
button.Font = new PdfFont(PdfFontFamily.Helvetica, 9f);

步驟 4 :應(yīng)用按鈕到頁面

//添加打印功能到按鈕
button.AddPrintAction();
//添加按鈕到頁面
doc.Form.Fields.Add(button);

步驟 5 :保存文檔
doc.SaveToFile("Output.pdf");
System.Diagnostics.Process.Start("Output.pdf");

完成代碼后,調(diào)試運(yùn)行程序,生成文檔(如下圖所示)。生成的文檔中,鼠標(biāo)點(diǎn)擊打印按鈕,即可彈出打印對(duì)話框,在對(duì)話框中設(shè)置打印需求,點(diǎn)擊打印即可完成打印。
C# 在PDF頁面添加打印按鈕

(本文完)
如需轉(zhuǎn)載,請(qǐng)注明出處

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI