Popular Python recipes tagged "meta:requires=reportlab"http://code.activestate.com/recipes/langs/python/tags/meta:requires=reportlab/2015-02-22T10:42:18-08:00ActiveState Code RecipesConvert JSON to PDF with Python and xtopdf (Python) 2014-12-10T18:02:14-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578979-convert-json-to-pdf-with-python-and-xtopdf/ <p style="color: grey"> Python recipe 578979 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/sys/">sys</a>). </p> <p>This recipe show the basic steps needed to convert JSON input to PDF output, using Python and xtopdf, a PDF creation toolkit. xtopdf is itself written in Pytho, and uses the ReportLab toolkit internally.</p> <p>We set up some needed values, such as the output PDF file name, the font name and size, the header and footer, and the input lines for the body of the PDF output; all these values are passed in JSON format (in a single dictionary) to a function that uses those values to generate a PDF file with the desired content.</p> <p>The code is intentionally kept simple so as to require the least amount of code needed to demonstrate the techniques involved. But it can be generalized or extended to more complex situations.</p> Publish databases to PDF with PyDAL (a Python DB library) and xtopdf (Python) 2015-01-15T16:09:27-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579004-publish-databases-to-pdf-with-pydal-a-python-db-li/ <p style="color: grey"> Python recipe 579004 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pydal/">pydal</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python_developer_tools/">python_developer_tools</a>, <a href="/recipes/tags/sql/">sql</a>, <a href="/recipes/tags/web2py/">web2py</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to use the PyDAL database library for Python, together with xtopdf, a PDF creation library for Python, to publish database data to PDF. PyDAL was earlier a part of the web2py Python web framework, and then was split out into a separate library that does not need to be used with web2py. It supports access to many popular relational databases, both open source and proprietary.</p> Convert Excel to PDF with xlwings and xtopdf (Python) 2015-02-22T10:42:18-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579026-convert-excel-to-pdf-with-xlwings-and-xtopdf/ <p style="color: grey"> Python recipe 579026 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/excel/">excel</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/xlwings/">xlwings</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to get the text content from an Excel file and convert it to PDF, using the xlwings and xtopdf Python libraries. It also shows how to create an Excel file programmatically using xlwings.</p> Serve PDF with Netius, a pure-Python network library, and xtopdf (Python) 2014-12-03T21:27:54-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578974-serve-pdf-with-netius-a-pure-python-network-librar/ <p style="color: grey"> Python recipe 578974 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/client/">client</a>, <a href="/recipes/tags/client_server/">client_server</a>, <a href="/recipes/tags/networking/">networking</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/server/">server</a>). </p> <p>This recipe shows how to serve PDF from a server written using Netius, a pure-Python library, together with xtopdf, a Python toolkit for PDF creation. It is a proof-of-concept recipe, to show the essentials needed for the task, so it hard-codes the text content that is served as PDF, but the concepts shown can easily be extended to serve dynamically generated PDF content.</p> Convert Microsoft Word files to PDF with DOCXtoPDF (Python) 2013-12-24T23:03:43-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578795-convert-microsoft-word-files-to-pdf-with-docxtopdf/ <p style="color: grey"> Python recipe 578795 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/docx/">docx</a>, <a href="/recipes/tags/microsoft/">microsoft</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/word/">word</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>Yhis recipe shows how to convert Microsoft Word .DOCX files to PDF format, using the python-docx library and my xtopdf toolkit for PDF creation.</p> <p>Note: The recipe has some limitations. E.g. fonts, tables, etc. from the input DOCX file are not preserved in the output PDF file.</p> Use PDFWriter with context manager support (Python) 2013-12-16T21:43:27-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578790-use-pdfwriter-with-context-manager-support/ <p style="color: grey"> Python recipe 578790 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/contextmanager/">contextmanager</a>, <a href="/recipes/tags/context_manager/">context_manager</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/with_statement/">with_statement</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>PDFWriter - a core class of the xtopdf toolkit - can now be used with a Python context manager, a.k.a. the Python <strong>with</strong> statement.</p> <p>Code example below. More details here:</p> <p><a href="http://jugad2.blogspot.in/2013/12/xtopdf-pdfwriter-now-has-context.html" rel="nofollow">http://jugad2.blogspot.in/2013/12/xtopdf-pdfwriter-now-has-context.html</a></p> Create simple PDF text calendars with xtopdf (Python) 2014-02-14T22:33:04-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578832-create-simple-pdf-text-calendars-with-xtopdf/ <p style="color: grey"> Python recipe 578832 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/calendar/">calendar</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to create simple text calendars as PDF using xtopdf, a Python toolkit for PDF creation.</p> Publish Berkeley DB data to PDF with xtopdf (Python) 2014-01-24T17:57:21-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578814-publish-berkeley-db-data-to-pdf-with-xtopdf/ <p style="color: grey"> Python recipe 578814 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/bsddb/">bsddb</a>, <a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to convert the data stored in a Berkeley DB database to PDF, using the xtopdf toolkit for PDF creation. It should work on either Linux/Unix or Windows.</p> Create PDF at the end of a Unix pipeline with PDFWriter (Python) 2013-12-22T22:19:00-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578794-create-pdf-at-the-end-of-a-unix-pipeline-with-pdfw/ <p style="color: grey"> Python recipe 578794 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pipelining/">pipelining</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to create PDF output at the end of a Unix or Linux pipeline, after all the text processing required, is done by previous components of the pipeline (which can use any of the standard tools of Unix such as sed, grep, awk, etc., as well as custom programs that act as filters).</p> A basic WSGI PDF server (Python) 2013-12-26T18:45:35-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578798-a-basic-wsgi-pdf-server/ <p style="color: grey"> Python recipe 578798 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/wsgi/">wsgi</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to create a rudimentary Python WSGI server that can serve PDF. I had seen a post on the Python Reddit about how to create 'a basic WSGI server (aka "enough to make a website without using a framework")'. Thought of modifying it to serve PDF content (hard-ccded, though, not dynamic content, just as a basic example). This is the result. It's meant for learning, as was the original from which it was adapted, not for production use. It requires my xtopdf toolkit and the Reportlab toolkit, v1.21</p> Create a Table of Contents for an ebook with XMLtoPDFBook (Python) 2013-12-16T21:49:33-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578791-create-a-table-of-contents-for-an-ebook-with-xmlto/ <p style="color: grey"> Python recipe 578791 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/ebooks/">ebooks</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/publishing/">publishing</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>XMLtoPDFBook is a tool that allows you to create simple PDF ebooks from XML content. It is a part of the xtpodf toolkit.</p> <p>You can now create PDF ebooks with XMLtoPDFBook, that include a Table of Contents (TOC).</p> XML to PDF book with ElementTree and xtopdf (Python) 2013-06-16T19:14:58-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578561-xml-to-pdf-book-with-elementtree-and-xtopdf/ <p style="color: grey"> Python recipe 578561 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/ebooks/">ebooks</a>, <a href="/recipes/tags/elementtree/">elementtree</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/publishing/">publishing</a>, <a href="/recipes/tags/xml/">xml</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>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.</p> <p>Create an XML template file like this:</p> <p>&lt;?xml version="1.0"?&gt; &lt;book&gt; &lt;chapter&gt; Chapter 1 content here. &lt;/chapter&gt;</p> <pre class="prettyprint"><code> &lt;chapter&gt; Chapter 2 content here. &lt;/chapter&gt; </code></pre> <p>&lt;/book&gt;</p> <p>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.</p> <p>Then run:</p> <p>python XMLtoPDFBook.py your_book.xml your_book.pdf</p> <p>Now the contents of your book will be in your_book.pdf</p> <p>More details and the full code here:</p> <p><a href="http://jugad2.blogspot.in/2013/06/create-pdf-books-with-xmltopdfbook.html" rel="nofollow">http://jugad2.blogspot.in/2013/06/create-pdf-books-with-xmltopdfbook.html</a></p> <ul> <li>Vasudev Ram <a href="http://dancingbison.com" rel="nofollow">dancingbison.com</a></li> </ul> Generate a PDF Greeting Card (Python) 2007-12-06T04:06:04-08:00greg phttp://code.activestate.com/recipes/users/4047849/http://code.activestate.com/recipes/535155-generate-a-pdf-greeting-card/ <p style="color: grey"> Python recipe 535155 by <a href="/recipes/users/4047849/">greg p</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>Code to generate a PDF greeting card using a user specified image, and text.</p> <p>You can try it out online here: <a href="http://utilitymill.com/utility/Greeting_Card_Generator" rel="nofollow">http://utilitymill.com/utility/Greeting_Card_Generator</a></p>