IRONSOFTWAREHOME
Custom PDF Size
import {PdfDocument, PaperSizeUnit} from "@ironsoftware/ironpdf";

(async () => {
    // Define the HTML content
    const html = `<p>Lorem ipsum dolor sit amet...</p>`;

    // Configure render options
    const options = {
        // Set the paper size to custom (5x5 inches)
        paperSize: {
            unit: PaperSizeUnit.Inch,
            height: 5,
            width: 5,
        },
    };

    // Render HTML content to a PDF
    const pdf = await PdfDocument.fromHtml(html, { renderOptions: options });

    // Save the PDF with the custom paper size
    await pdf.saveAs("customPaperSize.pdf");
})();
NuGet Download
Install-Package @ironsoftware/ironpdf
Custom PDF Size

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.
Explore Custom PDF Page Size Code Example on GitHub
View on GitHub

Ready to Get Started?

Version:2026.8just released

Key in blue circle

Get your free 30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge related to IronPDF Product Demo

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required