Welcome, guest | Sign In | My Account | Store | Cart

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>

</book>

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.

Then run:

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:

http://jugad2.blogspot.in/2013/06/create-pdf-books-with-xmltopdfbook.html

Python, 1 line
1
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.

2 comments

Vasudev Ram (author) 8 years, 5 months ago  # | flag

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.

Vasudev Ram (author) 8 years, 5 months ago  # | flag

Updated the post - support now added for chapter numbers and names in the output:

http://jugad2.blogspot.in/2013/06/xmltopdfbook-now-supports-chapter.html

  • Vasudev