PDF管理控件Spire.PDF使用教程:在PDF中添加页面跳转按钮

>>Spire.PDF更新至最新版v5.10.2,欢迎下载体验

在PDF中添加页面跳转按钮

跳转至特殊页(上一页、下一页、首页、最后一页)

//加载PDF文档PdfDocument doc = new PdfDocument();doc.LoadFromFile("C# Tutorials.pdf");//允许添加Formdoc.AllowCreateForm = true;//获取最后一页PdfPageBase lastPage = doc.Pages[doc.Pages.Count - 1];//在页面指定位置添加按钮PdfButtonField button = new PdfButtonField(lastPage, "返回首页");button.Bounds = new RectangleF(lastPage.ActualSize.Width - 110, lastPage.ActualSize.Height - 250, 60, 20);//设置按钮边框颜色button.BorderStyle = PdfBorderStyle.Solid;button.BorderColor = new PdfRGBColor(Color.LightPink);//设置按钮背景色button.BackColor = Color.Green;//设置按钮提示语       button.ToolTip = "点击此处返回首页";//设置按钮文字字体和颜色      PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(new Font("宋体", 10f), 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);

PDF管理控件Spire.PDF使用教程:在PDF中添加页面跳转按钮

跳转至指定页

//加载PDF文档PdfDocument doc = new PdfDocument();doc.LoadFromFile("C# Tutorials.pdf");//允许添加Formdoc.AllowCreateForm = true;//获取最后一页PdfPageBase lastPage = doc.Pages[doc.Pages.Count - 1];//在页面指定位置添加按钮PdfButtonField button = new PdfButtonField(lastPage, "返回至第三页");button.Bounds = new RectangleF(lastPage.ActualSize.Width - 150, lastPage.ActualSize.Height - 250, 100, 20);//设置按钮边框颜色button.BorderStyle = PdfBorderStyle.Solid;button.BorderColor = new PdfRGBColor(Color.LightPink);//设置按钮背景色button.BackColor = Color.LightBlue;//设置按钮提示语       button.ToolTip = "点击此处返回至第三页";//设置按钮文字字体和颜色      PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(new Font("宋体", 10f), true);button.Font = trueTypeFont;button.ForeColor = Color.Black;//实例化PdfDestination对象,传入指定页码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);

PDF管理控件Spire.PDF使用教程:在PDF中添加页面跳转按钮

*10月狂欢季,万元礼包邀您来领!想要购买Spire.PDF正版授权的朋友可以联系客服哦~

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年9月15日
下一篇 2019年9月15日

相关推荐

发表回复

登录后才能评论