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

Free Support Forum - aspose.com

First Selector in External CSS File is ignored in Conversion

Hello,

I am converting an HTML file to PDF and the first selector of the external CSS file is always ignored. I tried this in multiple scenarios.

My CSS File:

#test{
color: red;
}

h1 {
color: green;
}

th {
color: darkblue;
}

.navcode {
color: deeppink;
}


In this case #test will not be applied during conversion.
If I put a selector in front of #test this one is ignored. This is my workaround:
#unused, #test{
color: red;
}

h1 {
color: green;
}

th {
color: darkblue;
}

.navcode {
color: deeppink;
}



Am I doing something wrong or is this a bug?

Hi Philipp,


Thanks for your inquriy. I have tested the scenario using new DOM approach of HTML to PDF conversion with Aspose.Pdf for .NET 11.4.0 and unable to notice the issue. Please download and try latest version of Aspose.Pdf for .NET with new approach, it will resolve the issue. However if the issue persist then please share your input/output files along with sample code here, we will look into it and guide you accordingly.

Best Regards,

This is my code:

            HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions();
htmlLoadOptions.PageInfo.IsLandscape = false;
htmlLoadOptions.PageInfo.Height = 11.69 * 72;
htmlLoadOptions.PageInfo.Width = 8.6 * 72;
htmlLoadOptions.PageInfo.Margin.Left = 0;
htmlLoadOptions.PageInfo.Margin.Right = 0;
htmlLoadOptions.PageInfo.Margin.Top = 0;
htmlLoadOptions.PageInfo.Margin.Bottom = 0;
        <span style="color:green;">//Load HTML string</span>
        <span style="color:#2b91af;">Document</span> doc = <span style="color:blue;">new</span> <span style="color:#2b91af;">Document</span>(<span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>(System.Text.<span style="color:#2b91af;">Encoding</span>.UTF8.GetBytes(htmlpage)), htmlLoadOptions);

        <span style="color:green;">//Save PDF file</span>
        <span style="color:#2b91af;">MemoryStream</span> docStream = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>();
        doc.Save(docStream, <span style="color:#2b91af;">SaveFormat</span>.Pdf);
        docStream.Close();</pre><br><br>HTML:<br><br><span role="treeitem" class="nodeLabelBox repTarget "><<span class="nodeTag ">html</span><span class="nodeBracket editable insertBefore ">></span></span><div role="group" class="nodeChildBox "><div role="presentation" class="nodeBox containerNodeBox open"><div role="presentation" class="nodeLabel "><span role="treeitem" class="nodeLabelBox repTarget "><<span class="nodeTag ">head</span><span class="nodeBracket editable insertBefore ">></span></span></div><div role="group" class="nodeChildBox "><div role="presentation" class="nodeBox textNodeBox  "><div role="presentation" class="nodeLabel "><span role="treeitem" class="nodeLabelBox repTarget "><<span class="nodeTag ">title</span><span class="nodeBracket editable insertBefore ">></span><span class="nodeText editable "><span class="  ">Offer</span></span></<span class="nodeTag ">title</span>></span></div></div><div role="presentation" class="nodeBox containerNodeBox "><div role="presentation" class="nodeLabel "><span role="treeitem" class="nodeLabelBox repTarget "><<span class="nodeTag ">link</span><span class="nodeAttr editGroup "> <span class="nodeName editable ">href</span>="<span class="nodeValue editable ">http://localhost:55557/App_Styles/PdfOfferThemes/Global.css</span>"</span><span class="nodeAttr editGroup "> <span class="nodeName editable ">rel</span>="<span class="nodeValue editable ">stylesheet</span>"</span><span class="nodeAttr editGroup "> <span class="nodeName editable ">type</span>="<span class="nodeValue editable ">text/css</span>"</span><span class="nodeBracket editable insertBefore ">></span></span></div></div></div><div role="presentation" class="nodeCloseLabel "><span class="nodeCloseLabelBox repTarget "></<span class="nodeTag ">head</span>></span></div></div><div role="presentation" class="nodeBox containerNodeBox selected open"><div role="presentation" class="nodeLabel "><span role="treeitem" class="nodeLabelBox repTarget "><<span class="nodeTag ">body</span><span class="nodeBracket editable insertBefore ">></span></span></div><div role="group" class="nodeChildBox "><div role="presentation" class="nodeBox textNodeBox  "><div role="presentation" class="nodeLabel "><span role="treeitem" class="nodeLabelBox repTarget "><<span class="nodeTag ">h1</span><span class="nodeBracket editable insertBefore ">>Offer</span></<span class="nodeTag ">h1</span>><br><h2>2nd line</h2><br></span></div></div></div><div role="presentation" class="nodeCloseLabel "><span class="nodeCloseLabelBox repTarget "></<span class="nodeTag ">body</span>></span></div></div></div><div role="presentation" class="nodeCloseLabel "><span class="nodeCloseLabelBox repTarget "></<span class="nodeTag ">html</span>><br><br><br>Global.css:<br><br></span></div><pre style="font-family:Consolas;font-size:15;color:black;background:white;"><span style="color:maroon;">h1</span>{
<span style="color:red;">color</span>:<span style="color:blue;">red</span>;

}
h2{
color:green;
}


Result in Browser:
h1 is red, h2 is green

Result in Pdf:
h1 is black, h2 is green

Hi Philipp,


Thanks for contacting support.

I have tested the scenario and have observed that color information for both Heading objects is ignored during HTML to PDF conversion. For the sake of correction, I have logged this problem
as PDFNEWNET-40444 in our issue tracking system. We will
further look into the details of this problem and will keep you updated on the
status of correction. Please be patient and spare us little time. We are sorry
for this inconvenience.