How to Create PDF in C#

This how-to guide explains how to create PDF in C#. You can generate PDF from C# by following the easy steps given below in few API calls for any .NET based application.

Steps to Create PDF in C#

  1. Install Aspose.PDF for .NET using NuGet package manager
  2. Include Aspose.PDF reference in application
  3. Create an instance of Document class to create an empty PDF
  4. Create instance of TextFragment Class to add text and its properties
  5. Finally, Create PDF using C# by saving on disk

The following example explains how to generate PDF in C#. You will see how to create a blank PDF using Document Class and adding a page inside it. Then by using TextBuilder Class the text is added and its respective properties are set. Finally, the text will be appended to PDF.

Code to Create PDF from C#

In the above sample code, we observed how to create PDF file in C# with no dependence on Adobe PDF or any other API. By using few simple API calls, we have created a PDF from scratch by adding text and setting its respective properties.

In the previous topic, you learnt how to read PDF in C#. Whereas, the above explanation and sample code in C# create PDF file programmatically.

 English