Image not properly creating from HTML to PNG in Linux System

We are facing issue in linux system while creating PNG from HTML. Same is working fine in windows system. below code we are using. If you see in Linux.png, you can see space between words where as Windows.png seems fine.

Linux.png (9.4 KB)
Windows.png (73.0 KB)

   static void CreateImage()
        {
 ImageGenerateFolderPath = "D://Document//";
            var htmlContent = File.ReadAllText(ImageGenerateFolderPath + "//SampleHTML.txt", Encoding.UTF8);

            Stream outputStream = new MemoryStream();
            Aspose.Html.Rendering.Image.ImageRenderingOptions pdf_options = new Aspose.Html.Rendering.Image.ImageRenderingOptions(Aspose.Html.Rendering.Image.ImageFormat.Png);
            using (Aspose.Html.Rendering.Image.ImageDevice png_device = new Aspose.Html.Rendering.Image.ImageDevice(pdf_options, outputStream))
            {
                using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer())
                {
                    try
                    {
                        using (Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(htmlContent, string.Empty))
                        {
                            // Render the output using HtmlRenderer
                            renderer.Render(png_device, html_document);
                            using (var streamProvider = new MemoryStreamProvider())
                            {
                                // Convert HTML to Image by using the MemoryStreamProvider
                                Aspose.Html.Converters.Converter.ConvertHTML(html_document, new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Png), streamProvider);

                                // Get access to the memory stream that contains the result data
                                var memory = streamProvider.Streams.First();
                                memory.Seek(0, System.IO.SeekOrigin.Begin);
                                using (Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(memory))
                                {
                                    // Create an instance of Rectangle class with desired size, Perform the crop operation on object of Rectangle class and Save the results to disk
                                    Aspose.Imaging.Rectangle rectangle = new Aspose.Imaging.Rectangle(0, 0, 1250, 710);
                                    rasterImage.Crop(rectangle);


                                    using (var memoryStream = new MemoryStream())
                                    {
                                        rasterImage.Save(memoryStream);
                                        var finalImage = Convert.ToBase64String(memoryStream.ToArray());
                                        File.WriteAllBytes(ImageGenerateFolderPath + "Base64ofImage.png", memoryStream.ToArray());
                                    }
                                }

                            }

                        }

                    }
                    catch (Exception ex)
                    {

                        throw ex;
                    }
                }
            }
}

@cyginfo

Please make sure that the fonts used in your HTML document are installed on the system where you are doing the HTML to image conversion.

The Linux.png is empty image. Could you please attach it again along with input HTML? Please also share the output image file that is generated by Aspose.HTML using following line of code.

Aspose.Html.Converters.Converter.ConvertHTML(html_document, new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Png), streamProvider);

We will then investigate the issue either this issue is with Aspose.HTML or Aspose.Imaging and provide you more information on it.

Hi,

We also tried to generate image with your shared code snip.
but result is same as previous.

Attached 7z file which contains below 4 documents.

1.) Sample.html : Html template which convert into image.
2.) CodeSample.txt : file with c# code snip which generate html to image.
3.) Window_Generated_Image.png : Which Perfect working as expected.
4.) Linux_GeneratedImage.png : Random Space issue with Linux system.
`

Let me know if something require more.AsposeIssue.7z (96.8 KB)

@cyginfo

Please execute the following code example at your end and share the output PNG. Thanks for your cooperation.

Stream outputStream = new MemoryStream();
Aspose.Html.Rendering.Image.ImageRenderingOptions pdf_options = new Aspose.Html.Rendering.Image.ImageRenderingOptions(Aspose.Html.Rendering.Image.ImageFormat.Png);
using (Aspose.Html.Rendering.Image.ImageDevice png_device = new Aspose.Html.Rendering.Image.ImageDevice(pdf_options, outputStream))
{
    using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer())
    {
        try
        {
            using (Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(htmlContent, string.Empty))
            {
                // Convert HTML to Image by using the MemoryStreamProvider
                Aspose.Html.Converters.Converter.ConvertHTML(html_document, new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Png), MyDir + "output.png");
            }

        }
        catch (Exception ex)
        {
        }
    }
}

Hi,

Attached two images which is generated by your shared code example.
Issue is still persistent. Please do needful.
output_1_Linux.png (66.1 KB)
output_1_window.png (124.9 KB)

@cyginfo

We have logged this problem in our issue tracking system as HTMLNET-3901. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@cyginfo

Could you please share the Linux distribution and .NET version you used at your side?

Below is requested information,

Ubuntu VERSION :20.04.3 LTS
.NET Core SDK Version: 3.1.416

@cyginfo

Thanks for sharing the detail. We will inform you once there is an update available on this issue.

Hello,

Any update on this?

@cyginfo

Unfortunately, there is no update available on this issue at the moment. We will be sure to inform you via this forum thread once there is an update available on it.

Can we have update on this issue when are you going to fix as it is open since long now?

@cyginfo

We regret to share with you that there is no update available on it. We will inform you once this issue is resolved.

@tahir.manzoor ,
we also have similar requirement of hosting the website on linux. we’ve integration of aspose. let us know if the issue is resolved. we want to host on linux.

@NPSwaroop

We are afraid that the ticket is not yet resolved. We have logged your concerns and will surely inform you once the ticket is resolved. Please spare us some time.

The issues you have found earlier (filed as HTMLNET-3901) have been fixed in this update. This message was posted using Bugs notification tool by avpavlysh