翻譯|行業資訊|編輯:胡濤|2024-09-29 13:51:11.743|閱讀 80 次
概述:在本文中,我們將演示如何使用Spire.PDF for .NET在 C# 和 VB.NET 中為 PDF 文檔設置查看器首選項和縮放因子。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
優化查看器首選項和縮放因子對于改善 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 包中包含的 DLL 文件作為引用添加到您的 .NET 項目中。 可以從此鏈接下載 DLL 文件,也可以通過NuGet安裝。
PM> Install-Package Spire.PDF
查看器首選項是可應用于 PDF 文檔的設置,用于控制在 PDF 查看器中打開時文檔的顯示方式。這些首選項會影響查看體驗的各個方面,例如初始視圖、頁面布局和導航選項卡。
要使用 Spire.PDF for .NET 設置 PDF 文檔的查看器首選項,您可以按照以下步驟操作:
【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
縮放系數決定了 PDF 文檔打開時的縮放級別。默認情況下,大多數 PDF 查看器將縮放系數設置為“適合頁面”,即縮放文檔以適合查看器窗口的寬度。但是,您也可以根據需要設置特定的縮放系數,例如 60%、150% 或 200%。
要使用 Spire.PDF for .NET 設置 PDF 文檔的縮放比例,您可以按照以下步驟操作:
【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
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn