Posted 20 July 2023, 6:05 pm EST
We are using GrapeCity.Documents.Word and GrapeCity.Documents.Layout nuget package in a .Net Web API project to replace keywords in a Word template with text and images and save it as a PDF using GcWordLayout SaveAsPdf method.
This works great when we run the application locally but when we deploy it to Azure as an AppService, the images are replaced with a red box with a cross. This happens with both static as well as dynamic images inserted into the document.
Code snippet to add images in the document
[code]foreach (Attachment att in attachments)
{
par.GetRange().Runs.Add();
pic = par.GetRange().Runs.Last.GetRange().Pictures.Add();
pic.ImageData.SetImage(att.Content, att.Type);
pic.Size.Width.Value = 200;
pic.Size.Height.Value = 200;
par.GetRange().Runs.Add();
par.GetRange().Runs.Last.GetRange().Texts.AddBreak();
par.GetRange().Runs.Last.GetRange().Texts.Add(att.Name);
par.GetRange().Runs.Last.GetRange().Texts.AddBreak();
par.GetRange().Runs.Last.GetRange().Texts.AddBreak();
}[/code]
Code snippet to save as PDF
[code]using (var layout = new GcWordLayout(_doc))
{
log.Info($“Saving PDF to {Path.GetTempPath() + fileName}”);
layout.SaveAsPdf(Path.GetTempPath() + fileName);
byte[] pdfByteArray = System.IO.File.ReadAllBytes(Path.GetTempPath() + fileName); System.IO.File.Delete(Path.GetTempPath() + fileName); return pdfByteArray; }[/code]
Appreciate any quick help on this.