SaveAsPdf is missing images in the generated PDF on the server

Posted by: abdulkader.lashkarwala on 20 July 2023, 9:05 am EST

  • Posted 20 July 2023, 9:05 am 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.

  • Posted 23 July 2023, 10:57 pm EST

    Hi Abdul,

    It seems like a duplicate case. We have already replied here: https://www.grapecity.com/my-account/my-support/case/203f2ba7-c426-ee11-9966-000d3a4e0eeb

    Please follow the above MY Support thread.

    Regards,

    Nitin

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels