This is driving me a bit batty. I love the idea of Azure Functions but troubleshooting can be challenging. I'm trying to do a proof of concept on my company's free subscription to pass HTML into a function and have it spit out a PDF. The HTML will have patient data so we can't use a public service and it is too complex and littered with javascript and CSS to use most normal html to PDF solutions. ABCPdf with the Gecko engine actually does this really well. We're moving to an Azure App instance so we can't run it that way and my hope was that Azure Functions would be the next best thing.
This is the error I get.
2017-03-23T12:44:36.941 Exception while executing function: Functions.NNMakePDF. ABCpdf: Unable to load DLL 'ABCpdf10-32.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E).
This is my project.json
{
"frameworks": { "net46":{ "dependencies": { "ABCpdf": "10.1.2.1", "ABCpdf.ABCGecko": "10.1.2.1" } } } }
and here is the code in run.csx though I don't think it is entirely relevent
using System.Net;
using System.Net.Http.Headers;
using WebSupergoo.ABCpdf10;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("Processing PDF Request");
string html = await req.Content.ReadAsStringAsync();
XSettings.InstallLicense("License Key Goes Here");
Doc theDoc = new Doc();
theDoc.HtmlOptions.UseScript = true; // set to true if your layout is JavaScript-dependent
// add the first page of HTML. We save the returned ID as this will be used to add subsequent pages
theDoc.Page = theDoc.AddPage();
int imageID;
theDoc.HtmlOptions.Engine = EngineType.Gecko;
imageID = theDoc.AddImageHtml(html);
// now chain subsequent pages together. We stop when we reach a page which wasn't truncated
while (true)
{
if (!theDoc.Chainable(imageID))
{ break; }
theDoc.Page = theDoc.AddPage();
imageID = theDoc.AddImageToChain(imageID);
}
// After adding the pages we can flatten them. We can't do this until after the pages have been added because flattening will invalidate our previous ID and break the chain - flattening reduces the file size dramatically.
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
byte[] binaryPDF = theDoc.GetData();
log.Info($"PDF Generated. Length={binaryPDF.Length}");
var res = new HttpResponseMessage(HttpStatusCode.OK);
res.Content = new ByteArrayContent(binaryPDF);
res.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
res.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline");
return res;
}
I have tried adding a bin folder next to the run.csx and putting the ABCpdf10-32.dll there but it doesn't help.