Azure是否支持NReco pdf生成器?

时间:2019-04-22 05:43:53

标签: c# azure azure-functions

我为pdf生成创建了一个C#Azure函数,并且正在使用NReco pdf生成器,但是在Aazure上不起作用。

能否请您提出一种使它在天蓝色下运行的方法?

我已经通过NuGet软件包管理器控制台安装了NReco Pdf生成器,并且出现以下错误:

  

“拒绝访问路径'D:\ Program Files(x86)\ SiteExtensions \ Functions \ 1.0.12599 \ wkhtmltopdf'。

这是引发的异常的堆栈跟踪:

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)
at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
at System.IO.Directory.CreateDirectory(String path)
at NReco.PdfGenerator.HtmlToPdfConverter.EnsureWkHtmlLibs()
at NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdfInternal(WkHtmlInput[] htmlFiles, String inputContent, String coverHtml, String outputPdfFilePath, Stream outputStream)
at NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdfFromFile(String htmlFilePath, String coverHtml)
at VRProductions.Repository.PdfGenerationRepository.<SendMail>d__1.MoveNext()

这是用于生成pdf的代码:

var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
var pdfBytes = htmlToPdf.GeneratePdfFromFile(blockBlob.Uri.AbsoluteUri, "");

1 个答案:

答案 0 :(得分:1)

我能够使用以下功能代码生成pdf。.查看是否有任何帮助.. Azure功能V1

using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;

namespace FunctionApp41
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");


            var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
            var pdfBytes = htmlToPdf.GeneratePdfFromFile("<file_path_including_sas_token>", "");

            var response = req.CreateResponse(HttpStatusCode.OK);
            response.Content = new StreamContent(new MemoryStream(pdfBytes));
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

            return response;
        }
    }
}

如果从Visual Studio本地运行此功能,则会生成文件,并将pdf加载到浏览器中或要求保存。

http://localhost:7071/api/Function1