IRONSOFTWAREHOME
自定义PDF大小

import com.ironsoftware.ironpdf.*;  
import com.ironsoftware.ironpdf.render.*;  
import java.io.IOException;  
import java.nio.file.Paths;

String html = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>";  
  
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();  
renderOptions.setPaperSize(PaperSize.Custom);  
  
/*  
 * Setting page sizes using different measuring units: * 1. setCustomPaperWidth( width ) / setCustomPaperHeight( height ): for inches * 2. setCustomPaperSizeInCentimeters( width, height ): for centimeters. * 3. setCustomPaperSizeInMillimeters( width, height ): for millimeters * 4. setCustomPaperSizeInPixelsOrPoints( width, height ): for pixels/points */renderOptions.setCustomPaperSizeInCentimeters(13.97, 13.97);  
  
PdfDocument.renderHtmlAsPdf(html, renderOptions).saveAs(Paths.get("assets/CustomPaperSize.pdf"));
mvn install
自定义PDF大小

自定义PDF大小

使用IronPDF,开发人员可以生成尺寸不同于标准A4(8½ x 11 英寸,或21.59 x 27.94厘米)的PDF文档。

通过在setPaperSize方法中指定所需尺寸,渲染不同纸张大小的PDF。 在方法参数中设置纸张大小,并使用预设的PaperSize值。 之后,从源内容(HTML字符串、URL、HTML文件等)正常渲染PDF文档。

该PaperSize枚举类型支持超过100种业界认可的打印尺寸。 这为大多数业务场景中使用的尺寸提供了覆盖。 要使用PaperSize.Custom并手动设置所需的页宽和页高:

如上所示,setCustomPaperHeight接受以英寸为单位的数值来表示所需的尺寸。 要使用厘米设置尺寸,请使用setCustomPaperSizeInCentimeters。 要以毫米为单位设置尺寸,请使用setCustomPaperSizeInMillimeters。 对于像素/点,使用setCustomPaperSizeInPixelsOrPoints。

了解有关使用 IronPDF 设置自定义 PDF 大小的更多信息。
在 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

手动安装到您的项目中