Articles in this section
Category / Section

How to convert HTML to .NET MVC PDF in Azure website?

2 mins read

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:

  1. Open Visual Studio and create ASP.NET MVC project. Create a ASP.NET Web application project
  2. Install the Syncfusion.HtmlToPdfConverter.QtWebkit.AspNet.Mvc5 NuGet package as a reference to your .NET Framework application from the NuGet.org. Install required Nuget packages
  3. Copy the QtBinaries folder from the installed HtmltoPdfConverter package and paste it in the folder that contains the HTMLtoPDF_Azure.csproj file. Location of QtBinaries folder Paste location of QtBinaries

 

  1. After installing the package, include the QtBinaries folder to the project. Screenshot for include QtBinaries in project
  2. Then, set Copy to output directory to copy always to all the QtBinaries (All files including inner folders and files). Screenshot for set copy to output directory to copy always
  3. Add an Export To PDF button in index.cshtml. Add code snippet for Export to PDF button
  4. 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");
}

Screen shot for added code snippet

  1. Now, check the conversion in local machine.

Refer to the following steps to publish as Azure web application:

  1. Right-click the project and select Publish. Publish

 

  1. Create a new profile in publish window. Create new profile in publish window

 

  1. Create App service using Azure subscription and select a hosting plan. Create App Service
  2. 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. Configure hosting plan
  3. After creating a profile, click the publish button. Publish Publish status

 

  1. Now, the published website will open in the browser, then you can export the webpage to PDF. Published website
  2. By converting HTML to PDF, you will get the PDF document as follows. HTML to PDF output document

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 forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied