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.
//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("https://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 webpage to PDF.
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.
As always, your feedback is highly appreciated, so please do reach out in our comments. You can also contact us through our support forum or Direct-Trac. We are happy to assist you!
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 on our website.
If you like this blog post, we think you’ll also like the following free e-books:
PDF Succinctly
Linux Succinctly
ASP.NET Core Succinctly
.NET Core Succinctly