Updated February 11, 2025
Share:

How to Create New PDFs

by Chaknith Bin

Creating a new PDF is to generating a fresh PDF document from scratch, typically by adding text, images, or other elements programmatically. This can be done using libraries like IronPDF in C#, which allows developers to define the content, layout, and formatting before saving the document as a PDF file.


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

First Step:
green arrow pointer

Create a Blank PDF Example

There are multiple ways to create a PDF object. Let's start with the simplest method, which requires only the width and height of the PDF. This PdfDocument constructor will create a new blank PDF, ready for customization and use.

Code

:path=/static-assets/pdf/content-code-examples/how-to/create-new-pdfs.cs
using IronPdf;

PdfDocument pdf = new PdfDocument(270, 270);

pdf.SaveAs("blankPage.pdf");

Import PDF from File

Before a PDF can be modified or converted, it must first be imported as a PdfDocument object. Use the static FromFile method of the PdfDocument class to accomplish this. Importing PDFs from JSON, byte arrays, streams, and URLs is also supported within the same class.

Code

:path=/static-assets/pdf/content-code-examples/how-to/create-new-pdfs-from-file.cs
using IronPdf;

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

pdf.SaveAs("export.pdf");

Convert from Other Formats

In addition to the previously mentioned methods for obtaining a PdfDocument object, you can also convert various formats into PDF. The most sophisticated method is converting HTML to PDF, which renders the HTML along with all its assets—including JavaScript, images, links, and CSS styling using the Chrome engine. Besides HTML, you can also convert other formats into PDF, such as images, RTF, Markdown, and XML.

Chaknith related to Convert from Other Formats

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.