Git Product home page Git Product logo

pyxml2pdf's Introduction

What is PyXML2PDF?

PyXML2PDF is a pure python module that can generate PDF files from XML. It can be used with the command line or integrated in a python application. PyXML2PDF allows to generate pixel precise PDF documents in any page size. It can generate very complex pages while being easily edited as an XML file.

PyXML2PDF wraps over the excellent Reportlab python module to generate PDFs. All PyXML2PDF does is to bring an XML semantic to the concepts used in Reportlab. Instead of having to code your PDFs using Reportlab modules, you simply write easily maintainable PyXML2PDF files which in turn generate PDF pages.

We have been using this module in healthcare applications for 3 years now, and have had great results. Performance is adequate, however it certainly can be optimised for greater speed.

Ease of use: Anyone who knows some basic HTML/XML concepts will be able to use PyXML2PDF within minutes.

Snapping elements: Elements can be positionned relative to one another to create intricate tables. Check the details of this feature.

Styles (CSS): PyXML2PDF supports the concepts of a simple CSS implementation. This allows for flexibility and decoupling of content/appearance (like HTML).

HTML: PyXML2PDF is NOT compatible with any XHTML/HTML/CSS. It uses a small set of tags to quickly allow generation of PDFs.

PyXML2PDF Tags: Please refer to the list of tags in the 'Reference' section (below)

Scripting/Templating/Dynamic content: PyXML2PDF does not include a templating language for dynamically generating XML files. But you can use any templating tool or other method to generate XML files which can then be fed to PyXML2PDF in order to generate a PDF. We have been successfully using Genshi as a templating engine.

Reporting: PyXML2PDF is not a reporting engine. Rather it could be part of the backend for an existing reporting engine to help generate PDFs.

Language support: PyXML2PDF supports UTF8, but all language specific stuff should be handled by whoever generates the XML. In our case, we use Genshi and python language tools to generate our PyXML2PDF files in several languages.

Platforms

  • Windows (tested)
  • Linux (tested)
  • Mac should also work (untested)
  • Anywhere you can get Python/Reportlab to work.

Licensing

BSD License ( http://www.opensource.org/licenses/bsd-license.php )

Dependencies

Want to help this project?

We will gladly accept your help if you have any ideas and suggestions to make this project faster/better. You can contact me if you wish to discuss any improvement you would like to make. I strongly urge you not to do this on your own, as this project's goal is to evolve and improve over time. So please feel free to contribute patches and ideas.

Installation

Simply run the following command within root directory of the project:

python setup.py install

Using PyXML2PDF

###Command line: python xml2pdf.py -f input.xml out.pdf

###In your python code: from PyXML2PDF import xml2pdf xml2pdf.genpdf(in_xml_filename, out_pdf_filename)


Tutorial

[Here are a few sample XML files] (https://github.com/kelvin0/PyXML2PDF/tree/master/samples)

  1. Create an xml file named 'sample.xml'. Paste the following in it then save it.

    <style name="redhot"> border:4.0; color:red; </style> <style name="thinblue"> border:1.0; color:blue; </style> <style name="normal"> font-size:10; top-padding:0.5; left-padding:0.5; height:11; </style>
     <rlbox id="smallbox" width="40" height="20" snapto="bigbox|C|NW"/>
     
     <rlline posx="450" posy="230" endx="600" endy="10" class="thinblue" />
     
     <p width="40" height="20" background-color="white" class="normal" snapto="bigbox|C|C">
     BigBox
     </p>
     
     <pagebreak/>
    
  2. In the same directory as 'sample.xml' , create a file named 'sample.py'. Put the following code in the sample.py and save it.

    import os from PyXML2PDF import xml2pdf from reportlab.pdfbase.ttfonts import TTFont

    xml = os.path.abspath('./sample.xml') pdf = os.path.abspath('./sample.pdf')

    xml2pdf.genpdf(xml,pdf)

    Show the PDF (this line optionnal)

    os.system('call %s'%(pdf))

  3. From the command line in the same directory as the 'sample.py' file, type: (assuming python is installed and in path)

    python sample.py


Reference

We strongly urge you yo visit the links below in order to fully understand the possibilities of PyXML2PDF. Also, they explain in further detail such things as:

  • Fonts
  • Colors
  • Coordinate systems
  • Positionning elements relative to one another
  • And much more ...

[All XML tags] (https://github.com/kelvin0/PyXML2PDF/wiki/Reference:-XML-tags)

[All XML attributes] (https://github.com/kelvin0/PyXML2PDF/wiki/Reference:-XML-attributes)

pyxml2pdf's People

Contributors

kelvin0 avatar

Stargazers

Georgy Shelkovy avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.