首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure中支持NReco pdf生成器吗?

Azure中支持NReco pdf生成器吗?
EN

Stack Overflow用户
提问于 2019-04-22 05:43:52
回答 1查看 625关注 0票数 1

我已经创建了一个用于pdf生成的C# Azure函数,并且正在使用NReco pdf生成器,但它并不在Aazure上工作。

你能建议一种使它在蔚蓝中运行的方法吗?

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

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

这是抛出的异常的堆栈跟踪:

代码语言:javascript
复制
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的代码:

代码语言:javascript
复制
var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
var pdfBytes = htmlToPdf.GeneratePdfFromFile(blockBlob.Uri.AbsoluteUri, "");
EN

回答 1

Stack Overflow用户

发布于 2019-04-22 06:13:19

如果有任何帮助的话,我可以使用下面的函数code..see生成pdf。Azure函数V1

代码语言:javascript
复制
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;
        }
    }
}

如果您在本地运行此函数,则将生成可视studio..file,并在浏览器中加载pdf或要求保存。

代码语言:javascript
复制
http://localhost:7071/api/Function1
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55789672

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档