I need to generate a PDF from a HTML Canvas, but the process must complete on the server side which is an ASP.NET Core Web Api.
Steps to create PDF document in ASP.NET Core Create a new C# ASP.NET Core Web Application project. Select Web Application pattern (Model-View-Controller) for the project. Install the Syncfusion.Pdf.Net.Core NuGet package as reference to your.NET Standard applications from NuGet.org.
For simplicity, we will create a default Web API project with default options that will have one endpoint that will be responsible for creating a PDF document and returning the created document to the user. To start, let’s delete the existing controller and create our own controller that will be responsible for generating the PDF document.
To start generating PDF files, create a new ASP.NET Core MVC 3.1 project. Next, install the Wkhtmltopdf.NetCore NuGet package: Wkhtmltopdf.NetCore is a free wrapper of wkhtmltopdf that also integrates nicely with ASP.NET Core.
When you click on the “Generate PDF” button, it will create a PDF file you can see in the project folder. Now open the PDF file. You will see the output which has been generated by the IronPDF. The content in the PDF is the same as we give input in the program. We can convert HTML files to PDF using IronPDF in the ASP.NET core application.
using IronPdf;
IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();
// Render an HTML document or snippet as a string
Renderer.RenderHtmlAsPdf("<h1>Hello World</h1>").SaveAs("html-string.pdf");
// Advanced:
// Set a "base url" or file path so that images, javascript and CSS can be loaded
var PDF = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>",@"C:\site\assets\");
PDF.SaveAs("html-with-assets.pdf");
IronPDF for .NET Core
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With