C# PDF Page操作设置页面切换按钮的方法
作者:E-iceblue 发布时间:2021-11-18 04:33:43
标签:C#,PDF,Page
概述
在以下示例中,将介绍在PDF文档页面设置页面切换按钮的方法。示例中将页面切换按钮的添加分为了两种情况,一种是设置按钮跳转到首页、下页、上页或者最后一页,另一种是设置按钮跳转到指定页面。两种方法适应不同的程序设计需要,可自行选择合适的添加方法。
说明
这里的代码示例需要使用类库Spire.PDF for .NET,版本4.0 。在使用该类库时,在项目程序中引用Spire.Pdf.dll即可(dll文件在安装路径下的Bin文件中获取)。
如:
代码操作示例(供参考)
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类支持四种按钮跳转动作
添加效果(截图):
点击文中的按钮时,即可跳转至按钮指向的页面。
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");
}
}
}
添加效果(截图):
点击按钮,即可跳转至指定的文档第3页。
以上所述是小编给大家介绍的C# PDF Page操作设置页面切换按钮的方法网站的支持!
来源:https://www.cnblogs.com/Yesi/p/8979938.html
0
投稿
猜你喜欢
- 前言:mongodb是一个基于分布式文件存储的开源数据库系统。mongodb与我们平常使用的mysql的区别: 1.
- 这篇文章主要介绍了Spring Boot Logback配置日志过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考
- 用来练手还是不错的,分享大家看一下,还是一些新颖点的!哈哈 就是自定义DataGridView,方便每个功能部分调用!简单!再次重
- 一、背景在开发过程中,我们的软件会面对不同的运行环境,比如开发环境、测试环境、生产环境,而我们的软件在不同的环境中,有的配置可能会不一样,比
- 主要介绍:1.任务队列2.拒绝策略(抛出异常、直接丢弃、阻塞、临时队列)3.init( min )4.active5.maxmin<=
- 在Google I/O 2017中,Google 宣布 Kotlin 成为 Android 官方开发语言。为什么选择 Kotlin? 简洁:
- —举例(学生排课)—正常思路的处理方法和优化过后的处理方法:比如说给学生排课。学生和课程是一个多对多的关系。按照正常的逻辑 应该有一个关联表
- 1、背景最近用到了Spring Cloud Alibaba开发微服务,在开发的过程中发现,当我们的服务上线或下线的时候,我们的Spring
- 0. Iochttps://docs.spring.io/spring-framework/docs/current/spring-fram
- 在开发应用过程中,客户端与服务端经常需要进行数据传输,涉及到重要隐私信息时,开发者自然会想到对其进行加密,即使传输过程中被“有心人”截取,也
- 赛马下周一就要去做java实验了,还记得上一次实验还有一个程序没写完,匆匆交了实验报告的半成品(希望老师没发现www)。为了下周一能有更充裕
- 主要区别在于是否延迟加载。load方法不会立即访问数据库,当试图加载的记录不存在时,load方法返回一个未初始化的代理对象。get方法总是立
- C#消息提示框messagebox的详解及使用消息对话框是用messagebox对象的show方法显示的。MessageBox对象是命名空间
- 本文实例讲述了C#实现类似新浪微博长URL转短地址的方法。分享给大家供大家参考。具体如下:一、前台判断用户输入URL的JS代码如下。func
- 前言前段时间因为工作的需要用到Spring事件,翻翻文档将功能实现了,但是存在少许理解不畅的地方,今天有空来梳理梳理。需求背景叶子同学在新入
- 本文基于jdk1.8进行分析。ReentrantLock是一个可重入锁,在ConcurrentHashMap中使用了ReentrantLoc
- Spring boot + Spring data jpa + Thymeleaf批量插入 + POI读取 + 文件上传pom.xml:&l
- 方法的覆盖在类继承中,子类可以修改从父类继承来的方法,也就是说子类能创建一个与父类方法有不同功能的方法,但具有相同的名称、返回值类型、参数列
- PreparedStatement介绍可以通过调用 Connection 对象的 prepareStatement(String sql)
- 一、前言 做过系统参数设置的同学们,肯定遇到过要提供一系列具有相同特点的选项供用户选择。