Custom PDF Size

This code snippet illustrates how to define a custom paper size when rendering HTML content into a PDF document.

Use the paperSize property to customize the paper size in the rendering options. The options object is used to specify the custom paper size, setting it to a custom 5x5-inch dimension. You can adjust the height and width properties as needed to match your desired paper size.

Utilize the PdfDocument.fromHtml method from the IronPDF library to convert the HTML content into a PDF document while applying the specified rendering options.

After rendering, the resulting PDF document is saved with the custom paper size using the saveAs method.

  • The GenerateCustomSizedPdf method takes two arguments: htmlContent (the HTML content to be rendered into PDF) and outputPath (the file path where the generated PDF will be saved).

  • The ChromePdfRenderer is used to handle the rendering process of HTML content.

  • A PdfPaperSize object is created to specify a custom paper size of 5x5 inches. This is achieved by passing the width and height values (in inches) to the PdfPaperSize constructor.

  • The RenderingOptions property of the renderer is set to use the custom paper size.

  • The RenderHtmlAsPdf method converts the given HTML content into a PDF document according to the predefined settings.

  • Finally, the SaveAs method saves the PDF document at the specified outputPath.

Discover how to set custom PDF page sizes using our detailed Node.js example!

Talk to an Expert Five Star Trust Score Rating

Ready to Get Started?