gpt4 book ai didi

c# - 使用 Gembox.Document 的 azure 函数中出现 "Could not load file or assembly 'PresentationCore '"错误

转载 作者:行者123 更新时间:2023-12-05 06:09:12 25 4
gpt4 key购买 nike

我目前使用 Gembox.Document 来读取 PDF 文档中的内容。我有一个包含所有内容的类库和一个引用它的自托管 .NET Core 3.1 服务。我使用 PDF 数据查询服务,它以内容进行响应。我现在想将此功能移至 azure 函数 (v3),但遇到以下错误:

Could not load file or assembly 'PresentationCore, Version=4.0.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannotfind the file specified.

为了简化它,我只将基本部分移到了 azure 函数中,您可以在下面看到:

public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
ComponentInfo.FreeLimitReached += (sender, args) => args.FreeLimitReachedAction = FreeLimitReachedAction.ContinueAsTrial;

try
{
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
ParseRequest data = JsonConvert.DeserializeObject<ParseRequest>(requestBody);

StringBuilder sb = new StringBuilder();

using (var ms = new MemoryStream(data.Data))
{
// Load document from file's path.
var document = DocumentModel.Load(ms, LoadOptions.PdfDefault);

foreach (var childElement in document.GetChildElements(true, ElementType.Paragraph))
{
sb.AppendLine(childElement.Content.ToString());
}
}

return new OkObjectResult(sb.ToString());
}
catch (Exception e)
{
return new OkObjectResult("Unable to read document");
}
}

这是 azure 功能的限制吗?我读过一些相互矛盾的内容,这些内容表明它可以完成,也不能完成,因为它使用的是 WPF dll。作为记录,GemBox 网站提供了一个在 azure 函数中创建 PDF 文档的示例:https://www.gemboxsoftware.com/document/examples/create-word-pdf-on-azure-functions-app-service/5901 。所以我不明白为什么我也不能读一本!

谢谢!

编辑1:

根据 mu88 的评论,我已将 .csproj 文件更改为以下内容,但没有帮助。

enter image description here

最佳答案

我联系了 GemBox 支持,他们回复了 following :

Unfortunately, GemBox.Document uses WPF for reading PDF files. So,even though you can write PDF files on Azure Functions, I’m afraid youcannot read them.

But also, I should point out that PDF reader in GemBox.Document neverleft the BETA stage, it has limited usage. For more information,please check the Support level for reading PDF format (beta) section.

Instead, I would suggest you try out GemBox.Pdf, see its Readingexample. With GemBox.Pdf you can read and write PDF files on AzureFunctions.

Last, in the long term, we plan to replace the current (internal)implementations of both PDF reader (BETA) and PDF writer inGemBox.Document with a newer implementation that’s contained inGemBox.Pdf without changing the public API of GemBox.Document. Butthat will not be done in the current year and for later I cannot sayat this moment.

唉,GemBox.Document 还不可能。

关于c# - 使用 Gembox.Document 的 azure 函数中出现 "Could not load file or assembly 'PresentationCore '"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64893309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com