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

标签 c# .net azure pdf gembox-document

我目前使用 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 cannot find 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 you cannot read them.

But also, I should point out that PDF reader in GemBox.Document never left 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 Reading example. With GemBox.Pdf you can read and write PDF files on Azure Functions.

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

唉,GemBox.Document 还不可能。

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

相关文章:

c# - 在 C# 控制台应用程序中访问 dbContext

c# - 覆盖方法中的默认参数值

c# - 将 ref 参数与 this 关键字一起使用?

azure - 无法使用应用程序权限(角色)访问 Microsoft Graph API 组日历

c# - Blazor Web Assembly、OIDC 和 Azure AD B2C 无法处理 token

json - Azure - 逻辑应用程序到服务总线 - JSON 传输

c# - MS SQL 位变量可以吗(@a)?

c# - 如何在C#中实现与定时器的同步

c# - 我可以在 WinForms 中将菜单拆分为多列吗?

.net - 我可以使用 Albacore 任务转换 web.config 吗?