I currently use Gembox.Document to read content from PDF documents. I have a class library that houses it all and a self hosted .NET Core 3.1 service that references it. I query the service with the PDF data and it responds with the content. I now want to move this functionality to an azure function (v3) instead, but I am running into the following error:
Could not load file or assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
To simplify it I have moved only the essential parts into the azure function which you can see below:
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");
}
}
Is this a restriction of azure functions? I have read several conflicting things which suggest it can and can't be done as it's using a WPF dll. For the record, the GemBox website provides an example for creating a PDF document in an azure function: https://www.gemboxsoftware.com/document/examples/create-word-pdf-on-azure-functions-app-service/5901. So I don't see why I wouldn't be able to read one too!
Thanks!
EDIT 1:
As per mu88's comment, I have changed the .csproj file to the below and it hasn't helped.

GemBox.Documenthas this issue (it might be dependent on .net Framework component), butGemBox.Pdfworks fine as below.I tested it using the
GemBox.Pdfnuget with the below Function and it works fine for both creating and loading pdf in deployed Function app.Create PDF:
LoadPDF: