HTML to PDF - not all CSS rules are applied

In our scenario we convert a HTML file to a PDF file. It seems that Aspose PDF renderer does not apply all CSS rules we used in our HTML template. As example: the anchor color is blue (#428bca) instead of green (#009b7d) and there is space between the rows.

The source HTML file is “Example2.html”, and the “Example2.pdf” is the output we get after processing (see the attached zip file) .


Information:
Aspose.Pdf for .NET 11.6.0 via NuGet


Code extract:
// setup the HTML load options
var htmlLoadOptions = new HtmlLoadOptions(Path.GetDirectoryName(inputFilePath))
{
PageInfo =
{
Width = PageSize.A4.Width,
Height = PageSize.A4.Height,
Margin = new MarginInfo(25, 20, 25, 20)
}
};

// convert the HTML to PDF
using (var document = new Document(inputFilePath, htmlLoadOptions))
{
// save the PDF
document.Save(outputFilePath);
}

Can you help us find out why this happens?

Hi Bernd,

Thanks for your inquiry. I have tested your scenario with shared HTML document using Aspose.Pdf for .NET 11.6.0 and managed to observe the reported CSS rendering issue. For further investigation, I have logged an issue in our issue tracking system as PDFNEWNET-40893 and also linked your request to it. We will keep you updated via this thread regarding the issue status.

We are sorry for the inconvenience caused.

Best Regards,

Hello,
I found some new (or maybey the same) problems when converting html to pdf:

  1. style rules inside the media query “@media print” takes no effect, as example: background color, hide elements on print
  2. list style elements are not printed
  3. position and size of button does not match

Sample Files are included in the zip package.

Does this help to fix the problem? Do you have a workaround?

Best Regards, Bernd
Hi Bernd,

Thanks for your inquriy.

WinniB:

1. style rules inside the media query "@media print" takes no effect, as example: background color, hide elements on print


I have noticed that @media print style is not being honored in HTML to PDF conversion, so logged a ticket PDFNET-40985 for further investigation and rectification.

WinniB:

2. list style elements are not printed


List style are not being rendered as excepted, so logged a ticket PDFNET-40984 in issue tracking system for rectification.

WinniB:

3. position and size of button does not match


I have also noticed the button rendering issue and logged a ticket PDFNET-40983 for rectification.

I am afraid we can not share any workaround/ETA for these issues before completion of issue investigation. We will notify you as soon as we made some significant progress towards issues' resolution.

We are sorry for the inconvenience caused.

Best Regards,

The issues you have found earlier (filed as PDFNET-40893) have been fixed in Aspose.PDF for .NET 22.12.

The issues you have found earlier (filed as PDFNET-40985) have been fixed in Aspose.PDF for .NET 23.7.

The issues you have found earlier (filed as PDFNET-40984) have been fixed in Aspose.PDF for .NET 23.8.

This css rule is not working
.ps_gg body { background-color: rgba(255, 0, 0, 1) }
the whole body is red and I wont this

@gonzalo.tieri

Can you please share your sample HTML in .zip format with us? We will test the scenario in our environment and address it accordingly.