Closed irico-epi closed 11 months ago
This PR is not necessary, because this case after converting it to a URL, will be handled, and if you think it's not, show us a sample about it. Post an exception, something, ... Also follow this sample.
The problem is that URI has a limitation on the maximum string length, and for very large images, it throws an exception on the URI constructor. I'm attaching a small sample code to reproduce the error, as well as a screenshot of the error it throws.
Sample code:
` try { //I've removed part of the base64 image because it was too large and badly formatted. I'm attaching the image so that you can use it for testing. string filename = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEBXAFcAAD/4QAiRXhpZg ......";
Uri url = ConsoleApp1.Utilities.ToUrl(filename);
if (url == null)
{
throw new ArgumentNullException(nameof(url));
}
// Add support for base64 encoded images.
if (url.Scheme == "data")
{
Console.WriteLine("It is base64 image");
}
} catch (Exception ex) { Console.WriteLine(ex.ToString()); } `
OK. I will add it later without duplicating the same code block twice.
When creating a PDF from HTML, if the 'img' tag contains a base64-encoded image, it attempts to convert it into a URL. In the case of small images, it works well, but for larger images, it generates an exception. By verifying in advance if the 'img' tag contains a base64 image and handling it specifically, the issue is resolved.