[reportlab-users] Alternative paragraph implementation with HTML and CSS

Dirk Holtwick dirk.holtwick at gmail.com
Tue Jul 14 11:13:15 EDT 2009


Hi,

while cleaning up my computer I found some old code I worked on last
year. It is not completed but some stuff already works.

This is basically a new paragraph implementation based on some kind of
box model. It takes a DOM structure with CSS style informations and then
renders the corresponding paragraph. Maybe this could become interesting
as a sophisticated paragraph replacement in the RL toolkit some time.
Here is the code:

http://code.google.com/p/xhtml2pdf-base/source/browse/src/xhtml2pdf/paragraph.py

The parsing of the HTML and the enriching of the DOM with CSS style
information can be done in various ways. In the test implementation I
use the html5lib and Techgames CSS parser. But here is an example of how
this might be achieved by using lxml and cssutils too.

http://code.google.com/p/xhtml2pdf-base/source/browse/helpers/apply_styles.py

Genshi might also be a good solution. Here is some CSS to DOM mapping
implemented:

http://code.google.com/p/pyxer/source/browse/src/pyxer/template/cssselect.py

Since I will not find the time to bring this effort to an end quite
soon, maybe someone else is interested in helping out here. For now this
source is licensed under GPLv2 but it would be okay for me to license
some portions under MIT license too, if there is interest in it.

Hope you find this helpful.

Thanks
Dirk


More information about the reportlab-users mailing list