How to Render PDFs with Custom Paper Size

by Chaknith Bin

A custom paper size refers to a non-standard paper size that is defined by the user rather than being a standard size like A4 or letter size (8.5 x 11 inches). Custom paper sizes are often used when printing documents that require a unique or specific layout, such as posters, banners, or specialty documents.

Discover the extensive range of paper sizes available with IronPDF, offering a wide selection to suit your needs!


C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer

Check out IronPDF on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming PDF with C#.

C# NuGet Library for PDF nuget.org/packages/IronPdf/
Install-Package IronPdf

Consider installing the IronPDF DLL directly. Download and manually install it for your project or GAC form: IronPdf.zip

Manually install into your project

Download DLL

Use Custom Paper Size Example

First, we begin by instantiating the ChromePdfRenderer class. From the newly created object, we can access the RenderingOptions to apply a custom paper size to the newly generated PDF document. There are four methods that can be used to set the output paper size for PDF pages, each based on a different measurement unit:

  • SetCustomPaperSizeInCentimeters: Dimensions are in centimeters.
  • SetCustomPaperSizeInInches: Dimensions are in inches.
  • SetCustomPaperSizeInMillimeters: Dimensions are in millimeters.
  • SetCustomPaperSizeInPixelsOrPoints: Dimensions are in pixels or points.

Code

:path=/static-assets/pdf/content-code-examples/how-to/custom-paper-size-cm.cs
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Set custom paper size in cm
renderer.RenderingOptions.SetCustomPaperSizeinCentimeters(15, 15);

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Custom Paper Size</h1>");

pdf.SaveAs("customPaperSize.pdf");
Imports IronPdf

Private renderer As New ChromePdfRenderer()

' Set custom paper size in cm
renderer.RenderingOptions.SetCustomPaperSizeinCentimeters(15, 15)

Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Custom Paper Size</h1>")

pdf.SaveAs("customPaperSize.pdf")
VB   C#

Output PDF

  • PaperSize: Set an output paper size for PDF pages with predefined sizes such as letter, A3, A4, etc.
  • ForcePaperSize: Forces page sizes to be exactly what is specified via IronPdf.ChromePdfRenderOptions.PaperSize by resizing the page after generating a PDF from HTML. This feature is useful for bypassing CSS rules that specify paper size.

Modify Paper Dimension Example

In an existing PDF document or a freshly rendered PDF, the size of each page can be modified using the ExtendPage method. This method allows you to specify the target page index, the values to modify each of the four sides, and the units of measurement. The values for each side can be negative, which will reduce that particular side, or positive, which will extend that side.

Code

:path=/static-assets/pdf/content-code-examples/how-to/custom-paper-size-modify-paper-size.cs
using IronPdf;
using IronPdf.Editing;

PdfDocument pdf = PdfDocument.FromFile("customPaperSize.pdf");

pdf.ExtendPage(0, 50, 0, 0, 0, MeasurementUnit.Millimeter);

pdf.SaveAs( "extendedLeftSide.pdf");
Imports IronPdf
Imports IronPdf.Editing

Private pdf As PdfDocument = PdfDocument.FromFile("customPaperSize.pdf")

pdf.ExtendPage(0, 50, 0, 0, 0, MeasurementUnit.Millimeter)

pdf.SaveAs("extendedLeftSide.pdf")
VB   C#

Output PDF

Chaknith Bin

Software Engineer

Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.