Custom PDF Size

One important aspect to note when creating your PDF documents in IronPDF is to ensure they can be viewed or printed well. This means you need to define the target virtual paper size of the PDF and its related real-world paper size.

In this example, we show you how to add custom paper sizes to your PDF projects.

IronPDF supports close to 50 preset paper sizes and unlimited custom paper sizes that should fit every scenario or situation where you'd like your PDF to fit. You can render PDFs in different paper sizes measured in inches or millimeters.

The enum PdfPaperSize class defines the target virtual paper size of the PDF and its related real-world paper size.

You can use the following methods to create PDFs of custom size in inches or millimeters:

  • Renderer.RenderingOptions.SetCustomPaperSizeInInches
  • Renderer.RenderingOptions.SetCustomPaperSizeInMillimeters
// Example to set custom paper size in inches
// Ensure to include the necessary IronPDF namespace at the beginning of your file
using IronPdf;

public void SetCustomSizeInInches()
{
    // Create a new HtmlToPdf Renderer
    var Renderer = new HtmlToPdf();

    // Define the width and height in inches
    double widthInInches = 8.5;
    double heightInInches = 11.0;

    // Set the custom paper size in inches
    Renderer.RenderingOptions.SetCustomPaperSizeInInches(widthInInches, heightInInches);

    // Render an empty PDF document to test the custom paper size
    var pdfDocument = Renderer.RenderHtmlAsPdf("<h1>Sample PDF</h1>");

    // Save the PDF to a file
    pdfDocument.SaveAs("CustomSizeInches.pdf");
}
// Example to set custom paper size in inches
// Ensure to include the necessary IronPDF namespace at the beginning of your file
using IronPdf;

public void SetCustomSizeInInches()
{
    // Create a new HtmlToPdf Renderer
    var Renderer = new HtmlToPdf();

    // Define the width and height in inches
    double widthInInches = 8.5;
    double heightInInches = 11.0;

    // Set the custom paper size in inches
    Renderer.RenderingOptions.SetCustomPaperSizeInInches(widthInInches, heightInInches);

    // Render an empty PDF document to test the custom paper size
    var pdfDocument = Renderer.RenderHtmlAsPdf("<h1>Sample PDF</h1>");

    // Save the PDF to a file
    pdfDocument.SaveAs("CustomSizeInches.pdf");
}
' Example to set custom paper size in inches
' Ensure to include the necessary IronPDF namespace at the beginning of your file
Imports IronPdf

Public Sub SetCustomSizeInInches()
	' Create a new HtmlToPdf Renderer
	Dim Renderer = New HtmlToPdf()

	' Define the width and height in inches
	Dim widthInInches As Double = 8.5
	Dim heightInInches As Double = 11.0

	' Set the custom paper size in inches
	Renderer.RenderingOptions.SetCustomPaperSizeInInches(widthInInches, heightInInches)

	' Render an empty PDF document to test the custom paper size
	Dim pdfDocument = Renderer.RenderHtmlAsPdf("<h1>Sample PDF</h1>")

	' Save the PDF to a file
	pdfDocument.SaveAs("CustomSizeInches.pdf")
End Sub
$vbLabelText   $csharpLabel
// Example to set custom paper size in millimeters
using IronPdf;

public void SetCustomSizeInMillimeters()
{
    // Create a new HtmlToPdf Renderer
    var Renderer = new HtmlToPdf();

    // Define the width and height in millimeters
    double widthInMillimeters = 210.0;
    double heightInMillimeters = 297.0;

    // Set the custom paper size in millimeters
    Renderer.RenderingOptions.SetCustomPaperSizeInMillimeters(widthInMillimeters, heightInMillimeters);

    // Render an empty PDF document to test the custom paper size
    var pdfDocument = Renderer.RenderHtmlAsPdf("<h1>Sample PDF</h1>");

    // Save the PDF to a file
    pdfDocument.SaveAs("CustomSizeMillimeters.pdf");
}
// Example to set custom paper size in millimeters
using IronPdf;

public void SetCustomSizeInMillimeters()
{
    // Create a new HtmlToPdf Renderer
    var Renderer = new HtmlToPdf();

    // Define the width and height in millimeters
    double widthInMillimeters = 210.0;
    double heightInMillimeters = 297.0;

    // Set the custom paper size in millimeters
    Renderer.RenderingOptions.SetCustomPaperSizeInMillimeters(widthInMillimeters, heightInMillimeters);

    // Render an empty PDF document to test the custom paper size
    var pdfDocument = Renderer.RenderHtmlAsPdf("<h1>Sample PDF</h1>");

    // Save the PDF to a file
    pdfDocument.SaveAs("CustomSizeMillimeters.pdf");
}
' Example to set custom paper size in millimeters
Imports IronPdf

Public Sub SetCustomSizeInMillimeters()
	' Create a new HtmlToPdf Renderer
	Dim Renderer = New HtmlToPdf()

	' Define the width and height in millimeters
	Dim widthInMillimeters As Double = 210.0
	Dim heightInMillimeters As Double = 297.0

	' Set the custom paper size in millimeters
	Renderer.RenderingOptions.SetCustomPaperSizeInMillimeters(widthInMillimeters, heightInMillimeters)

	' Render an empty PDF document to test the custom paper size
	Dim pdfDocument = Renderer.RenderHtmlAsPdf("<h1>Sample PDF</h1>")

	' Save the PDF to a file
	pdfDocument.SaveAs("CustomSizeMillimeters.pdf")
End Sub
$vbLabelText   $csharpLabel

You can also use Renderer.RenderingOptions.PaperSize, which is our custom preset paper size, now accurate to 1 micron.

For more detailed information on how to utilize IronPDF's custom paper size functionality and other advanced features, visit the IronPDF Documentation.

If you're interested in learning about other powerful libraries offered by Iron Software, such as IronBarcode for barcode generation and reading or IronOCR for optical character recognition, head over to the Iron Software Home Page.