We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Bug in Aspose.HTML

Hello Guys

I found a bug in the HTML code while doing a conversion. Converting to a file it converts the fonts perfectly. Converting using a MemoryStream the fonts are not converted.

If I use this code the fonts convert perfectly.

using (ImageDevice device = new ImageDevice(imageRenderingOptions, tempBannerImageFile.Replace("\\", "/")))
    {
        // Initialize Class
        using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer())
        {
            // Initialize Class
            using (Aspose.Html.HTMLDocument document = new Aspose.Html.HTMLDocument(tempBannerFile.Replace("\\", "/")))
               {
                   // Render
                   renderer.Render(device, document);
                }
           }
    }

If I use this code the fonts don’t convert perfectly.

using (ImageDevice device = new ImageDevice(imageRenderingOptions,
                        memoryStream))
                    {
 
                        // Initialize Class
                        using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer())
                        {
 
                            // Initialize Class
                            using (Aspose.Html.HTMLDocument document = new Aspose.Html.HTMLDocument(tempBannerFile.Replace("\\", "/")))
                            {
 
                                // Render
                                renderer.Render(device,
                                    document);
 
                            }
 
                        }
 
                    }

This Topic is created by codewarior using the Email to Topic plugin.

@simon.murrell,

Thanks for contacting support.

I have tested the scenario using following code snippet and I am unable to notice any issue either when saving the output image in Stream instance or saving it as file object on system directory. Can you please share your input HTML and any related details, so that we can test the scenario in our environment. We are sorry for this inconvenience.

[C#]

String SimpleStyledFilePath = "c:/pdftest/FirstFile.html";
using (FileStream fs = File.Create(SimpleStyledFilePath))
using (StreamWriter sw = new StreamWriter(fs))
{
    sw.Write(
        @"<style>
.st
{
color: green;
}
</style>
<div id=id1>Aspose.Html rendering Text in Black Color</div>
<div id=id2 class=st>Aspose.Html rendering Text in Green Color</div>
<div id=id3 class=st style='color: blue;'>Aspose.Html rendering Text in Blue Color</div>
<div id=id3 class=st style='color: red;'><font face='Arial'>Aspose.Html rendering Text in Red Color<</font>/div>
");
}

// Name for resultant PDF file
//string Image_output = "c:/pdftest/simple-any-page.jpg";
FileStream image_stream = new FileStream("c:/pdftest/simple-any-page.jpg",  FileMode.OpenOrCreate);
            // create ImageRendering Options object
Aspose.Html.Rendering.Image.ImageRenderingOptions image_options = new Aspose.Html.Rendering.Image.ImageRenderingOptions();
            // specify the format of resultant image
image_options.Format = Aspose.Html.Rendering.Image.ImageFormat.Jpeg;

// specify the page numbers which will be rendered
// possible values can be AnyPage, FirstPage, LastPage, RightPage
// The AnyPage property Gets/Sets all pages configuration in page sequence
// the size for drawing is in pixels
image_options.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(400, 100));
// instantiate ImageDevice object while passing ImageRenderingOptions and resultant file path as arguments
using (Aspose.Html.Rendering.Image.ImageDevice image_device = new Aspose.Html.Rendering.Image.ImageDevice(image_options, image_stream))
{
    // Create HtmlRenderer object
    using (Aspose.Html.Rendering.HtmlRenderer image_renderer = new Aspose.Html.Rendering.HtmlRenderer())
    {
        // Create HtmlDocument instnace while passing path of already created HTML file
        using (Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(SimpleStyledFilePath))
        {
            // render the output using HtmlRenderer
            image_renderer.Render(image_device, html_document);
        }
    }
}
image_stream.Close();