翻譯|行業資訊|編輯:胡濤|2024-11-27 10:45:03.130|閱讀 75 次
概述:在本文中,您將學習如何使用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
旋轉以 90 度為增量。您可以將 PDF 頁面旋轉 0/90/180/270 度。以下是旋轉 PDF 頁面的步驟:
[C#]
using Spire.Pdf; namespace RotatePdfPage { class Program { static void Main(string[] args) { //Create a PdfDocument instance PdfDocument pdf = new PdfDocument(); //Load a PDF document pdf.LoadFromFile("Sample.pdf"); //Get the first page PdfPageBase page = pdf.Pages[0]; //Get the original rotation angle of the page int rotation = (int)page.Rotation; //Rotate the page 180 degrees clockwise based on the original rotation angle rotation += (int)PdfPageRotateAngle.RotateAngle180; page.Rotation = (PdfPageRotateAngle)rotation; //Save the result document pdf.SaveToFile("Rotate.pdf"); } } }
[VB.NET]
Imports Spire.Pdf Namespace RotatePdfPage Friend Class Program Private Shared Sub Main(ByVal args As String()) 'Create a PdfDocument instance Dim pdf As PdfDocument = New PdfDocument() 'Load a PDF document pdf.LoadFromFile("Sample.pdf") 'Get the first page Dim page As PdfPageBase = pdf.Pages(0) 'Get the original rotation angle of the page Dim rotation = CInt(page.Rotation) 'Rotate the page 180 degrees clockwise based on the original rotation angle rotation += CInt(PdfPageRotateAngle.RotateAngle180) page.Rotation = CType(rotation, PdfPageRotateAngle) 'Save the result document pdf.SaveToFile("Rotate.pdf") End Sub End Class End Namespace
以下是旋轉 PDF 文檔中所有頁面的步驟:
[C#]
using Spire.Pdf; namespace RotateAllPdfPages { class Program { static void Main(string[] args) { //Create a PdfDocument instance PdfDocument pdf = new PdfDocument(); //Load a PDF document pdf.LoadFromFile("Sample.pdf"); foreach (PdfPageBase page in pdf.Pages) { //Get the original rotation angle of the page int rotation = (int)page.Rotation; //Rotate the page 180 degrees clockwise based on the original rotation angle rotation += (int)PdfPageRotateAngle.RotateAngle180; page.Rotation = (PdfPageRotateAngle)rotation; } //Save the result document pdf.SaveToFile("RotateAll.pdf"); } } }
[VB.NET]
Imports Spire.Pdf Namespace RotateAllPdfPages Friend Class Program Private Shared Sub Main(ByVal args As String()) 'Create a PdfDocument instance Dim pdf As PdfDocument = New PdfDocument() 'Load a PDF document pdf.LoadFromFile("Sample.pdf") For Each page As PdfPageBase In pdf.Pages 'Get the original rotation angle of the page Dim rotation = CInt(page.Rotation) 'Rotate the page 180 degrees clockwise based on the original rotation angle rotation += CInt(PdfPageRotateAngle.RotateAngle180) page.Rotation = CType(rotation, PdfPageRotateAngle) Next 'Save the result document pdf.SaveToFile("RotateAll.pdf") End Sub End Class End Namespace
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢慧都在線客服 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn