How to create PDF in .NET Core 3.1
The Syncfusion Essential® PDF is a feature-rich and high-performance .NET Core PDF library that is used to create, read, and edit PDF documents programmatically without Adobe dependencies. Using this library, you can create a PDF document in NET Core 3.1.
Steps to create a PDF document programmatically in NET Core 3.1
1. Create a new C# console application project.
2. Install the Syncfusion.PDF.Core NuGet packages as a reference to your .NET Core Framework application from NuGet.org.
3. Install the System.Drawing.Common NuGet packages as a reference to your application.
4. Include the following namespaces in the Program.cs file.
C#
using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using System.Drawing;
5. The following code example shows how to create a PDF document using C#.
C#
//Create a new PDF document. PdfDocument document = new PdfDocument(); // Set the page size. document.PageSettings.Size = PdfPageSize.A4; //Add a page to the document. PdfPage page = document.Pages.Add(); //Create PDF graphics for the page. PdfGraphics graphics = page.Graphics; //Set the font. PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); //Save the document. FileStream fileStream = new FileStream("Sample.pdf", FileMode.Create, FileAccess.ReadWrite); //Save and close the PDF document document.Save(fileStream); document.Close(true);
A complete working sample can be downloaded from CreatePDF.zip.
By executing the program, you will get the PDF document as follows.
Take a moment to peruse the documentation. You can find the other options like drawing right-to-left text and multi-column text, consuming TrueType fonts, Standard fonts, and CJK fonts. Also, the features like PDF form filling, extract text or images from PDF and protect PDF documents with code examples.
Refer to here to explore a rich set of Syncfusion Essential® PDF features.
An online sample link to generate a Hello world PDF document.
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without trail message.
See Also:
https://www.syncfusion.com/kb/9137/how-to-create-a-pdf-file-in-asp-net-core
https://www.syncfusion.com/kb/10189/how-to-create-pdf-in-docker-container
https://www.syncfusion.com/kb/10188/how-to-create-pdf-in-azure-website
https://www.syncfusion.com/kb/10780/how-to-create-pdf-in-azure-using-c