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#
- Install Aspose.PDF for .NET using NuGet package manager
- Include Aspose.PDF reference in application
- Create an instance of Document class to create an empty PDF
- Create instance of TextFragment Class to add text and its properties
- 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.