Skip to main content

Ralsina.Me — Roberto Alsina's website

Generating PDFs from Restructured text

This has al­ways been pos­si­ble, go­ing via La­TeX.

How­ev­er, La­TeX be­ing what it is, you ei­ther need to learn it, or you end up with rather plain-look­ing doc­u­ments.

While that's ok for a man­u­al, I want to use Re­struc­tured Text for ev­ery­thing in­volv­ing doc­u­ments.

So, I looked for an­oth­er so­lu­tion. Sad­ly, I could not make the ex­ist­ing rlpdf writ­er work, sooooo I de­cid­ed to write my own tool.

Since I in­tense­ly dis­like the Vis­i­tor pat­tern in­volved in writ­ing a reg­u­lar do­cu­tils writer, I adapt­ed my old rst2rst.py and end­ed with rst2pdf.py which just tra­vers­es the tree re­cur­sive­ly and writes the PDF us­ing Re­port­Lab.

And it took me about 3 hours to make it work:

  • For a lim­it­ed sub­­set of RST (no foot­notes, no links, no dec­o­ra­­tion)

  • For some sub­­set of ta­bles (no col/row span­n­ing)

  • With lim­it­ed "styling" (it's most­­ly there, but I need to write a lot of Re­­port­Lab styles.

How well does it work... rather well.

Here's a gen­er­at­ed PDF of The Re­struc­tured­Text Primer

Ig­nore aes­thet­ic­s, and con­sid­er func­tion, it's pret­ty good.

Pablo Antonio / 2007-10-06 03:38:

Roberto, qué buen trabajo! Hace algunos días di una charla sobre reST en las Jornadas del LugFI 2007, y considero que tuvo bastante aceptación :) Ojalá decidas compartir esto. Voy a ser de los primeros en probarlo :)

Roberto Alsina / 2007-10-06 10:34:

Pero por supuesto, no lo compartí porque está muy verde, y porque google code no me deja abrir mas proyectos.

Así que acá está el código (necesita reportlab):

http://lateral.netmanagers....


Contents © 2000-2024 Roberto Alsina