This recipe shows how to create a PDF book from XML text content. It requires my xtopdf toolkit, the ElementTree module (from Python's standard library) and the open source version of the ReportLab toolkit.
Create an XML template file like this:
<?xml version="1.0"?> <book> <chapter> Chapter 1 content here. </chapter>
<chapter> Chapter 2 content here. </chapter>
Then populate the chapter elements with the text of each of the chapters of your book, as text. Call that file, your_book.xml, say.
python XMLtoPDFBook.py your_book.xml your_book.pdf
Now the contents of your book will be in your_book.pdf
More details and the full code here:
- Vasudev Ram dancingbison.com
Creating PDF books from XML text content.
This recipe provides an easy and quick way to create simple PDF ebooks from text content stored in an XML file.
It is like a much simpler version of DocBook. DocBook is much more powerful and has many more features, but also requires more setup and a more complicated toolchain to produce the PDF.
The formatting of the recipe seems to have been messed up (above) a bit by the XML tags. But the content is still clearly visible.
Updated the post - support now added for chapter numbers and names in the output: