IRONSOFTWAREHOME
纵向和横向方向

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
纵向和横向方向

纵向和横向方向

Java 版 IronPDF 可以修改新建和现有 PDF 文档的页面方向。 using IronPDF 重新渲染的新 PDF 文档默认使用纵向方向。 开发商可以在将内容(HTML, RTFs, URLs, 等)转换为PDF时,通过一个ChromePdfRenderOptions实例覆盖此行为。 PaperOrientation值,并允许开发人员根据需要更改生成PDF的纸张方向。 示例代码第 21 到 23 行创建了横向设置的 PDF 文档。 在第21行调用带setPaperOrientation触发了方向行为。 用PdfDocument.renderUrlAsPdf的调用采用纵向方向创建IronPDF首页。

ChromePdfRenderOptions 对象不能用于更改现有PDF的页面方向(这些可以是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 天试用密钥。
无需信用卡或创建账户
Java Maven PDF 库
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

手动安装到您的项目中