2X faster development
The ultimate ASP.NET Core UI toolkit to boost your development speed.
The Syncfusion HTML to PDF converter is a .NET library for converting webpages, SVG, MHTML, and HTML to PDF using C#. It is reliable and accurate. The result preserves all graphics, images, text, fonts, and the layout of the original HTML document or webpage. Using this library, you can convert an HTML to PDF in Azure App Service on Linux. Steps to convert HTML to PDF in Azure App service on Linux:
5.1Using SSH command line:
5.2Running the commands from C#
// [C# Code] private void InstallDependecies(string shellFilePath) { Process process = new Process { StartInfo = new ProcessStartInfo { FileName = "/bin/bash", Arguments = "-c " + shellFilePath, CreateNoWindow = true, UseShellExecute = false, } }; process.Start(); process.WaitForExit(); }
// [C# Code] //To get content root path of the project private readonly IHostingEnvironment _hostingEnvironment; public HomeController(IHostingEnvironment hostingEnvironment) { _hostingEnvironment = hostingEnvironment; } //To Export HTML to PDF public IActionResult ExportToPDF() { Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development"); //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = Path.Combine(_hostingEnvironment.ContentRootPath, "QtBinariesLinux"); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert HTML string to PDF PdfDocument document = htmlConverter.Convert("http://www.google.com"); //Save the document into stream MemoryStream stream = new MemoryStream(); document.Save(stream); stream.Position = 0; //Close the document document.Close(true); //Defining the ContentType for pdf file string contentType = "application/pdf"; //Define the file name string fileName = "Output.pdf"; //Creates a FileContentResult object by using the file contents, content type, and file name return File(stream, contentType, fileName);
Refer to the following steps to publish as Azure App Linux:
A complete work sample for converting an HTML to PDF in Azure App service on Linux can be downloaded from AzureAppLinux_CoreSample.zip. Take a moment to peruse the documentation, where you will find other WebKit, Blink, and IE rendering engines supported by Syncfusion .NET PDF library for converting HTML pages to PDF document along with respective customization options and features. Click here to explore the rich set of Syncfusion Essential PDF features. An online sample link to convert HTML to PDF. HTML to PDF conversion in Linux docker container HTML to PDF conversion in Azure Function HTML to PDF conversion in ASP .Net Core Linux HTML to PDF conversion in Azure App Service
|
2X faster development
The ultimate ASP.NET Core UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.