Azure函数无法从ABCpdf Nuget Package

时间:2017-03-23 12:56:45

标签: c# azure azure-functions

这让我有些慌张。我喜欢Azure功能的想法,但故障排除可能具有挑战性。我试图对我公司的免费订阅进行概念验证,将HTML传递给函数并让它吐出PDF。 HTML将包含患者数据,因此我们无法使用公共服务,而且使用大多数普通的HTML到PDF解决方案时,使用javascript和CSS太复杂了。使用Gecko引擎的ABCPdf实际上做得非常好。我们正在迁移到Azure App实例,因此我们无法以这种方式运行它,我希望Azure Functions将是下一个最佳选择。

这是我得到的错误。

  

2017-03-23T12:44:36.941执行函数时出现异常:Functions.NNMakePDF。 ABCpdf:无法加载DLL' ABCpdf10-32.dll':找不到指定的模块。 (HRESULT异常:0x8007007E)。

这是我的project.json

{

"框架":{     " net46":{       "依赖":{         " ABCpdf":" 10.1.2.1",         " ABCpdf.ABCGecko":" 10.1.2.1"       }     }    } }

这里是run.csx中的代码,虽然我不认为它是完全相关的

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;
}

我尝试在run.csx旁边添加一个bin文件夹并将ABCpdf10-32.dll放在那里,但它没有帮助。

1 个答案:

答案 0 :(得分:3)

  

我们正在迁移到Azure App实例,因此我们无法以这种方式运行

功能应用程序在App Service之上运行,因此所有限制都是继承的。

以下链接表示您的HTML-to-PDF生成库可能被沙箱阻止: https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#pdf-generation-from-html

相关问题