我目前使用 Gembox.Document 从 PDF 文档中读取内容。我有一个包含所有内容的类库和一个引用它的自托管 .NET Core 3.1 服务。我用 PDF 数据查询服务,它用内容响应。我现在想将此功能移至 azure 函数 (v3),但我遇到了以下错误:
无法加载文件或程序集“PresentationCore,版本=4.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35”。该系统找不到指定的文件。
为了简化它,我只将基本部分移到了 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");
}
}
这是天蓝色功能的限制吗?我已经阅读了一些相互矛盾的事情,这些事情表明它可以而且不能因为它使用 WPF dll 来完成。作为记录,GemBox 网站提供了一个在 azure 函数中创建 PDF 文档的示例:https ://www.gemboxsoftware.com/document/examples/create-word-pdf-on-azure-functions-app-service/ 5901 . 所以我不明白为什么我也无法阅读!
谢谢!
编辑1:
根据 mu88 的评论,我已将 .csproj 文件更改为以下内容,但没有帮助。