PDF in Azure App Service e.g. IronPDF


Use PDF in Azure App Service e.g. IronPDF



Issue

·       I am using some PDF class library which is working fine in local but not working after deploying to Azure App Service?

·       It fails with HTTP 500 exception

·       How can I generate PDF In azure app service application?

·       e.g. IronPDF

Solution:

This is very common issue. To understand this in details first we should know how does Azure App Service works.

All Azure Web Apps (as well as Mobile App/Services, WebJobs and Functions) run in a secure environment called a sandbox
Each app runs inside its own sandbox, isolating its execution from other instances on the same machine as well as providing an additional degree of security and privacy which would otherwise not be available

If you read more about Sandbox in above URL then you will see that,
There are multiple libraries used to convert HTML to PDF. Many Windows/.NET specific versions leverage IE APIs and therefore leverage User32/GDI32 extensively. These APIs are largely blocked in the sandbox (regardless of plan) and therefore these frameworks do not work in the sandbox.

There are some frameworks that do not leverage User32/GDI32 extensively (wkhtmltopdf, for example) and we are working on enabling these in Basic+ the same way we enabled SQL Reporting.

I am taking example of IronPDF here which is mostly used PDF library.
If you decompile it you will see references to a Chrome Engine and user32.dll and gdi32.dll.



This is one of the prime reason which was preventing your code to generate the Pdf while in local it was working fine.
How to solve this then?
One possibility is to use Windows Containers on App Service.
You can get more information on below URL,

For more info, this is the announcement:

Similarly if you want to use Excel in Azure App service you have to install it’s provider which is not supported but you have workaround which you can find in below URL,https://azureappservices.blogspot.com/2019/07/use-excel-in-azure-app-service-or-web.html