How can I help you?
Create or Generate PDF file in ASP.NET Web Forms
15 Jun 20263 minutes to read
The Syncfusion® .NET PDF library is used to create, read, and edit PDF documents. This library also offers functionality to merge, split, stamp, work with forms, and secure PDF files.
To include the .NET PDF library into your ASP.NET Web application, please refer to the NuGet Package Required or Assemblies Required documentation.
NOTE
This ASP.NET Web Forms platform is deprecated; you can use the same product from the ASP.NET Core platform.
Steps to create PDF document in ASP.NET Web Forms
Step 1: Create a new ASP.NET Web application project.

Step 2: Select the Empty project.

Step 3: Install the Syncfusion.Pdf.AspNet NuGet package as a reference to your .NET Framework applications from NuGet.org.

NOTE
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, you also have to add the
Syncfusion.Licensingassembly reference and include a license key in your projects. Please refer to this link to learn about registering the Syncfusion® license key in your application to use our components.
Step 4: Add a new Web Form in the ASP.NET project. Right-click the project, select Add > New Item, and add a Web Form from the list. Name it MainPage.
Step 5: Add a new button in the MainPage.aspx as follows.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Create Document" OnClick="OnButtonClicked" />
</div>
</form>
</body>
</html>Step 6: Include the following namespaces in your MainPage.aspx.cs file.
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using System.Drawing;Step 7: Include the following code example in the click event of the button in MainPage.aspx.cs to generate a PDF document using the PdfDocument class. Then use the DrawString method of the PdfGraphics object to draw text on the PDF page.
//Create a new PDF document.
using (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));
//Open the document in browser after saving it.
document.Save("Output.pdf", HttpContext.Current.Response, HttpReadType.Save);
}You can download a complete working sample from GitHub.
By executing the program, you will get the PDF document as follows.

Click here to explore the rich set of Syncfusion® PDF library features.
An online sample link to create PDF document.