自訂 PDF 尺寸

使用IronPDF,開發人員可以生成尺寸不同於標準A4(8½ × 11英寸或21.59 × 27.94厘米)的PDF文件。

使用setPaperSize方法在ChromePdfRenderOptions物件中指定所需的尺寸,以不同紙張大小渲染PDF。 在方法參數中使用預設的PaperSizes值設定紙張大小。 之後,從來源內容(HTML 字串、URL、HTML 檔案等)如常渲染 PDF 文件。

ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();  
renderOptions.setPaperSize(PaperSize.B5);  
PdfDocument.renderHtmlFileAsPdf("mycontent.html", renderOptions);
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();  
renderOptions.setPaperSize(PaperSize.B5);  
PdfDocument.renderHtmlFileAsPdf("mycontent.html", renderOptions);
JAVA

PaperSize 列舉型別支援超過 100 種業界公認的列印尺寸。 這提供了在大多數商業案例中使用的尺寸的覆蓋範圍。 要使用PaperSize列舉中包含的不同打印尺寸,請選擇PaperSize.Custom並手動設置所需的頁面寬度和頁面高度:

ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();  
renderOptions.setPaperSize(PaperSize.Custom);  
renderOptions.setCustomPaperWidth(11);   // in inches  
renderOptions.setCustomPaperHeight(17);  // in inches
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();  
renderOptions.setPaperSize(PaperSize.Custom);  
renderOptions.setCustomPaperWidth(11);   // in inches  
renderOptions.setCustomPaperHeight(17);  // in inches
JAVA

如上所示,setCustomPaperWidthsetCustomPaperHeight 接受表示所需尺寸(英寸)的數值。 要使用公分設定尺寸,請使用setCustomPaperSizeInCentimeters。 要以毫米設定尺寸,請使用setCustomPaperSizeInMillimeters。 對於像素/點,使用setCustomPaperSizeInPixelsOrPoints