Create PDF via C#

Native and high-performance PDF file creation without Adobe Acrobat installation using C#

How to generate PDF File via C#

In order to create a PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy-to-use document manipulation API for net platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF

How to Create PDF via C#


It is easy for the developers to create, load, modify and convert PDF files directly from .NET application in just a few lines of code.

  1. Include the namespace in your class file
  2. Initialize the Document class object.
  3. Add a page using Pages.Add() method.
  4. Create a new TextFragment object and set its text.
  5. Add TextFragment to the Paragraphs collection of the page.
  6. Save the PDF using Save(String) method.

Following source code shows how to create a PDF file using C#.

This sample code shows how to create PDF using C#


    // Initialize document object
    Document pdf_doc = new Document();

    // Add page
    Page page = pdf_doc.Pages.Add();

    // Place the text of choice
    page.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Text of choice"));

    // PDF file created at a specified location
    pdf_doc.Save("created_one.pdf");