Search code examples
phpazureazure-web-app-servicewkhtmltopdf

How can i enable wkhtmltopdf in Azure windows App


I'm using WKHTMLTOPDF library for converting html to pdf, previously I hosted my app on ubuntu server, where i can install the library via command line,

I want to migrate to Azure app services, Is there anyway I can use this library (wkhtmltopdf) in Azure windows platform

Please help me on this.


Solution

  • As I known, for Azure WebApp on Windows, any app using GDI is not supported, because there is a Win32k.sys (User32/GDI32) Restrictions introduced by the offical wiki page Azure Web App sandbox, as the figure below.

    enter image description here

    However, wkhtmltopdf without using GDI is a special framework which can be used on Azure WebApp for Windows, but you have to install it first on Azure WebApp without GUI interactive.

    So the only way is first to download the MXE (MinGW-w64) release files of 7z archive format for Windows from the downloads page of offical site or GitHub releases page, as the figures below,

    Fig 1. The offical downloads page

    enter image description here

    Fig 2. The GitHub releases page

    enter image description here

    And to unzip it on local and add it into your PHP project, then append the bin path of wkhtmltopdf to the tail of PATH environment variable via PHP functions getenv and putenv at the start of your PHP app or try to set the PATH value via add a key PATH in appSettings of web.config file.

    Finally, you can use the 3rd party library mikehaertl/phpwkhtmltopdf to do the convert function from HTML to PDF on Azure WebApp for Windows.