Pdftron with Azure App Service

Product: PDFTron.NETCore.Windows.x64

Product Version: 9.2.0

Please give a brief summary of your issue:
(Think of this as an email subject)
Bad allocation when using pdftron in Azure

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)
I have taken some code to test pdf creation from a template (PDFTron) and everything works fine locally. When I push the code to an App Service running in Azure I get the following exception

pdftron.Common.PDFNetException

Exception:
Message: document layout failed: bad allocation
Conditional expression:
Version : 9.2.0-91be0af529
Platform : Windows
Architecture : AMD64
Filename : FlowToPDFConversion.cpp
Function : PDF::DocxConversion::Convert()
Linenumber : 189

As it says bad allocation I was suspecting a memory issue, but I checked the App Service and there is plenty of memory available and when I run the code locally I see no issues in huge memory usage either.

This is the code I’m using:

var templateParams = new
{
    Title = $"Hello world"
};

using var doc = new PDFDoc();
var templateOptions = new OfficeToPDFOptions();
templateOptions.SetTemplateParamsJson(JsonSerializer.Serialize(templateParams));
pdftron.PDF.Convert.OfficeToPDF(doc, "DownloadTemplate.docx", templateOptions);
doc.Save(outputStream, pdftron.SDF.SDFDoc.SaveOptions.e_linearized);

Can someone help me figure out what’s going wrong?

Thank you for bringing this to our attention. We are looking into this issue, and will provide you with an update as soon as we have it.

@EBVV @shakthi124 Has there been a solution to this issue? I’m getting the same error in Azure, while it works locally.

Exception: 
	 Message: document layout failed: bad allocation
	 Conditional expression: 
	 Version      : 9.2.0-91be0af529
	 Platform     : Windows
	 Architecture : AMD64
	 Filename     : FlowToPDFConversion.cpp
	 Function     : PDF::DocxConversion::Convert()
	 Linenumber   : 189

Yes, this should be resolved now. Please download latest PDFNet 9.2 SDK below.

Look for PDFNetC64.zip download

Hello

After trying with latest PDFNet 9.3, we are still facing issue with azure service, in local the microsoft document file converts within seconds to PDF/XOD. however we deploy same code to azure app service (azure functions). we are seeing same issue with above errors or takes lot of time to respond(around 2/3 hours) with the same file. Which is like a small document file of 1.8 mb.

Could you please try disabling GDI+ usage in our SDK and see if this helps with the conversion time?

In order to disable GDI+, you can append the text DisableGDI to the end of your license key when passing it to the initialize call. For example:

PDFNet.Initialize("yourkey:1631666319960:78cf123203000000002b24438cc6ce84e9368054a9f79ABCDEF123DisableGDI");

Hi Ryan

thanks for quick response, disable GDI works like a charm.

Just wanted to confirm what features will it stop if i disable GDI? We use annotations, bookmarks, pulling thumbnail image from a document.

This only affects font substitution server side, when you are doing the conversion. In this mode PDFNet will no longer use the fonts registered with Windows OS.

Instead, for decent initial font coverage, please follow this guide, and download the Self serve font package.