C#PDFPage操作如何设置页面切换按钮-创新互联

这篇文章主要介绍C# PDF Page操作如何设置页面切换按钮,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

创新互联专注于鼓楼网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供鼓楼营销型网站建设,鼓楼网站制作、鼓楼网页设计、鼓楼网站官网定制、小程序定制开发服务,打造鼓楼网络公司原创品牌,更为您提供鼓楼网站排名全网营销落地服务。

说明

这里的代码示例需要使用类库Spire.PDF for .NET,版本4.0 。在使用该类库时,在项目程序中引用Spire.Pdf.dll即可(dll文件在安装路径下的Bin文件中获取)。

如:

C# PDF Page操作如何设置页面切换按钮

代码操作示例(供参考)

1.跳转至特定页(首页、下一页、上一页、最后一页)

【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)
 {
  //实例化PdfDocument类,加载PDF测试F文档
  PdfDocument doc = new PdfDocument();
  doc.LoadFromFile("sample.pdf");
  //允许添加Form
  doc.AllowCreateForm = true;
  //获取文档最后一页
  PdfPageBase lastPage = doc.Pages[doc.Pages.Count - 1];
  //在页面指定位置添加指定大小的按钮
  PdfButtonField button = new PdfButtonField(lastPage, "Click To Back ");
  button.Bounds = new RectangleF(lastPage.ActualSize.Width - 150, lastPage.ActualSize.Height - 400, 60, 20);
  //设置按钮边框颜色
  button.BorderStyle = PdfBorderStyle.Solid;
  button.BorderColor = new PdfRGBColor(Color.White);
  //设置按钮背景色
  button.BackColor = Color.Azure;
  //设置按钮提示语 
  button.ToolTip = "To the first page";
  //设置按钮文字字体和颜色 
  PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(new Font("Avant Garde", 9f), true);
  button.Font = trueTypeFont;
  button.ForeColor = Color.Black;
  //创建PdfNamedAction实例,在传入的参数中选择上一页、下一页、首页或最后一页
  PdfNamedAction namedAction = new PdfNamedAction(PdfActionDestination.FirstPage);
  //应用动作
  button.Actions.MouseDown = namedAction;
  //添加按钮到文档
  doc.Form.Fields.Add(button);
  //保存并打开PDF文档
  doc.SaveToFile("result.pdf", FileFormat.PDF);
  System.Diagnostics.Process.Start("result.pdf");
 }
 }
}

PS:这里的PdfNameAction类支持四种按钮跳转动作

C# PDF Page操作如何设置页面切换按钮

添加效果(截图):

C# PDF Page操作如何设置页面切换按钮

点击文中的按钮时,即可跳转至按钮指向的页面。

2.跳转至指定页面

【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)
 {
  //实例化PdfDocument类,加载PDF文档
  PdfDocument doc = new PdfDocument();
  doc.LoadFromFile("sample.pdf");
  //允许添加Form
  doc.AllowCreateForm = true;
  //获取最后一页
  PdfPageBase lastPage = doc.Pages[doc.Pages.Count - 1];
  //在页面指定位置添加按钮
  PdfButtonField button = new PdfButtonField(lastPage, "Back");
  button.Bounds = new RectangleF(lastPage.ActualSize.Width - 150, lastPage.ActualSize.Height - 700, 50, 20);
  //设置按钮边框颜色
  button.BorderStyle = PdfBorderStyle.Solid;
  button.BorderColor = new PdfRGBColor(Color.Transparent);
  //设置按钮背景色
  button.BackColor = Color.WhiteSmoke;
  //设置按钮提示语 
  button.ToolTip = "Click and back to the third page";
  //设置按钮文字字体和颜色 
  PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(new Font("Avant Garde", 9f), true);
  button.Font = trueTypeFont;
  button.ForeColor = Color.Black;
  //实例化PdfDestination对象,传入指定页码到第3页
  PdfDestination destination = new PdfDestination(doc.Pages[2]);
  //创建go to动作
  PdfGoToAction goToAction = new PdfGoToAction(destination);
  //应用动作
  button.Actions.MouseDown = goToAction;
  //添加按钮到文档
  doc.Form.Fields.Add(button);
  //保存并打开PDF文档
  doc.SaveToFile("result.pdf", FileFormat.PDF);
  System.Diagnostics.Process.Start("result.pdf");
 }
 }
}

添加效果(截图):

C# PDF Page操作如何设置页面切换按钮

点击按钮,即可跳转至指定的文档第3页。

以上是“C# PDF Page操作如何设置页面切换按钮”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联成都网站设计公司行业资讯频道!

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

网页题目:C#PDFPage操作如何设置页面切换按钮-创新互联
文章链接:https://www.cdcxhl.com/article48/dsddep.html

成都网站建设公司_创新互联,为您提供做网站微信公众号域名注册品牌网站制作外贸网站建设网站排名

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

小程序开发