Cómo configurar tamaños de papel personalizados para PDFs usando C# | IronPDF

How to Render PDFs with Custom Paper Size

This article was translated from English: Does it need improvement?
Translated
View the article in English

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!

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.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 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")
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer


Use Standard Paper Size Example

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.

Code

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.cs
using 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");
Imports IronPdf
Imports IronPdf.Rendering

Private renderer As New ChromePdfRenderer()

' Set paper size to A4
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4

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

pdf.SaveAs("standardPaperSize.pdf")
$vbLabelText   $csharpLabel
  • 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.

Get Standard Paper Sizes in Various 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.cs
using IronPdf.Rendering;

double A4WidthInPixel = PdfPaperSize.A4.ToMillimeters().width.ToPixel();
double A4HeightInCentimeter = PdfPaperSize.A4.ToMillimeters().height.ToCentimeter();
Imports IronPdf.Rendering

Private A4WidthInPixel As Double = PdfPaperSize.A4.ToMillimeters().width.ToPixel()
Private A4HeightInCentimeter As Double = PdfPaperSize.A4.ToMillimeters().height.ToCentimeter()
$vbLabelText   $csharpLabel

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

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.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")
$vbLabelText   $csharpLabel

Output PDF


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

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.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")
$vbLabelText   $csharpLabel

Output PDF

Ready to see what else you can do? Check out our tutorial page here: Create PDFs

Preguntas Frecuentes

¿Cómo puedo renderizar un PDF con un tamaño de papel personalizado en C#?

Para renderizar un PDF con un tamaño de papel personalizado usando IronPDF, instancia la clase ChromePdfRenderer, accede a las RenderingOptions y usa uno de los métodos SetCustomPaperSize según la unidad de medida que prefieras, como centímetros o pulgadas.

¿Cuáles son los pasos para descargar la biblioteca para configuraciones de tamaño de papel personalizado?

Puedes descargar IronPDF a través de NuGet para acceder a funciones de configuración de tamaños de papel personalizados en PDFs. Esta biblioteca proporciona las herramientas necesarias para definir dimensiones específicas para tus documentos PDF.

¿Cómo aplico un tamaño de papel estándar en la generación de PDF?

En IronPDF, crea una instancia de ChromePdfRenderer, luego usa las RenderingOptions para configurar la propiedad PaperSize a un valor predefinido del enum PdfPaperSize, como tamaño A4 o carta.

¿Es posible modificar el tamaño de página de un PDF existente usando IronPDF?

Sí, IronPDF te permite modificar el tamaño de página de un PDF existente utilizando el método ExtendPage. Este método te permite ajustar las dimensiones de cada lado de la página especificando el índice de la página y las unidades de medida.

¿Cuáles son las opciones para configurar tamaños de papel personalizados en IronPDF?

IronPDF proporciona métodos para configurar tamaños de papel personalizados usando varias unidades de medida: SetCustomPaperSizeInCentimeters, SetCustomPaperSizeInInches, SetCustomPaperSizeInMillimeters y SetCustomPaperSizeInPixelsOrPoints.

¿Cómo funciona la función ForcePaperSize en la renderización de PDF?

La función ForcePaperSize en IronPDF asegura que los tamaños de página reales coincidan con las dimensiones especificadas, redimensionando la página después de renderizar el PDF desde HTML. Esto ayuda a anular cualquier regla de CSS que defina el tamaño de papel.

¿Qué tamaños de papel predefinidos están disponibles en IronPDF?

IronPDF ofrece más de 100 tamaños de papel predefinidos, incluidos tamaños comunes como A3, A4 y tamaño carta, que se pueden seleccionar a través del enum PdfPaperSize.

¿Cómo puedo convertir tamaños de papel estándar en diferentes unidades usando IronPDF?

Puedes usar el método ToMillimeters de IronPDF para convertir tamaños de papel estándar en varias unidades como milímetros, centímetros, pulgadas, píxeles o puntos, brindando flexibilidad en el diseño del PDF.

¿IronPDF es totalmente compatible con .NET 10 y puedo usar funciones de tamaño de papel personalizado en un proyecto .NET 10?

Sí, IronPDF es totalmente compatible con .NET 10, incluidas sus versiones próximas o lanzadas recientemente, y puede usar todas las funciones descritas en la guía de tamaño de papel personalizado (como SetCustomPaperSizeInInches , SetCustomPaperSizeInMillimeters , ForcePaperSize , etc.) en un proyecto .NET 10 sin soluciones alternativas adicionales ni problemas de compatibilidad.

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
¿Listo para empezar?
Nuget Descargas 16,154,058 | Versión: 2025.11 recién lanzado