PDF (Portable Document Format) is a well known and widely used format to display or view digital documents without worrying about the compatible software, operating system, or hardware. Creating PDF files programmatically is quite useful for generating documents such as reports, resumes, invoices, etc. online within the web applications. So in this article, I’ll show you how to create PDF files programmatically in ASP.NET Core web application using C#.
Create PDF Files Programmatically in ASP.NET Core
In order to create PDF files programmatically, we’ll develop a PDF Creator in the ASP.NET Core web application. This PDF Creator will be based on a WYSIWYG HTML editor to create the content and Aspose.PDF for .NET to generate the PDF based on that content. So let’s begin creating our PDF Creator application in ASP.NET Core by following the below steps.
- Create a new ASP.NET Core Web Application in Visual Studio.
- Select Web Application (Model-View-Controller) from the templates.
Since this PDF Creator uses the WYSIWYG HTML editor to create the content for PDF documents, for the demonstration, I have used CKEditor’s Standard Package. You can feel free to choose your favorite HTML editor that could best serve your requirements. If you are good to go with the afore-mentioned editor then follow the below step for its integration, else skip it.
- Download the CKEditor’s package, extract it and copy/paste the folder in wwwroot directory.
- Open NuGet Package Manager and install the packages of Aspose.PDF and CKEditor.
- Open Views/Home/index.cshtml and replace the script with the following.
- Open Controllers/HomeController.cs and replace the code with the following.
- Build the application and run it in your favorite browser.
PDF Creator in ASP.NET Core – Demo
The following is the demonstration of how to create PDF files using ASP.NET PDF Creator we have just created.
Download Source Code
You can download the complete source code of the application from GitHub.
Get a Free License for Aspose.PDF for .NET
You can request a free temporary license of Aspose.PDF for .NET to avoid evaluation limitations.