C# 设置PDF页面缩放比例

2025-05-14 10:55:55

此经验将分享通过C#编程来设置PDF页面缩放比例的方法。

工具/原料

Free Spire.PDF for .NET(免费版)

dll引用

1、1.通过官网(https://www.e-iceblue.cn/Introduce/Free-Spire-PDF-NET.html)下载安装包--解压-安装。在程序中添加引用Spire.Pdf.dll,dll文件在安装路径下的bin文件夹中。2.通过Nuget官网下载。(http://www.nuget.org/packages/FreeSpire.PDF/)添加引用完成后,如下图:

C# 设置PDF页面缩放比例

C#代码示例

1、using Spire.Pdf;using Spire.Pdf.Actions;using Spire.Pdf.General;using System.Drawing稆糨孝汶;namespace SetZoomFactor_PDF{ class Program { static void Main(string[] args) { //新建PDFDocument示例并加载PDF Sample文档 PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile("sample.pdf"); //获取PDF文档第一页 PdfPageBase page = pdf.Pages[0]; //新建一个PdfDestination对象,该对象包含两个参数,页面及页面显示位置 PdfDestination dest = new PdfDestination(page, new PointF(-60f, -60f)); //设置缩放属性的值 dest.Zoom = 1.5f; //设置打开PDF文档时的页面显示缩放比例 PdfGoToAction gotoaction = new PdfGoToAction(dest); pdf.AfterOpenAction = gotoaction; //保存文档 pdf.SaveToFile("result.pdf", FileFormat.PDF); System.Diagnostics.Process.Start("result.pdf"); } }}

2、页面缩放比例设置结果:

C# 设置PDF页面缩放比例
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢