How to Render PDFs with Custom Paper Size in C#
IronPDF enables you to render PDFs with custom paper sizes in C# by using the ChromePdfRenderer class and setting specific dimensions through methods like SetCustomPaperSizeInInches(), allowing precise control over document dimensions for specialty layouts like posters or banners.
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. This flexibility is essential when working with HTML to PDF conversion projects that require specific dimensions.
Discover the extensive range of paper sizes available with IronPDF, offering a wide selection to suit your needs!
Quickstart: Define Custom Paper Sizes in IronPDF
In this quick guide, learn how to set custom paper sizes using IronPDF in just a few lines of code. With IronPDF, you can easily tailor PDF dimensions by defining exact width and height measurements in any unit you prefer. This flexibility is ideal for creating documents with unique layout requirements, such as posters or banners. Begin by downloading the IronPDF library via NuGet and follow this example to set your desired paper size effortlessly.
Get started making PDFs with NuGet now:
Install IronPDF with NuGet Package Manager
Copy and run this code snippet.
var renderer = new IronPdf.ChromePdfRenderer { RenderingOptions = { PaperSize = IronPdf.Rendering.PdfPaperSize.Custom } }; renderer.RenderingOptions.SetCustomPaperSizeInInches(5, 7); renderer.RenderHtmlAsPdf("<h1>Custom size</h1>").SaveAs("custom-size.pdf")Deploy to test on your live environment
Minimal Workflow (5 steps)
- Download IronPDF from NuGet for setting custom paper sizes in PDFs
- Instantiate the ChromePdfRenderer class in C#
- Access the RenderingOptions on the new object
- Invoke one of the
SetCustomPaperSizemethods based on the measurement unit - Render and export the PDF document
How Do I Use Standard Paper Sizes?
First, create an instance of the ChromePdfRenderer class. Then, use the RenderingOptions property of the newly created object to modify the PaperSize. Set it to one of the predefined values from the PdfPaperSize enum to specify the desired paper size. We offer over 100 predefined standard paper sizes for your convenience.
When working with PDF rendering options, IronPDF provides comprehensive control over how your documents are formatted. The standard paper sizes include commonly used formats like A4, Letter, Legal, and many international standards.
Which Standard Paper Sizes Are Available?
Below is an example of how to set a standard paper size:
:path=/static-assets/pdf/content-code-examples/how-to/custom-paper-size-standard-paper-size.csusing IronPdf;
using IronPdf.Rendering;
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Set paper size to A4
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Standard Paper Size</h1>");
pdf.SaveAs("standardPaperSize.pdf");IronPDF supports an extensive collection of standard paper sizes including:
- ISO 216 Series: A0 through A10, B0 through B10
- North American: Letter, Legal, Tabloid, Executive
- Architectural: ANSI A through E
- Japanese: JIS B0 through B10
- Envelope Sizes: Various international envelope standards
For a complete list of available paper sizes and their dimensions, refer to the API Reference documentation.
What Properties Control Paper Size?
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 viaIronPdf.ChromePdfRenderOptions.PaperSizeby resizing the page after generating a PDF from HTML. This feature is useful for bypassing CSS rules that specify paper size.
When using these properties in conjunction with custom margins, you can achieve precise control over your PDF layout.
How Do I Get Standard Paper Sizes in Different Units?
Need to find the dimensions of standard paper sizes? You can easily do so using the ToMillimeters method. This method returns a tuple containing the width and height of the standard paper size as Length objects. The Length class is incredibly versatile, allowing you to effortlessly convert these dimensions into a variety of units, including:
- Millimeters
- Centimeters
- Inches
- Pixels
- Points
:path=/static-assets/pdf/content-code-examples/how-to/custom-paper-size-standard-paper-size-in-other-unit.csusing IronPdf.Rendering;
double A4WidthInPixel = PdfPaperSize.A4.ToMillimeters().width.ToPixel();
double A4HeightInCentimeter = PdfPaperSize.A4.ToMillimeters().height.ToCentimeter();This functionality is particularly useful when integrating with CSS responsive layouts or when you need to calculate exact dimensions for custom layouts.
How Do I Create Custom Paper Sizes?
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 incentimeters.SetCustomPaperSizeInInches: Dimensions are ininches.SetCustomPaperSizeInMillimeters: Dimensions are inmillimeters.SetCustomPaperSizeInPixelsOrPoints: Dimensions are inpixels or points.
When creating custom paper sizes, it's important to consider how they will interact with headers and footers as well as page orientation settings.
What Units Can I Use for Custom Dimensions?
Below is an example of how to set a custom paper size in centimeters:
:path=/static-assets/pdf/content-code-examples/how-to/custom-paper-size-cm.csusing 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");Here are additional examples for each measurement unit:
// Example: Custom paper size in inches (for US letter-like custom size)
renderer.RenderingOptions.SetCustomPaperSizeInInches(8.5, 11.5);
// Example: Custom paper size in millimeters (for precise metric measurements)
renderer.RenderingOptions.SetCustomPaperSizeInMillimeters(297, 420); // A3 size
// Example: Custom paper size in pixels (useful for screen-based layouts)
renderer.RenderingOptions.SetCustomPaperSizeInPixelsOrPoints(1024, 768, 96); // 96 DPI// Example: Custom paper size in inches (for US letter-like custom size)
renderer.RenderingOptions.SetCustomPaperSizeInInches(8.5, 11.5);
// Example: Custom paper size in millimeters (for precise metric measurements)
renderer.RenderingOptions.SetCustomPaperSizeInMillimeters(297, 420); // A3 size
// Example: Custom paper size in pixels (useful for screen-based layouts)
renderer.RenderingOptions.SetCustomPaperSizeInPixelsOrPoints(1024, 768, 96); // 96 DPIWhen working with custom sizes, you might also want to explore viewport and zoom settings to ensure your content fits properly within the custom dimensions.
How Can I Modify Paper Dimensions?
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.
This feature is particularly useful when you need to adjust PDFs after they've been created, such as when merging multiple PDFs with different page sizes or when preparing documents for printing.
What Parameters Does ExtendPage Accept?
The ExtendPage method accepts the following parameters:
- Page Index: The zero-based index of the page to modify
- Left Extension: Amount to extend/reduce the left side
- Right Extension: Amount to extend/reduce the right side
- Top Extension: Amount to extend/reduce the top side
- Bottom Extension: Amount to extend/reduce the bottom side
- Measurement Unit: The unit of measurement (
millimeters, inches, etc.)
Below is an example of how to modify paper dimensions:
:path=/static-assets/pdf/content-code-examples/how-to/custom-paper-size-modify-paper-size.csusing IronPdf;
using IronPdf.Editing;
PdfDocument pdf = PdfDocument.FromFile("customPaperSize.pdf");
pdf.ExtendPage(0, 50, 0, 0, 0, MeasurementUnit.Millimeter);
pdf.SaveAs( "extendedLeftSide.pdf");Here's a more comprehensive example showing various page modifications:
// Extend all sides equally
pdf.ExtendPage(0, 10, 10, 10, 10, MeasurementUnit.Millimeter);
// Reduce page size (negative values)
pdf.ExtendPage(1, -20, -20, -10, -10, MeasurementUnit.Millimeter);
// Extend only top and bottom (useful for adding header/footer space)
pdf.ExtendPage(2, 0, 0, 25, 25, MeasurementUnit.Millimeter);
// Work with inches instead of millimeters
pdf.ExtendPage(3, 0.5, 0.5, 1, 1, MeasurementUnit.Inch);// Extend all sides equally
pdf.ExtendPage(0, 10, 10, 10, 10, MeasurementUnit.Millimeter);
// Reduce page size (negative values)
pdf.ExtendPage(1, -20, -20, -10, -10, MeasurementUnit.Millimeter);
// Extend only top and bottom (useful for adding header/footer space)
pdf.ExtendPage(2, 0, 0, 25, 25, MeasurementUnit.Millimeter);
// Work with inches instead of millimeters
pdf.ExtendPage(3, 0.5, 0.5, 1, 1, MeasurementUnit.Inch);Best Practices for Custom Paper Sizes
When working with custom paper sizes in IronPDF, consider these best practices:
Test Different Units: While working with custom sizes, test which measurement unit works best for your use case. Pixels are great for screen-based layouts, while millimeters or inches are better for print.
Consider Print Margins: When creating PDFs for printing, remember to account for printer margins. Most printers cannot print to the edge of the paper.
Responsive Design: When converting HTML to PDF, ensure your HTML uses responsive design principles to adapt to different paper sizes.
Performance Optimization: Very large custom paper sizes can impact performance. Consider using compression for large documents.
- Compatibility: Test your custom-sized PDFs in different PDF viewers to ensure compatibility, especially if using non-standard dimensions.
Ready to see what else you can do? Check out our tutorial page here: Create PDFs
Frequently Asked Questions
How do I set custom paper sizes for PDF documents in C#?
With IronPDF, you can set custom paper sizes using the ChromePdfRenderer class. Simply set the PaperSize property to PdfPaperSize.Custom in the RenderingOptions, then use methods like SetCustomPaperSizeInInches() to define your specific dimensions. For example: renderer.RenderingOptions.SetCustomPaperSizeInInches(5, 7).
What measurement units can I use for custom paper sizes?
IronPDF supports multiple measurement units for custom paper sizes through different SetCustomPaperSize methods. You can specify dimensions in inches, centimeters, millimeters, or pixels, making it flexible for various international standards and project requirements.
When would I need to use custom paper sizes instead of standard sizes?
Custom paper sizes in IronPDF are ideal when creating PDFs with unique layouts such as posters, banners, specialty documents, or any design that doesn't fit standard formats like A4 or Letter. This flexibility is especially useful for HTML to PDF conversion projects requiring specific dimensions.
How many predefined standard paper sizes are available?
IronPDF offers over 100 predefined standard paper sizes through the PdfPaperSize enum, including commonly used formats like A4, Letter, Legal, and many international standards, providing comprehensive options for most document requirements.
What are the steps to implement custom paper sizes?
To implement custom paper sizes with IronPDF: 1) Download IronPDF via NuGet, 2) Create a ChromePdfRenderer instance, 3) Access the RenderingOptions property, 4) Call a SetCustomPaperSize method with your desired dimensions, and 5) Render and save your PDF document.






