国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > C# > 正文

C# PDF Page操作設(shè)置頁(yè)面切換按鈕的方法

2020-01-24 00:18:30
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

概述

在以下示例中,將介紹在PDF文檔頁(yè)面設(shè)置頁(yè)面切換按鈕的方法。示例中將頁(yè)面切換按鈕的添加分為了兩種情況,一種是設(shè)置按鈕跳轉(zhuǎn)到首頁(yè)、下頁(yè)、上頁(yè)或者最后一頁(yè),另一種是設(shè)置按鈕跳轉(zhuǎn)到指定頁(yè)面。兩種方法適應(yīng)不同的程序設(shè)計(jì)需要,可自行選擇合適的添加方法。

說(shuō)明

這里的代碼示例需要使用類庫(kù)Spire.PDF for .NET,版本4.0 。在使用該類庫(kù)時(shí),在項(xiàng)目程序中引用Spire.Pdf.dll即可(dll文件在安裝路徑下的Bin文件中獲取)。

如:

代碼操作示例(供參考)

1.跳轉(zhuǎn)至特定頁(yè)(首頁(yè)、下一頁(yè)、上一頁(yè)、最后一頁(yè))

【C#】

using Spire.Pdf;using Spire.Pdf.Actions;using Spire.Pdf.Fields;using Spire.Pdf.Graphics;using System.Drawing;namespace ButtonToAppointedPage_PDF{ class Program { static void Main(string[] args) {  //實(shí)例化PdfDocument類,加載PDF測(cè)試F文檔  PdfDocument doc = new PdfDocument();  doc.LoadFromFile("sample.pdf");  //允許添加Form  doc.AllowCreateForm = true;  //獲取文檔最后一頁(yè)  PdfPageBase lastPage = doc.Pages[doc.Pages.Count - 1];  //在頁(yè)面指定位置添加指定大小的按鈕  PdfButtonField button = new PdfButtonField(lastPage, "Click To Back ");  button.Bounds = new RectangleF(lastPage.ActualSize.Width - 150, lastPage.ActualSize.Height - 400, 60, 20);  //設(shè)置按鈕邊框顏色  button.BorderStyle = PdfBorderStyle.Solid;  button.BorderColor = new PdfRGBColor(Color.White);  //設(shè)置按鈕背景色  button.BackColor = Color.Azure;  //設(shè)置按鈕提示語(yǔ)   button.ToolTip = "To the first page";  //設(shè)置按鈕文字字體和顏色   PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(new Font("Avant Garde", 9f), true);  button.Font = trueTypeFont;  button.ForeColor = Color.Black;  //創(chuàng)建PdfNamedAction實(shí)例,在傳入的參數(shù)中選擇上一頁(yè)、下一頁(yè)、首頁(yè)或最后一頁(yè)  PdfNamedAction namedAction = new PdfNamedAction(PdfActionDestination.FirstPage);  //應(yīng)用動(dòng)作  button.Actions.MouseDown = namedAction;  //添加按鈕到文檔  doc.Form.Fields.Add(button);  //保存并打開(kāi)PDF文檔  doc.SaveToFile("result.pdf", FileFormat.PDF);  System.Diagnostics.Process.Start("result.pdf"); } }}

PS:這里的PdfNameAction類支持四種按鈕跳轉(zhuǎn)動(dòng)作

添加效果(截圖):

點(diǎn)擊文中的按鈕時(shí),即可跳轉(zhuǎn)至按鈕指向的頁(yè)面。

2.跳轉(zhuǎn)至指定頁(yè)面

【C#】

using Spire.Pdf;using Spire.Pdf.Actions;using Spire.Pdf.Fields;using Spire.Pdf.General;using Spire.Pdf.Graphics;using System.Drawing;namespace Buttom2{ class Program { static void Main(string[] args) {  //實(shí)例化PdfDocument類,加載PDF文檔  PdfDocument doc = new PdfDocument();  doc.LoadFromFile("sample.pdf");  //允許添加Form  doc.AllowCreateForm = true;  //獲取最后一頁(yè)  PdfPageBase lastPage = doc.Pages[doc.Pages.Count - 1];  //在頁(yè)面指定位置添加按鈕  PdfButtonField button = new PdfButtonField(lastPage, "Back");  button.Bounds = new RectangleF(lastPage.ActualSize.Width - 150, lastPage.ActualSize.Height - 700, 50, 20);  //設(shè)置按鈕邊框顏色  button.BorderStyle = PdfBorderStyle.Solid;  button.BorderColor = new PdfRGBColor(Color.Transparent);  //設(shè)置按鈕背景色  button.BackColor = Color.WhiteSmoke;  //設(shè)置按鈕提示語(yǔ)   button.ToolTip = "Click and back to the third page";  //設(shè)置按鈕文字字體和顏色   PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(new Font("Avant Garde", 9f), true);  button.Font = trueTypeFont;  button.ForeColor = Color.Black;  //實(shí)例化PdfDestination對(duì)象,傳入指定頁(yè)碼到第3頁(yè)  PdfDestination destination = new PdfDestination(doc.Pages[2]);  //創(chuàng)建go to動(dòng)作  PdfGoToAction goToAction = new PdfGoToAction(destination);  //應(yīng)用動(dòng)作  button.Actions.MouseDown = goToAction;  //添加按鈕到文檔  doc.Form.Fields.Add(button);  //保存并打開(kāi)PDF文檔  doc.SaveToFile("result.pdf", FileFormat.PDF);  System.Diagnostics.Process.Start("result.pdf"); } }}

添加效果(截圖):

點(diǎn)擊按鈕,即可跳轉(zhuǎn)至指定的文檔第3頁(yè)。

以上所述是小編給大家介紹的C# PDF Page操作設(shè)置頁(yè)面切換按鈕的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 舒兰市| 巧家县| 繁昌县| 开江县| 隆化县| 玉田县| 泸定县| 富平县| 青阳县| 山东| 界首市| 哈巴河县| 和政县| 商都县| 南木林县| 偏关县| 宁波市| 禹州市| 乌拉特后旗| 滦平县| 敦煌市| 博客| 高安市| 安溪县| 合江县| 济阳县| 大理市| 洛宁县| 博乐市| 葫芦岛市| 叙永县| 岚皋县| 蒙山县| 罗山县| 云南省| 东至县| 青州市| 大新县| 涞水县| 天长市| 阳东县|