How to convert HTML to .NET MVC PDF in Azure website?
The Syncfusion ASP.NET MVC PDF converter for .NET is used to convert webpages, SVG, MHTML, and HTML to PDF. Using this library, you can convert HTML to PDF in Azure website using C# and VB.NET.
Steps to convert HTML to PDF in Azure website programmatically:
- Open Visual Studio and create ASP.NET MVC project.
- Install the Syncfusion.HtmlToPdfConverter.QtWebkit.AspNet.Mvc5 NuGet package as a reference to your .NET Framework application from the NuGet.org.
- Copy the QtBinaries folder from the installed HtmltoPdfConverter package and paste it in the folder that contains the HTMLtoPDF_Azure.csproj file.
- After installing the package, include the QtBinaries folder to the project.
- Then, set Copy to output directory to copy always to all the QtBinaries (All files including inner folders and files).
- Add an Export To PDF button in index.cshtml.
- Include the following namespaces and code snippet in controller for converting HTML to PDF in Azure website. Refer to the following link for more information.
UG: https://help.syncfusion.com/file-formats/pdf/converting-html-to-pdf
// [C# Code] using Syncfusion.HtmlConverter; using Syncfusion.Pdf; using System.IO;
public ActionResult ExportToPDF() { //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = Server.MapPath("~/QtBinaries/"); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF PdfDocument document = htmlConverter.Convert("http://www.google.com"); MemoryStream stream = new MemoryStream(); //Save and close the PDF document document.Save(stream); return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "Sample.pdf"); }
- Now, check the conversion in local machine.
Refer to the following steps to publish as Azure web application:
- Right-click the project and select Publish.
- Create a new profile in publish window.
- Create App service using Azure subscription and select a hosting plan.
- HTML to PDF conversion works from basic hosting plan (B1). So, select the hosting plan as required. HTML to PDF conversion will not work if the hosting plan is Free/Shared.
- After creating a profile, click the publish button.
- Now, the published website will open in the browser, then you can export the webpage to PDF.
- By converting HTML to PDF, you will get the PDF document as follows.
A complete working sample can be downloaded from HTMLToPDF_Azure.zip.
Refer here to include the OPENSSL assemblies in Azure website.
Take a moment to peruse the documentation for Converting HTML to PDF, where you will find various options for URL to PDF, HTML string to PDF, and Hyperlinks.
Refer here to explore the rich set of Syncfusion Essential PDF features.
Conclusion
I hope you enjoyed learning about how to display PDF document from URL using SfPdfViewer in Xamarin.Android.
You can refer to our ASP.NET MVC PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our ASP.NET MVC PDF documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our ASP.NET MVC PDF and other ASP.NET MVC components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!