Most viewed recipes tagged "pdf" but not "mupdf"http://code.activestate.com/recipes/tags/pdf-mupdf/views/2016-11-07T20:28:01-08:00ActiveState Code RecipesConvert Microsot Excel (XLSX) to PDF with Python and xtopdf (Python)
2015-11-22T22:15:25-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579128-convert-microsot-excel-xlsx-to-pdf-with-python-and/
<p style="color: grey">
Python
recipe 579128
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/excel/">excel</a>, <a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/openpyxl/">openpyxl</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/xlsx/">xlsx</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how the basics of to convert the text data in a Microsoft Excel file (XLSX format) to PDF (Portable Document Format). It uses openpyxl to read the XLSX file and xtopdf to generate the PDF file.</p>
Convert doc and docx files to pdf (Python)
2014-03-31T18:39:16-07:00Fabian Mayerhttp://code.activestate.com/recipes/users/4189629/http://code.activestate.com/recipes/578858-convert-doc-and-docx-files-to-pdf/
<p style="color: grey">
Python
recipe 578858
by <a href="/recipes/users/4189629/">Fabian Mayer</a>
(<a href="/recipes/tags/doc/">doc</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/win32com/">win32com</a>).
Revision 2.
</p>
<p>The Script converts all doc and docx files in a specified folder to pdf files. It checks whether the provided absolute path does actually exist and whether the specified folder contains any doc and docx files. It does not travers the directory recursively. The script is not portable and runs only a Windows machine. Based on the experience I made, I recommend closing MS Word before running the script.</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>
Crop PDF File with pyPdf (Python)
2011-11-03T17:42:10-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/576837-crop-pdf-file-with-pypdf/
<p style="color: grey">
Python
recipe 576837
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pypdf/">pypdf</a>).
Revision 3.
</p>
<p>This recipe was originally posted by <code>sjvr767</code> on <a href="http://www.mobileread.com/forums/showthread.php?t=25565" rel="nofollow">http://www.mobileread.com/forums/showthread.php?t=25565</a> and I decided to also make it available here.</p>
<p>It uses pypdf (<a href="http://pybrary.net/pyPdf/%29" rel="nofollow">http://pybrary.net/pyPdf/)</a></p>
<p>The script is supposed to be run like this:</p>
<p><code>pdf_crop.py" -m "120 50 120 180" -i mypdf.pdf</code></p>
<p>where the margins are <code>left top right bottom</code></p>
<p>To install pyPdf try <code>easy_install pypdf</code>.</p>
Extract images of a PDF - optionally by page using PyMuPDF / fitz (Python)
2016-09-28T12:03:59-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580703-extract-images-of-a-pdf-optionally-by-page-using-p/
<p style="color: grey">
Python
recipe 580703
by <a href="/recipes/users/4193772/">Jorj X. McKie</a>
(<a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/png/">png</a>).
</p>
<p>Two small scripts to extract images contained in a PDF document as PNG files.
(1) Script 1 extracts <strong>all</strong> images
(2) Script 2 extracts only images that are referenced by a page</p>
Improved ReportLab recipe for "page x of y" (Python)
2009-07-06T10:03:28-07:00Vinay Sajiphttp://code.activestate.com/recipes/users/4034162/http://code.activestate.com/recipes/576832-improved-reportlab-recipe-for-page-x-of-y/
<p style="color: grey">
Python
recipe 576832
by <a href="/recipes/users/4034162/">Vinay Sajip</a>
(<a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/reportlab/">reportlab</a>).
Revision 2.
</p>
<p>This recipe is based on <a href="http://code.activestate.com/recipes/546511/"><a href="http://code.activestate.com/recipes/546511/">Recipe 546511</a></a> which does not work reliably if there are images in the content.</p>
Convert HTML text to PDF with Beautiful Soup and xtopdf (Python)
2015-01-28T22:20:53-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579014-convert-html-text-to-pdf-with-beautiful-soup-and-x/
<p style="color: grey">
Python
recipe 579014
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/format/">format</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/reportgeneration/">reportgeneration</a>, <a href="/recipes/tags/reporting/">reporting</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to convert the text in an HTML document to PDF. It uses the Beautiful Soup and xtopdf Python libraries. Beautiful Soup is a library for HTML parsing and content extraction. xtopdf is a library for PDF creation from other formats, including text and many others.</p>
wxPython PDF Viewer using Poppler (Python)
2010-04-15T17:43:27-07:00Marcelo Fernándezhttp://code.activestate.com/recipes/users/4173551/http://code.activestate.com/recipes/577195-wxpython-pdf-viewer-using-poppler/
<p style="color: grey">
Python
recipe 577195
by <a href="/recipes/users/4173551/">Marcelo Fernández</a>
(<a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/poppler/">poppler</a>, <a href="/recipes/tags/python_poppler/">python_poppler</a>, <a href="/recipes/tags/viewer/">viewer</a>, <a href="/recipes/tags/wxpython/">wxpython</a>).
</p>
<p>This example shows a PDF Viewer class, which handles things like Zoom and Scrolling. It requires python-poppler and wxPython >= 2.8.9.</p>
Generate a PDF invoice with xtopdf and Python (Python)
2015-10-07T18:02:46-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579108-generate-a-pdf-invoice-with-xtopdf-and-python/
<p style="color: grey">
Python
recipe 579108
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows the basics of how to generate invoices as PDF documents, using xtopdf, a Python toolkit for PDF creation. An example of creating a simple invoice through Python and xtopdf code is shown. </p>
<p>xtopdf is available on Bitbucket at:</p>
<p><a href="https://bitbucket.org/vasudevram/xtopdf" rel="nofollow">https://bitbucket.org/vasudevram/xtopdf</a></p>
<p>and you can find many links with examples of using xtopdf, how to install it, etc., from this Google search:</p>
<p><a href="https://google.com/search?q=xtopdf" rel="nofollow">https://google.com/search?q=xtopdf</a></p>
<p>This sub-feed of my blog:</p>
<p><a href="http://jugad2.blogspot.com/search/label/xtopdf" rel="nofollow">http://jugad2.blogspot.com/search/label/xtopdf</a></p>
<p>gives access to all my blog posts labelled xtopdf.</p>
PDF a Directory of Images using Reportlab (Python)
2009-04-12T08:35:10-07:00andrew.canithttp://code.activestate.com/recipes/users/4169843/http://code.activestate.com/recipes/576717-pdf-a-directory-of-images-using-reportlab/
<p style="color: grey">
Python
recipe 576717
by <a href="/recipes/users/4169843/">andrew.canit</a>
(<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/pdf/">pdf</a>).
</p>
<p>Walk through a directory PDFing Images</p>
Convert PDF to plain text (Python)
2010-11-25T15:30:52-08:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/577095-convert-pdf-to-plain-text/
<p style="color: grey">
Python
recipe 577095
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/converter/">converter</a>, <a href="/recipes/tags/pdf/">pdf</a>).
</p>
<p>This is a very raw PDF converter which has absolutely no idea of the page layout or text positioning.</p>
<p>To install the required module try <code>easy_install pypdf</code> in a console.</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>
How to use Python to convert a web page to PDF with a POST request to SelectPdf Online API and save it on the disk (Python)
2015-11-16T14:52:17-08:00SelectPdfhttp://code.activestate.com/recipes/users/4193129/http://code.activestate.com/recipes/579126-how-to-use-python-to-convert-a-web-page-to-pdf-wit/
<p style="color: grey">
Python
recipe 579126
by <a href="/recipes/users/4193129/">SelectPdf</a>
(<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/converter/">converter</a>, <a href="/recipes/tags/htmltopdf/">htmltopdf</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/selectpdf/">selectpdf</a>).
</p>
<p>This code converts an url to pdf in Python using SelectPdf HTML To PDF REST API through a POST request. The parameters are JSON encoded. The content is saved into a file on the disk.</p>
Printing an ASCII table to PDF (Python)
2015-04-02T18:38:04-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579043-printing-an-ascii-table-to-pdf/
<p style="color: grey">
Python
recipe 579043
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/ascii/">ascii</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to print part of an ASCII table to PDF. It shows it for the first 32 ASCII characters, the control characters, i.e. the characters with ASCII codes 0 to 31. The same logic can be extended to print the remaining ASCII characters, either upto code 127 or 255, depending on your definition of ASCII, and also on whether your PDF font supports printing all those characters.</p>
Read CSV with D and write it to PDF with Python (Python)
2016-10-26T17:49:00-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580710-read-csv-with-d-and-write-it-to-pdf-with-python/
<p style="color: grey">
Python
recipe 580710
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to read data from a CSV file with a D program and write that data to a PDF file with a Python program - all in a single command-line invocation (after writing the individual programs, of course).</p>
<p>It requires the xtopdf toolkit, which you can get from:</p>
<p><a href="https://bitbucket.org/vasudevram/xtopdf" rel="nofollow">https://bitbucket.org/vasudevram/xtopdf</a></p>
<p>Instructions for installing xtopdf:</p>
<p><a href="http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html" rel="nofollow">http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html</a></p>
<p>xtopdf in turn requires the open source version of the ReportLab toolkit, which you can get from:</p>
<p><a href="http://www.reportlab.com/ftp" rel="nofollow">http://www.reportlab.com/ftp</a> (<a href="http://www.reportlab.com/ftp/reportlab-1.21.1.tar.gz%29" rel="nofollow">http://www.reportlab.com/ftp/reportlab-1.21.1.tar.gz)</a></p>
<p>It also requires the DMD compiler to compile the D program - this was the version used:</p>
<p>DMD32 D Compiler v2.071.2</p>
Publish SQLite data to PDF using named tuples (Python)
2015-02-24T22:08:11-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579027-publish-sqlite-data-to-pdf-using-named-tuples/
<p style="color: grey">
Python
recipe 579027
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/sql/">sql</a>, <a href="/recipes/tags/sqlite/">sqlite</a>, <a href="/recipes/tags/sqlite3/">sqlite3</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to publish SQLite data to PDF, using named tuples from the collections module of Python, the sqlite3 library, and the xtopdf library for PDF generation.</p>
Use PrettyTable and xtopdf to create PDF tables with borders, alignment and padding (Python)
2015-01-24T21:21:27-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579012-use-prettytable-and-xtopdf-to-create-pdf-tables-wi/
<p style="color: grey">
Python
recipe 579012
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/prettytable/">prettytable</a>, <a href="/recipes/tags/string/">string</a>, <a href="/recipes/tags/tabular/">tabular</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to create tabular data in PDF format, supporting neat borders, and alignment and padding of columns, using the Python libraries called PrettyTable and xtopdf.</p>
Roll your own Postscript code from scratch (Python)
2015-12-09T23:30:13-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/579136-roll-your-own-postscript-code-from-scratch/
<p style="color: grey">
Python
recipe 579136
by <a href="/recipes/users/4076953/">Jack Trainor</a>
(<a href="/recipes/tags/ghostscript/">ghostscript</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/postscript/">postscript</a>, <a href="/recipes/tags/ps/">ps</a>).
</p>
<p>This recipe provides a mini-framework for creating custom Postscript PS and PDF files from scratch. It includes sample code for a personalized business index card.</p>
<p>Recipe does not use any Python PDF libraries. However, Ghostscript and a PDF viewer are useful for displaying/debugging output.</p>
<p>It's easier than you might think to roll your own Postscript code!</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>
Batch conversion of text files to PDF with fileinput and xtopdf (Python)
2016-11-07T20:28:01-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580715-batch-conversion-of-text-files-to-pdf-with-fileinp/
<p style="color: grey">
Python
recipe 580715
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/batch/">batch</a>, <a href="/recipes/tags/batchmode/">batchmode</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/text_processing/">text_processing</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to do a batch conversion of the content of multiple text files into a single PDF file, with a) an automatic page break after the content of each text file (in the PDF output), b) page numbering, and c) a header and footer on each page.</p>
<p>It uses the fileinput module (part of the Python standard library), and xtopdf, a Python library for conversion of other formats to PDF.</p>
<p>xtopdf is available here: <a href="https://bitbucket.org/vasudevram/xtopdf" rel="nofollow">https://bitbucket.org/vasudevram/xtopdf</a></p>
<p>and a guide to installing and using xtopdf is here:</p>
<p><a href="http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html" rel="nofollow">http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html</a></p>
<p>Here is a sample run of the program:</p>
<p>python BTTP123.pdf text1.txt text2.txt text3.txt</p>
<p>This will read the content from the three text files specified and write it into the PDF file specified, neatly formatted.</p>