当前位置: 首页 > article >正文

Spire.PDF for .NET【页面设置】演示:设置 PDF 的查看器首选项和缩放系数

优化查看器首选项和缩放因子对于改善 PDF 文档的查看体验至关重要。通过使用适当的查看器首选项和缩放因子,您可以使您的 PDF 文档更加用户友好、可查看且适合不同的设备和平台。在本文中,我们将演示如何使用Spire.PDF for .NET在 C# 和 VB.NET 中为 PDF 文档设置查看器首选项和缩放因子。

Spire.PDF for .NET 是一款独立 PDF 控件,用于 .NET 程序中创建、编辑和操作 PDF 文档。使用 Spire.PDF 类库,开发人员可以新建一个 PDF 文档或者对现有的 PDF 文档进行处理,且无需安装 Adobe Acrobat。

E-iceblue 功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式

安装 Spire.PDF for .NET

首先,您需要将 Spire.PDF for.NET 包中包含的 DLL 文件作为引用添加到您的 .NET 项目中。 可以从此链接下载 DLL 文件,也可以通过NuGet安装。

PM> Install-Package Spire.PDF
在 C# 和 VB.NET 中设置 PDF 查看器首选项

查看器首选项是可应用于 PDF 文档的设置,用于控制在 PDF 查看器中打开时文档的显示方式。这些首选项会影响查看体验的各个方面,例如初始视图、页面布局和导航选项卡。

要使用 Spire.PDF for .NET 设置 PDF 文档的查看器首选项,您可以按照以下步骤操作:

  • 初始化PdfDocument类的实例。
  • 使用PdfDocument.LoadFromFile()方法加载 PDF 文档。
  • 获取PdfViewerPreferences对象。
  • 使用PdfViewerPreferences类提供的属性设置文档的查看器首选项。
  • 使用PdfDocument.SaveToFile()方法保存结果文档。

【C# 】

using Spire.Pdf;

namespace SetViewerPreference
{
internal class Program
{
static void Main(string[] args)
{
//Initialize an instance of PdfDocument class
PdfDocument pdf = new PdfDocument();
//Load a PDF document
pdf.LoadFromFile(@"Example.pdf");

//Get the PdfViewerPreferences object
PdfViewerPreferences viewerPreferences = pdf.ViewerPreferences;

//Set viewer preference
viewerPreferences.FitWindow = false;
viewerPreferences.HideMenubar = true;
viewerPreferences.HideToolbar = true;
viewerPreferences.CenterWindow= true;
viewerPreferences.DisplayTitle = false;
viewerPreferences.PageLayout = PdfPageLayout.SinglePage;
viewerPreferences.PageMode = PdfPageMode.UseNone;

//Save the result document
pdf.SaveToFile("SetViewerPreference.pdf");
pdf.Close();
}
}
}

【VB.NET 】

Imports Spire.Pdf

Namespace SetViewerPreference
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Initialize an instance of PdfDocument class
Dim pdf As PdfDocument = New PdfDocument()
'Load a PDF document
pdf.LoadFromFile("Example.pdf")

'Get the PdfViewerPreferences object
Dim viewerPreferences As PdfViewerPreferences = pdf.ViewerPreferences

'Set viewer preference
viewerPreferences.FitWindow = False
viewerPreferences.HideMenubar = True
viewerPreferences.HideToolbar = True
viewerPreferences.CenterWindow = True
viewerPreferences.DisplayTitle = False
viewerPreferences.PageLayout = PdfPageLayout.SinglePage
viewerPreferences.PageMode = PdfPageMode.UseNone

'Save the result document
pdf.SaveToFile("SetViewerPreference.pdf")
pdf.Close()
End Sub
End Class
End Namespace

C#/VB.NET:设置 PDF 的查看器首选项和缩放系数

在 C# 和 VB.NET 中设置 PDF 的缩放比例

缩放系数决定了 PDF 文档打开时的缩放级别。默认情况下,大多数 PDF 查看器将缩放系数设置为“适合页面”,即缩放文档以适合查看器窗口的宽度。但是,您也可以根据需要设置特定的缩放系数,例如 60%、150% 或 200%。

要使用 Spire.PDF for .NET 设置 PDF 文档的缩放比例,您可以按照以下步骤操作:

  • 初始化PdfDocument类的实例。
  • 使用PdfDocument.LoadFromFile()方法加载 PDF 文档。
  • 使用PdfDocument.Pages[int index]属性获取特定页面。
  • 初始化PdfDestination类的实例。
  • 使用PdfDestination.ModePdfDestination.LocationPdfDestination.Zoom属性设置目标模式、位置和缩放比例。
  • 初始化PdfGoToAction类的实例,并将PdfDestination实例作为参数传递给该类的构造函数。
  • 使用PdfDocument.AfterOpenAction属性设置打开文档时要执行的操作。
  • 使用PdfDocument.SaveToFile()方法保存结果文档。

【C# 】

using Spire.Pdf;
using Spire.Pdf.Actions;
using Spire.Pdf.General;
using System.Drawing;

namespace SetZoomFactor
{
internal class Program
{
static void Main(string[] args)
{
//Initialize an instance of the PdfDocument class
PdfDocument pdf = new PdfDocument();
//Load a PDF document
pdf.LoadFromFile(@"Example.pdf");

//Get the first page
PdfPageBase page = pdf.Pages[0];

//Initialize an instance of the PdfDestination class
PdfDestination dest = new PdfDestination(page);
//Set the destination mode
dest.Mode = PdfDestinationMode.Location;
//Set the destination location
dest.Location = new PointF(40f, 40f);
//Set the zoom factor
dest.Zoom = 1.5f;

//Initialize an instance of the PdfGoToAction class
PdfGoToAction gotoAction = new PdfGoToAction(dest);
//Set the action to be executed when the document is opened
pdf.AfterOpenAction = gotoAction;

//Save the result document
pdf.SaveToFile("SetZoomFactor.pdf");
pdf.Close();
}
}
}

【VB.NET 】

Imports Spire.Pdf
Imports Spire.Pdf.Actions
Imports Spire.Pdf.General
Imports System.Drawing

Namespace SetZoomFactor
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Initialize an instance of the PdfDocument class
Dim pdf As PdfDocument = New PdfDocument()
'Load a PDF document
pdf.LoadFromFile("Example.pdf")

'Get the first page
Dim page As PdfPageBase = pdf.Pages(0)

'Initialize an instance of the PdfDestination class
Dim dest As PdfDestination = New PdfDestination(page)
'Set the destination mode
dest.Mode = PdfDestinationMode.Location
'Set the destination location
dest.Location = New PointF(40F, 40F)
'Set the zoom factor
dest.Zoom = 1.5F

'Initialize an instance of the PdfGoToAction class
Dim gotoAction As PdfGoToAction = New PdfGoToAction(dest)
'Set the action to be executed when the document is opened
pdf.AfterOpenAction = gotoAction

'Save the result document
pdf.SaveToFile("SetZoomFactor.pdf")
pdf.Close()
End Sub
End Class
End Namespace

C#/VB.NET:设置 PDF 的查看器首选项和缩放系数


http://www.kler.cn/news/335119.html

相关文章:

  • o1-preview 在 IMO 2024 第一题的实测表现
  • 系统架构设计师论文《论SOA在企业集成架构设计中的应用》精选试读
  • javaScript数组(16个案例+代码+效果图)
  • 安装配置pytorch(cuda、、cudnn、torch、torchvision对应版本)
  • 大数据利器Hadoop:从基础到实战,一篇文章掌握大数据处理精髓!
  • 已解决:org.springframework.web.HttpMediaTypeNotAcceptableException
  • 免费!推荐10个可商用模特图片素材网站!
  • 实现Xshell与虚拟机中Linux服务器的连接(附常见错误解决)
  • vite学习教程06、vite.config.js配置
  • 54.二叉树的最大深度
  • 全栈开发从未如此轻松:Bolt.new 让 AI 助力编程体验
  • 药物识别与分类系统源码分享
  • c#代码介绍23种设计模式_19状态者模式
  • 【WPF开发】超级详细的“文件选择”(附带示例工程)
  • 华为手机连接蓝牙音响后播放声音小的问题分析
  • RCE+[伪协议综合]
  • 图像转3D视差视频:DepthFlow
  • Linux Cent7 已安装MySQL5.7.X,再安装MYSQL8.4.2
  • 视频加字幕免费软件哪个好用?详细介绍6款字幕编辑软件的优缺点!码住!
  • 网络威胁情报技术的进步