Adding image to an ASPNET api from an external website

Posted by: smakilan on 11 September 2023, 4:30 am EST

    • Post Options:
    • Link

    Posted 11 September 2023, 4:30 am EST

    We developed an api that handles pdf printing using grapecity word. I would like to add an image from an external site and based on the documentation https://www.grapecity.com/documents-api-word/docs/online/images.html the only option I have is by adding an image through Stream. I can see on the example you are using System.Drawing.Image which is not available (Classes within the System.Drawing.Imaging namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.) . Do you have any example/documentation that handles this in an ASPNET api? Thank you.

  • Posted 12 September 2023, 4:56 am EST

    Hello,

    Please refer to the following code snippet and the attached sample to load the image from an external site.

    
                          var _path = @"https://images.g2crowd.com/uploads/product/image/large_detail/large_detail_26f3682cca12d5731ad87ce6a0313183/wijmo.jpg";
                            WebClient client = new WebClient();
                            byte[] content = client.DownloadData(_path);
                        
    
                            var pic1 = par.GetRange().Runs.Last.GetRange().Pictures.Add();
                            pic1.ImageData.SetImage(content, "jpg/JPG");

    The sample also shows how to load the images from the same server in WebApi.

    Hope it helps!

    Regards,

    Manish Gupta

    ImagesInWord_PDF_Local_External.zip

  • Posted 12 September 2023, 8:21 pm EST

    Hi Manish, this works as expected.

    Thank you very much!

Need extra support?

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

Learn More

Forum Channels