Is There a Web Service for Converting HTML to Pdf

Is there a web service for converting HTML to PDF?

For third party solutions there are lots of options. Just to name a few...

  • https://cloudlayer.io
  • https://www.api2pdf.com
  • https://www.printfriendly.com
  • https://pdfshift.io
  • http://pdfmyurl.com/html-to-pdf-api
  • https://www.html2pdfrocket.com/
  • https://pdflayer.com/
  • http://pdfcrowd.com/
  • http://www.pdfonline.com/convert-pdf/
  • http://docraptor.com
  • https://restpack.io/html2pdf
  • https://products.aspose.cloud/pdf
  • https://pdfmage.org/

A best Html to PDF converter in ASP.NET Core 6.0

You can use Syncfusion to convert html to pdf.

First, Install Syncfusion.HtmlToPdfConverter.Net.Windows NuGet package.

Then, Edit the corresponding method in the controller:

public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult ExportToPDF()
{
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();

//Convert URL to PDF document
PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com");

//Create memory stream
MemoryStream stream = new MemoryStream();

//Save the document
document.Save(stream);

return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "HTML-to-PDF.pdf");
}
}

Don't forget to add the namespace:

using Syncfusion.Pdf;
using Syncfusion.HtmlConverter;

Finally, Add the call in Index.cshtml:

@{
Html.BeginForm("ExportToPDF", "Home", FormMethod.Post);
{
<div>
<input type="submit" value="Convert HTML to PDF" style="width:250px;height:27px" />
</div>
}
Html.EndForm();
}

You can change the URL Page you want to download in the controller method:

PdfDocument document = htmlConverter.Convert("Your Url");

For more details, you can refer to this document.

Update:

Yes, it's not actually open source, you need to get a license key to remove it (only 30 days free trial).

Free and effective first choice is actually SelectPDF.

If you really don't want to use it, you can choose the following two:

PuppeteerSharp:
It's a headless chrome instance which can capture pdfs, and has a nice C# library (Puppeteer Sharp).

jsPDF:
This is also a conversion tool used by open source.

Just my opinion, I think the experience of these two is not as good as SelectPDF. Maybe there are other free and up-to-date PDF converters, but I haven't found them and haven't used them.

Wht is the best solution for HTML to PDF (on Azure Web app)

Azure Apps (former WebSites) operate in restricted (partial-trust) environment and wkhtmltopdf.exe (that is internally used by NReco PdfGenerator wrapper) cannot be executed in this case directly from asp.net application.

update:

Unfortunately it will not work with Azure WebJobs as well: tasks are executed under the same (limited) environment as WebSites and GDI functions used by wkhtmltopdf are disabled.

If your ASP.NET app uses wkhtmltopdf-based component for PDF generation (doesn't matter how it is invoked - in separate process or as native DLL API) it will work only under Azure WebRole / WorkerRole / VM.

-- update 2017 --

Wkhtmltopdf (and NReco PdfGenerator wrapper) can be used with Azure Apps with VM-based subscription plan (Basic or higher). At least one issue still exists: it seems fonts API is still restricted and custom fonts cannot be rendered to PDF.

Converting HTML files to PDF

The Flying Saucer XHTML renderer project has support for outputting XHTML to PDF. Have a look at an example here.



Related Topics



Leave a reply



Submit