# Getting Started with .NET PDF Library in ASP.NET Core

The [.NET PDF library](https://www.syncfusion.com/document-sdk/net-pdf-library) is a powerful and versatile solution for creating, reading, and editing PDF documents in .NET applications. It also provides advanced features such as merging and splitting PDFs, adding stamps, working with form fields, and securing PDF files with encryption and permissions.

To integrate the .NET PDF library into your ASP.NET Core application, refer to the official documentation sections on [NuGet Package Required](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/nuget-packages-required) or [Assemblies Required](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/assemblies-required) for step-by-step guidance.

## Steps to create PDF document in ASP.NET Core

{% tabcontents %}
{% tabcontent Visual Studio %}
**Prerequisites:**

* Visual Studio 2019 or later with the ASP.NET and web development workload installed.
* Install .NET 8.0 SDK or later from the [.NET Downloads page](https://dotnet.microsoft.com/en-us/download).

Step 1: Create a new C# ASP.NET Core Web Application project. Select **ASP.NET Core Web App (Model-View-Controller)** from the template list.

![Create ASP.NET Core Web application in Visual Studio](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/asp.net.core_images/creation1.png)

Step 2: Name your project and click **Next**. In the **Additional information** window, select the target framework (for example, .NET 8.0) and click **Create**.

![Select Web Application pattern](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/asp.net.core_images/creation2.png)

Step 3: Install the [Syncfusion.Pdf.Net.Core](https://www.nuget.org/packages/Syncfusion.Pdf.Net.Core/) NuGet package from [NuGet.org](https://www.nuget.org/).

![Install PDF .NET Core NuGet package](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/asp.net.core_images/creation3.png)

Step 4: Register the Syncfusion<sup>&reg;</sup> license key. A trial watermark is added to every page of the generated PDF until a valid key is registered. Include the license key in **Program.cs** before initializing any Syncfusion<sup>&reg;</sup> component:

{% tabs %}
{% highlight c# tabtitle="C#" %}

using Syncfusion.Licensing;

var builder = WebApplication.CreateBuilder(args);
// Register the Syncfusion license
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR LICENSE KEY");

// Add services to the container.
builder.Services.AddControllersWithViews();

var app = builder.Build();

{% endhighlight %}
{% endtabs %}

Replace `"YOUR LICENSE KEY"` with the license key associated with your Syncfusion<sup>&reg;</sup> account. If you do not have a license key, you can request a free 30-day trial or apply for a Community License from the Syncfusion<sup>&reg;</sup> website. For more information about registering a license key in your application, refer to the [Syncfusion<sup>&reg;</sup> Licensing Documentation](https://help.syncfusion.com/common/essential-studio/licensing/overview).

Step 5: A default controller named **HomeController.cs** is added on creation of an ASP.NET Core MVC project. Include the following namespaces in that **HomeController.cs** file.

{% tabs %}
{% highlight c# tabtitle="C#" %}

using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Drawing;
using System.IO;
using Microsoft.AspNetCore.Mvc;

{% endhighlight %}
{% endtabs %}

Step 6: A default action method named **Index** is present in **HomeController.cs**. Right-click the **Index** method and select **Go To View** to open **Index.cshtml**, then add a new button as shown below.

{% tabs %}
{% highlight CSHTML %}

@{Html.BeginForm("CreateDocument", "Home", FormMethod.Get);
      {
         <div>
            <input type="submit" value="Create PDF Document" style="width:200px;height:27px" />
         </div>
      }
      Html.EndForm();
}

{% endhighlight %}
{% endtabs %}

Step 7: Add a new action method named `CreateDocument` in **HomeController.cs** and include the following code to generate a PDF document using the [PdfDocument](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.PdfDocument.html) class. Then use the [DrawString](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfGraphics.html#Syncfusion_Pdf_Graphics_PdfGraphics_DrawString_System_String_Syncfusion_Pdf_Graphics_PdfFont_Syncfusion_Pdf_Graphics_PdfBrush_System_Drawing_PointF_) method of the [PdfGraphics](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfGraphics.html) object to draw the text on the PDF page.

{% tabs %}
{% highlight c# tabtitle="C#" %}

public IActionResult CreateDocument()
{
   //Create a new PDF document.
   PdfDocument document = new PdfDocument();
   //Add a page to the document.
   PdfPage page = document.Pages.Add();
   //Create PDF graphics for the page.
   PdfGraphics graphics = page.Graphics;
   //Set the standard font.
   PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
   //Draw the text.
   graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));
   //Save the PDF to the MemoryStream.
   MemoryStream stream = new MemoryStream();
   document.Save(stream);
   //Close the document. Pass true to dispose internal resources.
   document.Close(true);
   //Set the position to '0'.
   stream.Position = 0;
   //Download the PDF document in the browser.
   FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");
   fileStreamResult.FileDownloadName = "Sample.pdf";
   return fileStreamResult;
}

{% endhighlight %}
{% endtabs %}

Step 8: Build the project by clicking **Build > Build Solution** or pressing <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd>.

Step 9: Run the project by clicking the **Start** button (green arrow) or pressing <kbd>F5</kbd>.

Step 10: Open the app in a browser, then click the **Create PDF Document** button on the home page. The browser downloads `Sample.pdf` containing the text "Hello World!!!".

{% endtabcontent %}
 
{% tabcontent Visual Studio Code %}
**Prerequisites:**

* .NET SDK (version 8.0 or later) — [Download](https://dotnet.microsoft.com/en-us/download).
* Visual Studio Code — [Download](https://code.visualstudio.com/download?_exp_download).
* [C# extension for VS Code](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) installed from the Extensions view (<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>X</kbd>).

Step 1: Open the terminal (<kbd>Ctrl</kbd>+<kbd>`</kbd>) and run the following command to create a C# ASP.NET Core Web Application project targeting .NET 8.0.

```
dotnet new mvc -n CreatePdfASPNETCoreAPP -f net8.0
```

Step 2: Navigate to the project directory and open it in VS Code.

```
cd CreatePdfASPNETCoreAPP
```

Step 3: Add the [Syncfusion.Pdf.Net.Core](https://www.nuget.org/packages/Syncfusion.Pdf.Net.Core/) NuGet package to your project.

```
dotnet add package Syncfusion.Pdf.Net.Core
```

Step 4: Register the Syncfusion<sup>&reg;</sup> license key. A trial watermark is added to every page of the generated PDF until a valid key is registered. Include the license key in **Program.cs** before initializing any Syncfusion<sup>&reg;</sup> component:

{% tabs %}
{% highlight c# tabtitle="C#" %}

using Syncfusion.Licensing;

var builder = WebApplication.CreateBuilder(args);
// Register the Syncfusion license
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR LICENSE KEY");

// Add services to the container.
builder.Services.AddControllersWithViews();

var app = builder.Build();

{% endhighlight %}
{% endtabs %}

Replace `"YOUR LICENSE KEY"` with the license key associated with your Syncfusion<sup>&reg;</sup> account. If you do not have a license key, you can request a free 30-day trial or apply for a Community License from the Syncfusion<sup>&reg;</sup> website. For more information about registering a license key in your application, refer to the [Syncfusion<sup>&reg;</sup> Licensing Documentation](https://help.syncfusion.com/common/essential-studio/licensing/overview).

Step 5: A default controller named **HomeController.cs** is added on creation of the ASP.NET Core project. Include the following namespaces in that file.

{% tabs %}
{% highlight c# tabtitle="C#" %}

using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Drawing;
using System.IO;
using Microsoft.AspNetCore.Mvc;

{% endhighlight %}
{% endtabs %}

Step 6: A default action method named **Index** is present in **HomeController.cs**. Open **Views/Home/Index.cshtml** and add a new button as shown below.

{% tabs %}
{% highlight CSHTML %}

@{Html.BeginForm("CreateDocument", "Home", FormMethod.Get);
    {
        <div>
            <input type="submit" value="Create PDF Document" style="width:200px;height:27px" />
        </div>
    }
    Html.EndForm();
}

{% endhighlight %}
{% endtabs %}

Step 7: Add a new action method named `CreateDocument` in **HomeController.cs** and include the following code to generate a PDF document using the [PdfDocument](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.PdfDocument.html) class. Then use the [DrawString](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfGraphics.html#Syncfusion_Pdf_Graphics_PdfGraphics_DrawString_System_String_Syncfusion_Pdf_Graphics_PdfFont_Syncfusion_Pdf_Graphics_PdfBrush_System_Drawing_PointF_) method of the [PdfGraphics](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfGraphics.html) object to draw the text on the PDF page.

{% tabs %}
{% highlight c# tabtitle="C#" %}

public IActionResult CreateDocument()
{
    //Create a new PDF document.
    PdfDocument document = new PdfDocument();
    //Add a page to the document.
    PdfPage page = document.Pages.Add();
    //Create PDF graphics for the page.
    PdfGraphics graphics = page.Graphics;
    //Set the standard font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
    //Draw the text.
    graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));
    //Save the PDF to the MemoryStream.
    MemoryStream stream = new MemoryStream();
    document.Save(stream);
    //Close the document. Pass true to dispose internal resources.
    document.Close(true);
    //Set the position to '0'.
    stream.Position = 0;
    //Download the PDF document in the browser.
    FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");
    fileStreamResult.FileDownloadName = "Sample.pdf";
    return fileStreamResult;
}

{% endhighlight %}
{% endtabs %}

Step 8: Build the project by running the following command:

```
dotnet build
```

Step 9: Run the project:

```
dotnet run
```

Step 10: Open a browser, navigate to the URL shown in the terminal output (typically `https://localhost:7xxx`), and click **Create PDF Document** to download `Sample.pdf`.
{% endtabcontent %}

{% tabcontent JetBrains Rider %}
**Prerequisites:**

* JetBrains Rider (latest stable version).
* .NET 8.0 SDK or later — [Download](https://dotnet.microsoft.com/en-us/download).

Step 1: On the Rider welcome screen, click **New Solution**.

![Launch JetBrains Rider](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/jetbrains_images/launch-jetbrains-rider.png)

Step 2: Select **Project Type** as **Web**, choose the target framework (for example, .NET 8.0), and select the **Web App (Model-View-Controller)** template. Enter a project name and location, then click **Create**.

![Creating a new ASP.NET Core web application in JetBrains Rider](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/jetbrains_images/create-asp.net-core-application.png)

Step 3: Install the [Syncfusion.Pdf.Net.Core](https://www.nuget.org/packages/Syncfusion.Pdf.Net.Core/) NuGet package. Click the NuGet icon in the Rider toolbar, search for **Syncfusion.Pdf.Net.Core**, select the latest stable version, click **+ (Add)**, and then **Install**.

![Install the package](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/jetbrains_images/install-core-web-package.png)

Step 4: Register the Syncfusion<sup>&reg;</sup> license key. A trial watermark is added to every page of the generated PDF until a valid key is registered. Include the license key in **Program.cs** before initializing any Syncfusion<sup>&reg;</sup> component:

{% tabs %}
{% highlight c# tabtitle="C#" %}

using Syncfusion.Licensing;

var builder = WebApplication.CreateBuilder(args);
// Register the Syncfusion license
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR LICENSE KEY");

// Add services to the container.
builder.Services.AddControllersWithViews();

var app = builder.Build();

{% endhighlight %}
{% endtabs %}

Replace `"YOUR LICENSE KEY"` with the license key associated with your Syncfusion<sup>&reg;</sup> account. If you do not have a license key, you can request a free 30-day trial or apply for a Community License from the Syncfusion<sup>&reg;</sup> website. For more information about registering a license key in your application, refer to the [Syncfusion<sup>&reg;</sup> Licensing Documentation](https://help.syncfusion.com/common/essential-studio/licensing/overview).

Step 5: A default controller named **HomeController.cs** is added on creation of the ASP.NET Core project. Include the following namespaces in that file.

{% tabs %}
{% highlight c# tabtitle="C#" %}

using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Drawing;
using System.IO;
using Microsoft.AspNetCore.Mvc;

{% endhighlight %}
{% endtabs %}

Step 6: A default action method named **Index** is present in **HomeController.cs**. Right-click the **Index** method and select **Go To View** to open **Index.cshtml**, then add a new button as shown below.
{% tabs %}
{% highlight CSHTML %}

@{
    Html.BeginForm("CreateDocument", "Home", FormMethod.Get);
    {
        <div>
            <input type="submit" value="Create PDF Document" style="width:200px;height:27px" />
        </div>
    }
    Html.EndForm();
}

{% endhighlight %}
{% endtabs %}

Step 7: Add a new action method named `CreateDocument` in **HomeController.cs** and include the following code to generate a PDF document using the [PdfDocument](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.PdfDocument.html) class. Then use the [DrawString](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfGraphics.html#Syncfusion_Pdf_Graphics_PdfGraphics_DrawString_System_String_Syncfusion_Pdf_Graphics_PdfFont_Syncfusion_Pdf_Graphics_PdfBrush_System_Drawing_PointF_) method of the [PdfGraphics](https://help.syncfusion.com/cr/document-processing/Syncfusion.Pdf.Graphics.PdfGraphics.html) object to draw the text on the PDF page.

{% tabs %}
{% highlight c# tabtitle="C#" %}

public IActionResult CreateDocument()
{
    //Create a new PDF document.
    PdfDocument document = new PdfDocument();
    //Add a page to the document.
    PdfPage page = document.Pages.Add();
    //Create PDF graphics for the page.
    PdfGraphics graphics = page.Graphics;
    //Set the standard font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
    //Draw the text.
    graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));
    //Save the PDF to the MemoryStream.
    MemoryStream stream = new MemoryStream();
    document.Save(stream);
    //Close the document. Pass true to dispose internal resources.
    document.Close(true);
    //Set the position to '0'.
    stream.Position = 0;
    //Download the PDF document in the browser.
    FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");
    fileStreamResult.FileDownloadName = "Sample.pdf";
    return fileStreamResult;
}

{% endhighlight %}
{% endtabs %}

Step 8: Build the project by clicking the **Build** button in the toolbar or pressing <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd>.

Step 9: Run the project by clicking the **Run** button (green arrow) in the toolbar or pressing <kbd>Shift</kbd>+<kbd>F10</kbd>.

Step 10: Open the app in a browser, then click the **Create PDF Document** button on the home page. The browser downloads `Sample.pdf` containing the text "Hello World!!!".
{% endtabcontent %}
{% endtabcontents %}

You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Getting%20Started/ASP.NET%20Core/Create-new-PDF-document).

By executing the program, you will get the PDF document as follows.
![ASP.NET Core output PDF document](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/gettingstarted_images/pdf-generation-output.png)

Click [here](https://www.syncfusion.com/document-sdk/net-pdf-library) to explore the rich set of Syncfusion<sup>&reg;</sup> PDF library features.

An online sample link to [create PDF document](https://document.syncfusion.com/demos/pdf/default#/tailwind) in ASP.NET Core.

## Next steps

* [Open and read an existing PDF document](Open-PDF-file.md)
* [Save the generated PDF to a file or stream](Save-PDF-file.md)
* [Work with PDF pages, fonts, and images](Working-with-Pages.md)
* [Add headers, footers, and form fields](Working-with-Headers-and-Footers.md) 