{ "info": { "author": "Joel Rivera", "author_email": "rivera@joel.mx", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.5", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Topic :: Office/Business", "Topic :: Software Development :: Libraries", "Topic :: Text Processing :: Filters" ], "description": "Python Preprocessor of the Formatting Objects Processor [pypfop]\r\n================================================================\r\n\r\nDocument preprocessor for `Apache FOP`_.\r\n\r\nHow does it works?\r\n------------------\r\nIt does what the huge title is implying, preprocess a *higher* level template\r\nto generate *dynamically* an specific `XSL-FO`_ document, which then gets \r\nfed to `Apache FOP`_ and generate the expected output. So that means that\r\nthis packages *requires Java* ``>_<'``, but fear not!, it is almost transparent \r\nto the python application.\r\n\r\nIn general the internal workflow is::\r\n\r\n template -> mako -> apply css -> xsl-fo -> fop -> *Document*\r\n\r\n\r\nInstallation\r\n------------\r\n\r\n1. Install pypfop::\r\n\r\n pip install pypfop\r\n\r\n2. Install `Apache FOP`_:\r\n\r\n #. Download the binary package of fop1.1 either the zip_ or tar_ package.\r\n #. Decompress in wherever place you like and set environment variable ``FOP_CMD``\r\n to the ``bin/fop`` of the decompressed folder. [1]_\r\n\r\n\r\nUsage\r\n-----\r\n\r\nThe Markup\r\n^^^^^^^^^^\r\n\r\nThe markup used to generate the documents is almost the same as the xsl-fo, the only\r\ndifference is that is not necessary to set the xml namespace to all the elements,\r\nfor example::\r\n\r\n \r\n \r\n \r\n \r\n Project\r\n \r\n \r\n \r\n \r\n \r\n \r\n pypfop\r\n \r\n \r\n \r\n \r\n\r\ncan be written like this::\r\n \r\n \r\n \r\n \r\n \r\n Project\r\n \r\n \r\n \r\n \r\n \r\n \r\n pypfopp\r\n \r\n \r\n \r\n
\r\n\r\n\r\nThe higher level template language\r\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\nAt the time the only supported template language is mako_ it should not be very\r\ncomplicated to extend to your favorite template language based in the implementation\r\nof mako (which is pretty straight forward) and hopefully contribute back to the project :).\r\n\r\nFor example the previous table can be generated with this mako template assuming the\r\n`header` and `rows` variables are passed to the `Document.generate` method::\r\n\r\n\r\n \r\n \r\n \r\n % for name in header:\r\n \r\n ${name}\r\n \r\n % endfor\r\n \r\n \r\n \r\n % for row in rows:\r\n \r\n % for cell in row: \r\n \r\n ${cell}\r\n \r\n % endfor\r\n \r\n % endfor\r\n \r\n
\r\n\r\n\r\nSkeletons\r\n^^^^^^^^^\r\nThe previous examples are really just a fragment a document to be able to generate\r\na full document with metadata, paper size, margins, etc. To avoid the repetitive\r\nwork to write this kind of base document pypfop come with skeletons documents, the\r\npurpose if this documents is to be inherited at each template, at the time\r\nthe only implemented skeleton is in `pypfop/skeletons/mako/simple-letter-base.fo.mako`,\r\nwhich include place holders for metadata about the document and two regions, body\r\nand footer, with a few defaults, which of course can be overwritten with the\r\nappropriate parameters.\r\n\r\nTo be a fully functional template for pypfop the previous table need to be like this.\r\n\r\n\r\n*simple-table.fo.mako*::\r\n\r\n <%inherit file=\"simple-letter-base.fo.mako\" />\r\n \r\n \r\n \r\n % for name in header:\r\n \r\n ${name}\r\n \r\n % endfor\r\n \r\n \r\n \r\n % for row in rows:\r\n \r\n % for cell in row: \r\n \r\n ${cell}\r\n \r\n % endfor\r\n \r\n % endfor\r\n \r\n
\r\n\r\nThe skeletons directory is set in the template directory path by default.\r\n\r\n\r\nFormat and style with CSS\r\n^^^^^^^^^^^^^^^^^^^^^^^^^\r\nBeside the *higher level language* that define the content and layout of the document,\r\nthe style and formatting use *CSS*, to be more specific it can parse the rules that\r\ncssutils_ support, which are a very good subset of CSS2 and CSS3, for example it support\r\nthings like ``:nth-child(X)`` and ``@import url(XX)``.\r\n\r\nThe properties that can be set are the same as in the specification of xsl-fo,\r\ncheck out the section of `About XSL-FO syntax`_, with the only exception that you can\r\nuse classes as selectors, xsl-fo does not support the ``class`` attribute,\r\nthe pypfop parser is going to look for the ``class`` attribute then substitute with the\r\nspecific style and then remove the ``class`` attribute.\r\n\r\nFor example I could define the style for the previous table in three files.\r\n\r\n*simple_table.css*::\r\n\r\n @import url(\"general.css\");\r\n @import url(\"colors.css\");\r\n \r\n #main-table > table-header > table-row{\r\n text-align: center;\r\n font-weight: bold;\r\n }\r\n \r\n #main-table > table-header table-cell{\r\n padding: 2mm 0 0mm;\r\n }\r\n\r\n\r\n*general.css*::\r\n\r\n flow[flow-name=\"xsl-region-body\"] {\r\n font-size: 10pt;\r\n font-family: Helvetica;\r\n }\r\n\r\n*colors.css*::\r\n\r\n #main-table> table-body > table-row > table-cell:first-child{\r\n color: red;\r\n } \r\n #main-table> table-body > table-row > table-cell:nth-child(2){\r\n color: blue;\r\n }\r\n #main-table> table-body > table-row > table-cell:nth-child(3){\r\n color: cyan;\r\n }\r\n #main-table> table-body > table-row > table-cell:last-child{\r\n color: green;\r\n }\r\n\r\n\r\nGenerate the document\r\n^^^^^^^^^^^^^^^^^^^^^\r\nThere are a few different ways to implement the ``Document`` class, \r\nbut for the sake of simplicity this is a way to generate the document::\r\n\r\n\r\n from pypfop import Document\r\n from pypfop.makotemplates import TemplateFactory\r\n\r\n tfactory = TemplateFactory()\r\n params = {'header': ['Project', 'Website', 'Language', 'Notes'],\r\n 'rows': [('pypfop', 'https://bitbucket.org/cyraxjoe/pypfop', \r\n 'Python', 'Abstraction on top of Apache FOP'),\r\n\t\t\t('Apache FOP', 'https://xmlgraphics.apache.org/fop/', \r\n 'Java', '')] }\r\n doc = Document(tfactory('simple-table.fo.mako'), 'simple_table.css')\r\n print(doc.generate(params)) # returns the path of the generated file.\r\n\r\n\r\nSupported Document formats\r\n^^^^^^^^^^^^^^^^^^^^^^^^^^\r\nIn the previous example we didn't define the output of the `Document` in that case\r\nthe default output of ``pdf`` is used, but the supported outputs are the same as\r\nin `Apache FOP output formats`_.\r\n\r\nFrom ``pypfop.__init__``::\r\n\r\n VALID_OFORMATS = frozenset(('awt', 'pdf', 'mif', 'rtf',\r\n 'tiff', 'png', 'pcl', 'ps', 'txt'))\r\n\r\n\r\nThe output format can be set in ``Document.__init__`` or ``Document.generate`` ::\r\n\r\n doc = Document(tfactory('simple-table.fo.mako'), 'simple_table.css',\r\n oformat='rtf')\r\n\r\nor ::\r\n\r\n doc.generate(params, oformat='rtf')\r\n\r\n\r\nAbout XSL-FO syntax\r\n^^^^^^^^^^^^^^^^^^^\r\n\r\nAs you should notice already it is required to know how to format xsl-fo documents\r\nwhich in most part are very similar to the HTML counterparts (except that anything needs \r\nto be in ``block`` tags), the best reference that I could find online is in the `XML Bible`_.\r\n\r\n\r\nWhy!\r\n----\r\n\r\nThis project it use to be part of a larger project of one of my customers, \r\nwhich I decide early on that I will use *only python 3*, terrible decision \r\nif you want to generate pdf files easily or at least at the moment.\r\nI was looking to have some kind of *template* to the very rigid format of\r\nthe average invoice and billing order, so pypfop came to relieve that pain.\r\n\r\n.. [1] Actually you can set the command at another level, check the ``Document`` class. \r\n\r\n.. _`Apache FOP`: https://xmlgraphics.apache.org/fop/\r\n.. _XSL-FO: https://en.wikipedia.org/wiki/XSL_Formatting_Objects\r\n.. _zip: http://apache.webxcreen.org/xmlgraphics/fop/binaries/fop-1.1-bin.zip\r\n.. _tar: http://apache.webxcreen.org/xmlgraphics/fop/binaries/fop-1.1-bin.tar.gz\r\n.. _`XML Bible`: http://www.ibiblio.org/xml/books/bible3/chapters/ch16.html\r\n.. _mako: http://www.makotemplates.org/\r\n.. _cssutils: http://pypi.python.org/pypi/cssutils\r\n.. _`Apache FOP output formats`: https://xmlgraphics.apache.org/fop/1.1/output.html", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/cyraxjoe/pypfop", "keywords": "", "license": "Copyright 2013 Joel Rivera\r\n\r\nLicensed under the Apache License, Version 2.0 (the \"License\");\r\nyou may not use this file except in compliance with the License.\r\nYou may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nUnless required by applicable law or agreed to in writing, software\r\ndistributed under the License is distributed on an \"AS IS\" BASIS,\r\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\nSee the License for the specific language governing permissions and\r\nlimitations under the License.", "maintainer": "", "maintainer_email": "", "name": "pypfop", "package_url": "https://pypi.org/project/pypfop/", "platform": "linux2,win32,cygwin,darwin", "project_url": "https://pypi.org/project/pypfop/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/cyraxjoe/pypfop" }, "release_url": "https://pypi.org/project/pypfop/0.2.0/", "requires_dist": null, "requires_python": null, "summary": "Document preprocessor for Apache FOP.", "version": "0.2.0" }, "last_serial": 1455392, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "417b1c80ed519c0b60d8f2caa63f3bf5", "sha256": "b55b78377e8e79fe73c0340a58b7f9559467a2cd73fce1f8c35041baa8610a5e" }, "downloads": -1, "filename": "pypfop-0.1.0.tar.gz", "has_sig": false, "md5_digest": "417b1c80ed519c0b60d8f2caa63f3bf5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9845, "upload_time": "2013-01-26T23:08:27", "url": "https://files.pythonhosted.org/packages/eb/c9/5a99ce3b52eb1021e7d8939e35c0bd1ea8ea6c1366ca2e829d764142976a/pypfop-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "02c73c68efc60a57d82f01942ace94c9", "sha256": "c608f2d98f8bd26a7b0e5889996e7611c567555e890b66b8f10b5503966271f0" }, "downloads": -1, "filename": "pypfop-0.1.1.tar.gz", "has_sig": false, "md5_digest": "02c73c68efc60a57d82f01942ace94c9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10013, "upload_time": "2013-01-29T10:27:17", "url": "https://files.pythonhosted.org/packages/9c/28/a0c24dd2bc3e9a9d0a3d099b71f451fbb90401b547b59ad36c2cf1a1b477/pypfop-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "0eb6c966d8df724ecf07012ba46bc698", "sha256": "4748841a7398664a732811e171844ea41b20c936935caedb4cb8d7cb1ecc3ee0" }, "downloads": -1, "filename": "pypfop-0.1.2.tar.gz", "has_sig": false, "md5_digest": "0eb6c966d8df724ecf07012ba46bc698", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10076, "upload_time": "2013-02-06T06:54:38", "url": "https://files.pythonhosted.org/packages/29/a1/e5f8eedc5a4bd9323bb236a148422a8a574681b42602246aa1ff79229a64/pypfop-0.1.2.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "a709eeb30e6cbb2d3ff555646922f445", "sha256": "d1bfbbe547834fac8b6cfc6f860b0851715bb43bade1c1fd1a5c11aa76b4798a" }, "downloads": -1, "filename": "pypfop-0.2.0.tar.gz", "has_sig": false, "md5_digest": "a709eeb30e6cbb2d3ff555646922f445", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11938, "upload_time": "2013-02-22T06:55:56", "url": "https://files.pythonhosted.org/packages/f3/98/a5aff66b35f9dc2f58acb7df027f1ae253c1853caf2aafd98da8ed1ef3c7/pypfop-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a709eeb30e6cbb2d3ff555646922f445", "sha256": "d1bfbbe547834fac8b6cfc6f860b0851715bb43bade1c1fd1a5c11aa76b4798a" }, "downloads": -1, "filename": "pypfop-0.2.0.tar.gz", "has_sig": false, "md5_digest": "a709eeb30e6cbb2d3ff555646922f445", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11938, "upload_time": "2013-02-22T06:55:56", "url": "https://files.pythonhosted.org/packages/f3/98/a5aff66b35f9dc2f58acb7df027f1ae253c1853caf2aafd98da8ed1ef3c7/pypfop-0.2.0.tar.gz" } ] }