当前位置: 首页 > 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

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

PM> Install-Package Spire.PDF
使用 C# 和 VB.NET 旋转 PDF 中的特定页面

旋转以 90 度为增量。您可以将 PDF 页面旋转 0/90/180/270 度。以下是旋转 PDF 页面的步骤:

  • 创建PdfDocument类的实例。
  • 使用PdfDocument.LoadFromFile()方法加载 PDF 文档。
  • 通过PdfDocument.Pages[pageIndex]属性根据其索引(从零开始)获取所需的页面。
  • 通过PdfPageBase.Rotation属性获取页面原始旋转角度。
  • 将原始旋转角度增加所需的度数。
  • 通过PdfPageBase.Rotation属性将新的旋转角度应用到页面。
  • 使用PdfDocument.SaveToFile()方法保存结果文档。

[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

C#/VB.NET:旋转 PDF 中的页面

使用 C# 和 VB.NET 旋转 PDF 中的所有页面

以下是旋转 PDF 文档中所有页面的步骤:

  • 创建PdfDocument类的实例。
  • 使用PdfDocument.LoadFromFile()方法加载 PDF 文档。
  • 循环遍历文档中的每一页。
  • 通过PdfPageBase.Rotation属性获取页面原始旋转角度。
  • 将原始旋转角度增加所需的度数。
  • 通过PdfPageBase.Rotation属性将新的旋转角度应用到页面。
  • 使用PdfDocument.SaveToFile()方法保存结果文档。

[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

http://www.kler.cn/a/417218.html

相关文章:

  • 私有化部署DeepSeek并SpringBoot集成使用(附UI界面使用教程-支持语音、图片)
  • c++ 浮点数比较判断
  • 【STM32系列】利用MATLAB配合ARM-DSP库设计IIR数字滤波器(保姆级教程)
  • 1-kafka服务端之延时操作前传--时间轮
  • 深入理解k8s中的容器存储接口(CSI)
  • 爬虫学习笔记之Robots协议相关整理
  • Docker化部署Django:高效、可扩展的Web应用部署策略
  • 有效判断住宅IP与机房IP的方法
  • 数据并行、模型并行与张量并行:深度学习中的并行计算策略(中英双语)
  • 试题转excel;试题整理工具;试卷转excel;word转excel
  • 外卖开发(二)开发笔记
  • 【论文阅读】 Learning to Upsample by Learning to Sample
  • 3D Gaussian Splatting综述 论文笔记
  • scala模式匹配
  • Qt 前置课程 QtNFC
  • Android.mk 和Android.bp 设置头文件的命令
  • 黑马2024AI+JavaWeb开发入门Day03-Maven-单元测试飞书作业
  • openharmony 下的 rtos虚拟化方案
  • 基础入门-Web应用架构类别源码类别镜像容器建站模版编译封装前后端分离
  • FinalShell工具数据备份升级、密码解密方法
  • dhcp服务
  • MFC音视频播放器-支持电子放大等功能
  • Monitor 显示器软件开发设计入门二
  • 基于Java Springboot门诊预约之鼻护灵微信小程序
  • 【NLP高频面题 - LLM架构篇】旋转位置编码RoPE相对正弦位置编码有哪些优势?
  • OpenMP出现Stack Overflow及其疑问