How to Render PDFs with Custom Paper Size
A custom watermark is a personalized image or text overlay added to a PDF. It serves various purposes, including branding with logos or names, enhancing security with labels like 'Confidential,' ensuring copyright protection, and indicating document status. Custom watermarks can include text, images, or both, be applied selectively or universally, and their opacity can be adjusted for versatility in personalizing, securing, and contextualizing PDFs.
IronPDF offers a one-liner to apply a watermark. The watermark feature accepts a HTML string to generate the watermark, which is capable of using all HTML features as well as CSS styling.
How to Render PDFs with Custom Paper Size
- Download the C# library to set a custom paper size
- Instantiate the ChromePdfRenderer class in C#
- Access the RenderingOptions on the new object
- invoke one of the
SetCustomPaperSize
methods based on the measurement unit - Render and export the PDF document
Install with NuGet
Install-Package IronPdf
Download DLL
Manually install into your project
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")