0

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.

Anil kumar
  • 4,107
  • 1
  • 21
  • 36
  • It's possible to use Azure app service with Linux if you prefer... https://learn.microsoft.com/en-us/azure/app-service/containers/app-service-linux-intro – ADyson Oct 10 '19 at 10:14
  • I want to use Windows platform for my app, is it possible for windows ? – Anil kumar Oct 10 '19 at 10:15
  • 1
    Why do you want to use Windows, specifically? With the linux one you can, as I understand from reading that article, optionally deploy your own Docker container with all the language features, 3rd party software you need already installed...so you could basically lift and shift your existing app onto Azure. WKHTMLTOPDF does have windows builds. However app service for windows is provided as a sandbox, you can't really make changes to it other than deploying your own code. – ADyson Oct 10 '19 at 10:20
  • If you still want to go down that route, you could potentially modify your app a bit so it offloads the HTML to PDF processing onto a 3rd party API such as https://www.api2pdf.com/wkhtmltopdf-on-aws-lambda/ – ADyson Oct 10 '19 at 10:21
  • Another alternative might be to ditch WKHTMLTOPDF and use a PHP-only library like one of these: https://ourcodeworld.com/articles/read/226/top-5-best-open-source-pdf-generation-libraries-for-php so you can just deploy it along with the rest of your PHP code. – ADyson Oct 10 '19 at 10:25
  • 1
    So (from a few moments of googling) there are a few options you can consider if you are prepared to be flexible and use your imagination....you'll have to decide what suits your situation best. The one thing you can't do is just install and run the WKHTMLTOPDF executable in a windows-based app service. The question might be better posed as how to convert HTML to PDF within an App Service using PHP, rather than focusing on one specific library. – ADyson Oct 10 '19 at 10:26

1 Answers1

1

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.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43