0

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.

Echostorm
  • 9,678
  • 8
  • 36
  • 50
  • If you do a quick search for `[azure] abcpdf` you'll see a few questions about this (including the one I marked). Azure App Service (where Functions runs) will not let you install some software that has low-level changes such as registry. You'd need to work with a VM (or web/worker role cloud service). – David Makogon Mar 23 '17 at 14:57
  • I did see both that question and your answer from about a year ago. I didn't see anything about requiring registry changes in the abcpdf docs about Azure. All I had to do was include 2 Nuget packages. My error only says it cannot find a dll. Given the time that has passed, the newness of Functions and the changes that Azure undergoes almost daily I felt that it was not unreasonable to ask if this was viable. Having to do this another way is going to cost us more money every month and diminish the reason we're moving to Azure in the first place. Is there anything your team can do about this? – Echostorm Mar 23 '17 at 17:34
  • 1
    The marking as a duplicate here is incorrect. This question relates to the Gecko HTML engine and the duplicate relates to the MSHTML engine. The two have completely different requirements. Look on the ABCpdf web site and there are details about how to deploy on Azure.. – OnceUponATimeInTheWest Jul 13 '17 at 07:44

1 Answers1

3

We're moving to an Azure App instance so we can't run it that way

Function Apps are running on top of App Service, so all the restrictions are inherited.

The following link says your HTML-to-PDF generation library might be blocked by the sandbox: https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#pdf-generation-from-html

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
  • 2
    Again there are two different HTML engines in ABCpdf and they operate in completely different ways. The deployment requirements for one are not the same as those for the other. Details about how to deploy are provided on the ABCpdf web site. – OnceUponATimeInTheWest Jul 13 '17 at 07:46