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;
}
}
}
}