How to Create New PDFs
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.
How to Create New PDFs
- Download IronPDF from NuGet for creating new PDFs
- Use the PdfDocument constructor to create a blank PDF
- Import existing PDF from file, URL, byte, as well as JSON
- Convert many different formats to PDFs such as HTML, RTF, Markdown, images, and XML
- Export the PDF document
Start using IronPDF in your project today with a free trial.
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.