IRONSOFTWAREHOME
Custom PDF Size

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
Custom PDF Size

Custom PDF Size

使用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天試用金鑰。
無需信用卡或帳戶建立
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

手動安裝到您的專案中