LoadImageFromUri with multiple image import

1 Answer 50 Views
PdfProcessing WordsProcessing
Ben
Top achievements
Rank 1
Ben asked on 28 Sep 2023, 08:14 PM

Hi,

I get HTML in my code and I have the image byte in another file. I want to combine it to export my HTML to PDF with images. This is what I do, and it only works with a single image, on the second iteration I got an error in importSettings.LoadImageFromUri (Method = <Internal Error evaluating expression>). What can I do to add multiple images in the importSettings? I don't see an example in the documentation.


foreach (var img in imageList)
{               
  EventHandler<LoadImageFromUriEventArgs> loadImageFromUri = (s, e) =>
  {
    
    byte[] data = img.ContentBytes;
    e.SetImageInfo(data, "jpg");
  };

  importSettings.LoadImageFromUri += loadImageFromUri;                          
}

Thanks

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 03 Oct 2023, 06:19 AM

Hi Ben,

The idea behind the LoadImageFromUri event is to use it to pass the missing in the HTML document image source. So, when importing the HTML file and there is no image data, the event is triggered and the data is searched by name using this event and you need to provide the actual path to it.

I slightly updated the provided code snippet in order to demonstrate what should be its implementation:

importSettings.LoadImageFromUri += (s, e) =>
{
	byte[] data = File.ReadAllBytes("Images/" + e.Uri);
	e.SetImageInfo(data, "png");
};

provider.ImportSettings = importSettings;

RadFlowDocument flowDocument = provider.Import(File.ReadAllText("sample.html"));

I am attaching the sample project I created to test this functionality as well. Please, feel free to modify it in a way closer to your scenario.

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Ben
Top achievements
Rank 1
commented on 03 Oct 2023, 12:41 PM

Hy Martin, 

Thank's for you answer. I really didn't understand that the event was triggered on each image whithout data. Thanks again!

Regards,

Ben

Tags
PdfProcessing WordsProcessing
Asked by
Ben
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or