IRONSOFTWAREHOME
Portrait & Landscape Orientation

import com.ironsoftware.ironpdf.PdfDocument;  
import com.ironsoftware.ironpdf.edit.PageSelection;  
import com.ironsoftware.ironpdf.page.PageRotation;  
import com.ironsoftware.ironpdf.render.*;  
import java.io.IOException;  
import java.nio.file.Paths;

// Use the setPaperOrientation method to set rendered PDFs in portrait or landscape orientation.  
// Note: This will only work for newly-created PDFs!  
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();  
renderOptions.setPaperOrientation(PaperOrientation.LANDSCAPE);  
PdfDocument newPdf = PdfDocument.renderUrlAsPdf("https://ironpdf.com", renderOptions);  
newPdf.saveAs(Paths.get("assets/LandscapePdf.pdf"));  
  
// Use the rotatePage/rotateAllPages methods to adjust the page orientation for existing PDFs  
PdfDocument existingPdf = PdfDocument.fromFile(Paths.get("assets/example.pdf"));  
  
// Get the orientation of the first page of the existing PDF document.  
PageRotation firstPageRotation = existingPdf.getPagesInfo().get(0).getPageRotation();  
System.out.println(firstPageRotation);  
  
// Rotate the first page of the document only 90 degrees clockwise.  
existingPdf.rotatePage(PageRotation.CLOCKWISE_90, PageSelection.firstPage());  
  
// Rotate all pages of the document clockwise.  
existingPdf.rotateAllPages(PageRotation.CLOCKWISE_270);  
  
existingPdf.saveAs(Paths.get("assets/ExistingPdfRotated.pdf"));
mvn install
Portrait & Landscape Orientation

Portrait & Landscape Orientation

IronPDF for Java可以修改新建和現有PDF文件的頁面方向。

使用IronPDF重新渲染的新PDF文件預設為縱向方向。 開發者可以在將內容(HTML、RTFs、URLs等)轉換為PDF時,透過ChromePdfRenderOptions實例覆蓋此行為。 PaperOrientation值,允許開發者根據需要更改生成的PDF的紙張方向。 特徵程式碼範例中的第21至23行建立了一個橫向方向的PDF文件。 在第21行,調用PaperOrientation.LANDSCAPE會觸發方向行為。 將枚舉值替換為PdfDocument.renderUrlAsPdf的呼叫將建立IronPDF首頁,呈現為縱向方向。

PdfDocument.fromFile方法載入到IronPDF中)。 對於這些PDF文件,可以使用基於旋轉的轉換來調整頁面方向。 為此,IronPDF提供了可用的rotateAllPages方法。

PageRotation枚舉型別,該型別指定了一組接受的旋轉值。 特徵程式碼範例中的第40行將工作中的PDF文件中的每個頁面順時鐘旋轉270度。 要旋轉PDF中的單頁(或多頁),請使用rotateAllPages。

Learn more about PaperOrientation in IronPDF for Java.
在 GitHub 查看

準備好開始了嗎?

版本:2026.6剛剛發布

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天試用金鑰。
無需信用卡或帳戶建立
PDF的Java Maven程式庫
using Maven 安裝

版本: 2026.6

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.6.1</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.6.1
or
Java PDF JAR
下載 JAR

版本: 2026.6

手動安裝到您的專案中