Docker is a lightweight and very popular container platform that packages an application with everything it needs to run, with the necessary code, system libraries, fonts, other supported libraries, or files.
Visual Studio 2017 and Docker support building and running .NET applications using a Windows docker container and .NET Core application on Linux docker containers.
Syncfusion HTML to PDF converter can be easily integrated into any application with five simple lines of code. Using this library, you can turn an entire webpage into a PDF file. Or just convert a portion of the page. Your PDF will just look like the webpage you converted—it preserves all graphics, images, text, fonts, links, and the layout of the original HTML document or webpage.
Furthermore, Syncfusion HTML to PDF converter is available in Windows Forms, WPF, ASP.NET, ASP.NET MVC, and ASP.NET Core. In this post, I use ASP.NET Core in a Linux Docker container.
- First, download HTML to PDF Linux from our download page. For this demo, I downloaded HTML to PDF for Linux. But you can just as easily download any other installer, like Mac and Windows.
- Make sure to select ASP.NET Core 2.0, enable Docker support, and target the Linux OS.
- Add the Syncfusion.HtmlConverter.NETStandard NuGet packages as a reference to your .NET Core project from the Syncfusion ASP.NET Core NuGet feed. For more information about adding a NuGet feed in Visual Studio and installing the NuGet package, refer to our documentation. You can also install this package from the NuGet package manager console by executing the following command.
- Extract the downloaded .zip file and refer the QtBinaries physical path to the WebKitPath from the WebKitConverterSettings class.
Can you show us some code?
//Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Set WebKit path htmlConverter.ConverterSettings.WebKitPath = Path.Combine(_hostingEnvironment.ContentRootPath, "QtBinaries"); //Convert URL to PDF PdfDocument document = htmlConverter.Convert("http://www.google.com"); MemoryStream ms = new MemoryStream(); //Save and close the PDF document document.Save(ms); document.Close(true);
Include the below snippet in the docker file to install the dependent packages in the docker container.
Build and run the sample in the docker, it will pull the Linux docker image from the docker hub and run the project. Now, the webpage will open in the browser. Click Convert to PDF to convert the Google webpage to a PDF.
This sample is made as simple as possible for converting a.
Whether you need to convert a URL, webpage, or HTML string to PDF in the docker containers, the Syncfusion HTML to PDF converter libraries make work short for .NET developers. With our libraries, we can even convert SVG and MHTML to PDF. There are advanced features such as form authentication, header, footer, table of contents, and automatic bookmark hierarchy based on heading style. Take a moment to peruse the documentation, where you’ll find other options and features, all with accompanying code examples.
If you’re already a Syncfusion user, you can download the product setup on Direct-Trac. If you’re not yet a Syncfusion user, you can download a free, 30-day trial .
If you like this blog post, we think you’ll also like the following free e-books: