#c# #azure #azure-functions
#c# #azure #azure-функции
Вопрос:
Я создал функцию C # Azure для генерации PDF-файлов и использую NReco pdf generator, но он не работает на Aazure.
Не могли бы вы предложить способ заставить его работать в Azure?
Я установил NReco Pdf generator через консоль NuGet Package Manager, и я получаю следующую ошибку:
«Доступ к тропинке ‘D:Program Файлы (x86)SiteExtensionsФункции1.0.12599wkhtmltopdf’ запрещены.
Это трассировка стека исключения, которое генерируется:
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. «Не работает» не является техническим описанием проблемы
Ответ №1:
Я могу сгенерировать PDF, используя следующий функциональный код .. посмотрите, поможет ли это.. Azure functions 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
Комментарии:
1. Это то же самое, что я использую, и все равно я получаю эту ошибку.
2. пожалуйста, посмотрите эту ссылку . Я пробовал это, но все еще не работает
3. дам попробовать на Azure.. Я не пробовал развертывать в Azure