IRONSOFTWAREHOME
纵向和横向方向
using IronPdf;

// For NEW PDF Documents use PdfPaperOrientation
// PdfPaperOrientation: To choose Landscape or Portrait Orientation in a new PDF document
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Landscape;

var newPdfFromHtml = renderer.RenderHtmlAsPdf("<h1> Hello World! </h1>");
var newPdfFromHtmlFile = renderer.RenderHtmlFileAsPdf("example.html");
var newPdfFromUrl = renderer.RenderUrlAsPdf("https://ironpdf.com");


// For EXISTING PDFs use PageRotation
// PageRotation : To rotate a PDF page and all of its  its contents
var existingPdf = new PdfDocument("old_report.pdf");

// Get rotation value
var getRotationFirstPage = existingPdf.Pages[0].PageRotation;

// Rotate specified page
existingPdf.SetPageRotation(PageIndex: 0, Rotation: IronPdf.Rendering.PdfPageRotation.Clockwise90);

// Rotate ALL pages
existingPdf.SetAllPageRotations(IronPdf.Rendering.PdfPageRotation.Clockwise270);
Imports IronPdf

' For NEW PDF Documents use PdfPaperOrientation
' PdfPaperOrientation: To choose Landscape or Portrait Orientation in a new PDF document
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Landscape

Dim newPdfFromHtml = renderer.RenderHtmlAsPdf("<h1> Hello World! </h1>")
Dim newPdfFromHtmlFile = renderer.RenderHtmlFileAsPdf("example.html")
Dim newPdfFromUrl = renderer.RenderUrlAsPdf("https://ironpdf.com")


' For EXISTING PDFs use PageRotation
' PageRotation : To rotate a PDF page and all of its  its contents
Dim existingPdf = New PdfDocument("old_report.pdf")

' Get rotation value
Dim getRotationFirstPage = existingPdf.Pages(0).PageRotation

' Rotate specified page
existingPdf.SetPageRotation(PageIndex:=0, Rotation:=IronPdf.Rendering.PdfPageRotation.Clockwise90)

' Rotate ALL pages
existingPdf.SetAllPageRotations(IronPdf.Rendering.PdfPageRotation.Clockwise270)
NuGet Download
PM > Install-Package IronPdf
纵向和横向方向

纵向和横向方向

通常,在创建动态 PDF 文档时,您会发现需要自定义文档的页面方向。 这正是 IronPDF 的 PaperOrientation 派上用场的地方。 该工具允许开发者访问 PdfPaperOrientation 类。 借助此功能,您在将 HTML 或 URL 内容渲染为 PDF 文档时,可选择横向或纵向页面方向。

  • 对于横向布局,请使用:PdfPaperOrientation.Landscape
  • 对于纵向布局,请使用:PdfPaperOrientation.Portrait

如果您正在处理现有的 PDF 文档,可以使用 PageRotation 自定义 PDF 文档的页面方向。 要设置文档内页面的旋转角度,请执行以下操作:

  • 若需旋转 PDF/A 中的特定页面,请使用 SetPageRotation
  • 若需旋转 PDF 文档中的所有页面,请使用 SetAllPageRotations

首先,我们需要确定是使用现有的 PDF 文档,还是渲染一个新的文档。 首先,让我们了解如何设置新渲染的 PDF 文档的页面方向,然后是针对现有 PDF 文档的操作方法。

首先,您需要创建一个新的 ChromePdfRenderer() 实例。 这将处理从 HTML 或 URL 内容创建新 PDF 文档的操作。 接下来,在渲染之前,使用 renderer.RenderingOptions.PaperOrientation 设置纸张方向。 选择 PdfPaperOrientation.Landscape 后,生成的 PDF 将以横向模式显示,而非默认的纵向模式。 我们将采用 RenderHtmlAsPdf 渲染方法,该方法可接收 HTML 字符串并即时将其转换为 PDF。

现在,让我们来看看如何为现有的 PDF 文档设置自定义方向。 首先,我们将一个名为 old_report.pdf 的文件加载到 PdfDocument 对象中,从而访问其中的页面。 使用 Pages[0].PageRotation,您可以检查第一页的旋转状态。 要进行更改,SetPageRotation 会旋转单页,本例中是将第一页顺时针旋转 90 度。

这些示例共同说明了 IronPDF 不仅能从 HTML 和网络源生成精美的 PDF 文件,还提供了强大的工具来调整现有 PDF 文档的页面方向和旋转,从而为 .NET 开发人员简化 PDF 工作流程。

了解有关 PDF 中页面方向与旋转的更多信息。
在 GitHub 上查看

准备开始了吗?

Nuget Downloads 21,105,021版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥。

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

OR
bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥。
无需信用卡或创建账户
C# 用于 PDF 的 NuGet 库
通过 NuGet 安装

版本: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. 在解决方案资源管理器中,右键点击引用,管理 NuGet 包
  2. 选择浏览并搜索 “IronPDF”
  3. 选择包并安装
C# PDF DLL
下载 DLL

版本: 2026.9

或在此处下载 Windows 安装程序。

  1. 下载并解压 IronPDF 到您的解决方案目录中的 ~/Libs 之类的位置
  2. 在 Visual Studio 解决方案资源管理器中,右键点击引用。选择浏览,“IronPDF.dll”

$999 起