Support External stylesheet and styles

Dear Team,
We are using Gembox.Document to generate HTML to PDF and we have included css styles in our HTML. We are getting few layout issues and PDF is not generating as expected. On diving deeper we found that few of the styles like flex, float and width CSS not working while generated PDF.

Kindly guide us with an alternative to these CSS if they are not supported with a link or documentations guide.

Hi Tayyab,

Yes, those styles are not supported.

I’m afraid that GemBox.Document doesn’t support changing the “display” CSS property nor specifying the size of the block-level elements (like “div”, “p”, etc.).

Note, GemBox.Document loads any content into a DocumentModel, which is an in-memory representation that has a content model that resembles the closest to the Word document’s structure:
https://www.gemboxsoftware.com/document/docs/content-model.html

So, if some HTML content doesn’t have appropriate representation in a Word file, it’s very likely that GemBox.Document won’t support it.

This is why things like floating, absolute positioning, or size specified “div” elements are not supported.
There is no equivalent element with which to represent them in Word files. They could be presented as TextBox elements but then all the semantics would be lost.

Anyway, in general, in order to get the most accurate representation, you should provide printer-friendly HTML pages to GemBox.Document. In other words, your website’s content and structure should ideally be optimized for print.

Perhaps you could try using a tabular layout to achieve the desired positioning?

In the future, we’ll consider providing a more accurate representation of HTML content, but that will break the document’s semantics. One of those would be to represent the block-level elements with specified size using TextBox which is an inline-level element. There are other such scenarios, like having to represent one HTML element with multiple document elements.

But one of the problems is that HTML content can be loaded at any part of the document, and thus it’s often used with “mail merge”, “find and replace”, etc. actions. Introducing this kind of change would make it a lot harder to process the loaded HTML content in those contexts.

Nevertheless, we will probably introduce an option for this in the future, but at the moment I cannot say exactly when that will be.

Regards,
Mario