简体   繁体   English

Azure 是否支持 NReco pdf 生成器?

[英]Is NReco pdf generator supported in Azure?

I have created a C# Azure function for pdf generation and am using the NReco pdf generator, but it is not working on Aazure.我已经为 pdf 生成创建了一个 C# Azure 函数,并且正在使用 NReco pdf 生成器,但它不适用于 Aazure。

Could you please suggest a method to make it run in azure?你能建议一种方法让它在天蓝色运行吗?

I have installed NReco Pdf generator through NuGet Package Manager Console and I am getting the following error:我已经通过 NuGet 包管理器控制台安装了 NReco Pdf 生成器,但出现以下错误:

"Access to the path 'D:\\Program Files (x86)\\SiteExtensions\\Functions\\1.0.12599\\wkhtmltopdf' is denied. “访问路径 'D:\\Program Files (x86)\\SiteExtensions\\Functions\\1.0.12599\\wkhtmltopdf' 被拒绝。

This is the stacktrace of exception that is thrown:这是抛出的异常的堆栈跟踪:

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()

This is the code am using for pdf generation:这是用于 pdf 生成的代码:

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

I am able to generate pdf using following function code..see if this of any help.. Azure functions V1我可以使用以下函数代码生成 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;
        }
    }
}

if you run this function locally from visual studio..file will be generated and pdf will be loaded in browser or asked to save.如果您从 Visual Studio 本地运行此功能。将生成文件,并在浏览器中加载 pdf 或要求保存。

http://localhost:7071/api/Function1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM