GUIDE: Using xtopdf to create PDF from text and DBF files (including creating simple PDF e-books)

Discussion in 'Python' started by vasudevram, Jul 22, 2006.

  1. vasudevram

    vasudevram Guest


    I'm giving below, steps to install and use my xtopdf PDF
    creation/conversion toolkit.

    This post is for end-users. xtopdf is both a set of end-user tools and
    a library for use by developers, to create PDF from various input
    I'll post another message here about how developers can use it in
    various ways, sometime later.

    The steps are for the Windows platform. Will do another post for Linux.

    1. Get Python v2.4.3 here:
    Size is not more than 10 MB. Install it - its an MSI, so just

    (Any Python version >= 2.2 will work for xtopdf).

    2. Get Reportlab open source version 1.21 here:

    Size is not more than 3 MB.

    (Don't use ReportLab 2.0 although it is available. I've not yet tested
    xtopdf with it. ReportLab 1.21 is the latest stable version in the
    version 1 series.)

    Install it following the instructions in the README file.
    It should be straightforward. The main points to take care of are:

    2.1 First, before installing ReportLab, run Python once (you may have
    to add the dir. where Python got installed, say C:\Python24, to your
    PATH variable first). Once that dir. is added to your PATH (preferably
    via Control Panel), open a DOS prompt.
    At this prompt, type:


    This should start the Python interpreter. You will get a one or two
    line message with the Python version, and then the Python interpreter

    2.2. At this prompt, type the following two lines:

    import sys
    print sys.path

    This should display a list of all the dirs. that are in the Python PATH
    - an internal Python variable that gets set automatically, upon startup
    of the interpreter, to a set of default dirs. This variable is
    analogous to the DOS PATH variable. In this list of dirs., look for
    "C:\Python24\lib\site-packages" as one of the dirs. It should be there
    by default.

    If it is there, then exit the Python interpreter by typing Ctrl-Z and

    3. Now install Reportlab:

    Unzip the ReportLab_1_21.tgz file with WinZip, into some folder, say
    This will create a folder called either:
    a) reportlab_1.21 with a folder called reportlab under it
    b) just a folder called reportlab.

    If a), then move the reportlab folder (which is under reportlab_1.21)
    to under C:\Python24\Lib\site-packages .
    If b), then move the reportlab folder to under

    The above steps should make ReportLab work.

    An alternative way is to just unzip the reportlab .tgz file into some
    folder, say, C:\RL, and then create a file called, say, reportlab.pth,
    which contains just one line - the path to this folder where the
    extracted contents get stored.e.g. C:\RL\reportlab . Please check that
    step out (in the ReportLab .tgz file's README file for the exact

    4. After the above steps, to check that Reportlab works, go to a DOS
    prompt again, run python again as before, and then at the Python
    prompt, enter either or both of the following commands (on separate

    import reportlab

    from reportlab import pdfgen

    If either or both of these above commands work (and if there is no
    error message), it means that Reportlab is properly installed.

    5. Now you can install xtopdf.

    Get xtopdf here: (click on the
    green rectangle which says "Download Conversion of other formats to
    After downloading the file, unzip it into a folder, say c:\temp. This
    will create a folder called xtopdf-1.0 under C:\temp.
    Go to that folder.

    There are many Python programs here with extension .py.

    To run, e.g.,, do this:

    python some_file.txt

    This will run it and the output will be a file called some_file.pdf.
    Try opening it in Adobe Reader.

    Similarly try running some more programs:

    python test1.dbf (or test2.dbf or test3.dbf or test4.dbf -
    all of which are in the package)

    This should read the DBF file and display its metadata (file header and
    field headers) and data records to standard output - the screen.

    python test1.dbf test1.pdf

    This should do the same as the above (, except that
    instead of the output going to the screen, it will go to a file called

    And so on, try out a few others. Most of all of the programs can be run
    as "python". Some require one or
    more command-line arguments (all of them require at least one
    command-line argument, at least an input file).
    Some of them give usage messages if you run them without any
    command-line arguments, but this is not necessarily the case for
    all of them, nor are the messages always user-friendly enough - I'm
    working on fixing that in the next release. (Developers who have at
    a working knowledge of Python should be easily able to figure out the
    usage, though, just by reading the start of the main() function for
    each program -
    the part where the code checks the command-line arguments.)

    But you should be able to run at least a few of them like this.

    Be sure to try running this one also:

    python book1.pdf book1.txt

    This one reads a list of chapter file names (where each chapter is one
    ..txt file) and corresponding chapter titles, from the 2nd
    argument book1.txt, and creates a PDF e-book out of all the chapters
    combined, using the chapter title as the heading for each page.
    This is a very quick and simple way of creating simple PDF e-books from
    a set of chapters, one chapter per text file.

    Post a message here if you encounter any problems.

    Vasudev Ram
    Software training and consulting
    Custom utility development
    vasudevram, Jul 22, 2006
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HDL Book Seller
    HDL Book Seller
    Dec 1, 2004
  2. vasudevram
    Aug 19, 2006
  3. vasudevram
    Oct 27, 2006
  4. vasudevram
    Oct 4, 2009
  5. vasudevram
    Jul 25, 2006

Share This Page