Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What options do we have to generate a PDF from an ASP.NET Core Web Api

Tags:

asp.net

pdf

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.

like image 712
Sorin B. Avatar asked Sep 27 '19 09:09

Sorin B.


People also ask

How do I create a PDF file in ASP NET Core?

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.

How do I create a PDF document using web API?

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.

How do I generate a PDF file from a MVC project?

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.

How to convert HTML files to PDF using ironpdf in ASP NET?

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.


Video Answer


1 Answers

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

like image 51
RezaGhahari Avatar answered Sep 20 '22 20:09

RezaGhahari