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 20,809,720版本:2026.9剛剛發布

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
預訂您的免費現場演示
Booking Badge

受到全球數百萬工程師的信任

Iron Software的客戶標誌
獲取您的無義務諮詢
填寫以下表格或電子郵件sales@ironsoftware.com
您的詳細資訊將始終保密
受到全球數百萬工程師的信任
Iron Software的客戶標誌
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立