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

Free Support Forum - aspose.com

Invalid table formatting in inline HTML conversion

Given this simple HTML:

<!DOCTYPE html>

<html lang=“en” xmlns=http://www.w3.org/1999/xhtml>
<head>
<meta charset=“utf-8” />
<title>Test Page</title>
<style>
.Title {
font-size: 18pt;
font-weight: bold;
}

        <span style="color: maroon;">body</span> { <span style="color: red;">font-family</span>: <span style="color: blue;">Arial</span>; }
    <span style="color: blue;"></</span><span style="color: maroon;">style</span><span style="color: blue;">></span>
<span style="color: blue;"></</span><span style="color: maroon;">head</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">body</span><span style="color: blue;">></span>
    <span style="color: blue;"><</span><span style="color: maroon;">table</span> <span style="color: red;">style</span><span style="color: blue;">=</span><span style="color: blue;">"</span><span style="color: red;">width</span>: <span style="color: blue;">100%</span>; <span style="color: red;">border</span>: <span style="color: blue;">1px</span> <span style="color: blue;">solid</span> <span style="color: blue;">black</span>;<span style="color: blue;">"</span><span style="color: blue;">></span>
        <span style="color: blue;"><</span><span style="color: maroon;">tr</span><span style="color: blue;">><</span><span style="color: maroon;">td</span> <span style="color: red;">style</span><span style="color: blue;">=</span><span style="color: blue;">"</span><span style="color: red;">width</span>: <span style="color: blue;">85%</span><span style="color: blue;">"</span><span style="color: blue;">><</span><span style="color: maroon;">div</span> <span style="color: red;">class</span><span style="color: blue;">=</span><span style="color: blue;">"Title"</span><span style="color: blue;">></span>ACME<span style="color: blue;"><</span><span style="color: maroon;">sub</span><span style="color: blue;">></span><span style="color: red;">&trade;</span><span style="color: blue;"></</span><span style="color: maroon;">sub</span><span style="color: blue;">></span> Tools<span style="color: blue;"></</span><span style="color: maroon;">div</span><span style="color: blue;">></</span><span style="color: maroon;">td</span><span style="color: blue;">><</span><span style="color: maroon;">td</span> <span style="color: red;">style</span><span style="color: blue;">=</span><span style="color: blue;">"</span><span style="color: red;">width</span>: <span style="color: blue;">15%</span><span style="color: blue;">"</span><span style="color: blue;">></span>DATE<span style="color: blue;"></</span><span style="color: maroon;">td</span><span style="color: blue;">></</span><span style="color: maroon;">tr</span><span style="color: blue;">></span>
    <span style="color: blue;"></</span><span style="color: maroon;">table</span><span style="color: blue;">></span>
<span style="color: blue;"></</span><span style="color: maroon;">body</span><span style="color: blue;">></span>

</html>

and this code copied from documentation:

        private static void ConvertHtmlFile(string fileName)
{
var pdf = new Pdf();
        <span style="color: blue;">var</span> section = pdf.Sections.Add();
        section.IsLandscape = <span style="color: blue;">true</span>;
        section.PageInfo.Margin = <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">MarginInfo</span> {
                                                     Bottom = 18,
                                                     Top = 18,
                                                     Left = 18,
                                                     Right = 18
                                                 };
        section.BackgroundColor = <span style="color: blue;">new</span> Aspose.Pdf.Generator.<span style="color: rgb(43, 145, 175);">Color</span>(200, 200, 200);
        <span style="color: blue;">var</span> fileInfo = <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">FileInfo</span>(fileName);
        <span style="color: blue;">using</span> (<span style="color: blue;">var</span> fs = <span style="color: rgb(43, 145, 175);">File</span>.OpenText(fileName))
        {
            <span style="color: blue;">var</span> text = <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">Text</span>(section, fs.ReadToEnd()) {
                IsHtmlTagSupported = <span style="color: blue;">true</span>,
                IsHtml5Supported = <span style="color: blue;">true</span>};
            section.Paragraphs.Add(text);
            section.Paragraphs.Add( <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">Text</span>(NLipsum.Core.<span style="color: rgb(43, 145, 175);">LipsumGenerator</span>.Generate(3)));
            pdf.Save(<span style="color: blue;">string</span>.Format(<span style="color: rgb(163, 21, 21);">"</span><span style="color: mediumseagreen;">{0}</span><span style="color: rgb(163, 21, 21);">\\</span><span style="color: mediumseagreen;">{1}</span><span style="color: rgb(163, 21, 21);">.pdf"</span>, fileInfo.Directory, fileInfo.Name.Remove(fileInfo.Name.IndexOf(fileInfo.Extension))));

        }
    }

the PDF generated seems to have the table element sized to the portrait mode, not landscape (attached). Is there a workaround available?

Darek

Hi Darek,

Sorry for the inconvenience faced. While testing the scenario with latest version of Aspose.Pdf for NET 8.2.0, I've managed to reproduce this issue on my side and logged the issue in our bug tracking system as PDFNEWNET-35563 for further investigation and resolution. I've also linked your request to this issue and you will be notified via this thread as soon as it is resolved.

Please feel free to contact us for any further assistance.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-35563) have been fixed in Aspose.Pdf for .NET 8.3.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.