Install wkhtmltopdf for Azure Linux App Service Plans
When working with web applications, you may occasionally need to convert HTML content into images or PDFs. In my case, I stumbled upon this requirement and, after a quick search, I discovered a fantastic open-source package called wkhtmltopdf
. This powerful package provides an efficient solution for such conversions, offering two command-line tools: wkhtmltopdf
for converting HTML to PDF, and wkhtmltoimage
for converting HTML to various image formats. You can support the authors here: https://wkhtmltopdf.org/.
While the wkhtmltopdf
package is conveniently included in Windows plans by default, I ran into a challenge when I switched to a Linux plan. My application began throwing exceptions, and I soon realized that the tools were not pre-installed on Linux hosts. Since Azure spins up a new host/container with each application start and any data outside the /home
directory is not persisted, just installing the package is not enough. This article will walk you through the steps to install wkhtmltopdf
on Azure Linux App Service Plans during app startup, ensuring seamless integration with your application.
- Login to Azure Portal
Select your App Service instance. Choose the SSH menu and then open the SSH console.
- Create two files,
install-tools.sh
andstartup.sh
, under the/home/site/wwwroot/
directory. Follow the steps from the screenshot below: Go to your App Service instance again. Choose the
Configuration
menu, theGeneral settings
sub-menu, and update the startup command to./startup.sh
. Save the changes.- In the Overview section of the same page, stop and start the service.
- Your application should be up and running immediately.
After some time (it may take a couple of minutes), connect to the SSH console again and check whether the tool is available.
I hope you found this article useful. Happy coding!
Comments powered by Disqus.