Top-rated recipes by Harald Lieder http://code.activestate.com/recipes/users/4191581/top/2016-10-29T20:22:27-07:00ActiveState Code RecipesPDF wrapper for FileOptimizer (Python) 2016-10-29T20:22:27-07:00Harald Liederhttp://code.activestate.com/recipes/users/4191581/http://code.activestate.com/recipes/580711-pdf-wrapper-for-fileoptimizer/ <p style="color: grey"> Python recipe 580711 by <a href="/recipes/users/4191581/">Harald Lieder</a> (<a href="/recipes/tags/fileoptimizer/">fileoptimizer</a>, <a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/optimization/">optimization</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>). </p> <p>Among dozens of other filetypes, FileOptimizer also compresses PDFs - often significantly. The issue is that the used plugin <em>smpdf</em> is free for non-commercial use only and it annoyingly <strong>also overwrites metadata</strong> information to state this.</p> <p>The following tool remedies these metadata changes (but not the license situation!).</p> Find Paper Format of based on Pixel Width and Height of a (PDF) Page (Python) 2016-05-05T23:47:49-07:00Harald Liederhttp://code.activestate.com/recipes/users/4191581/http://code.activestate.com/recipes/580659-find-paper-format-of-based-on-pixel-width-and-heig/ <p style="color: grey"> Python recipe 580659 by <a href="/recipes/users/4191581/">Harald Lieder</a> (<a href="/recipes/tags/a4/">a4</a>, <a href="/recipes/tags/format/">format</a>, <a href="/recipes/tags/letter/">letter</a>, <a href="/recipes/tags/paper/">paper</a>). </p> <p>A simple function to determine what format page a page in document has. Parameters provided are width and height in float or integer format.</p> <p>Return is a string like "A4-P" or "Letter-L" when an exact fit is found. If not, information is provided as a string like "width x height (other), closest &lt;format&gt; width x height". The closest format in this case is determined by minimizing the sum of absolute differences of width and height with a table of official formats.</p> Saving a numpy array to png image using fitz / MuPDF (PyMuPDF) (Python) 2016-03-19T12:57:38-07:00Harald Liederhttp://code.activestate.com/recipes/users/4191581/http://code.activestate.com/recipes/580630-saving-a-numpy-array-to-png-image-using-fitz-mupdf/ <p style="color: grey"> Python recipe 580630 by <a href="/recipes/users/4191581/">Harald Lieder</a> (<a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/png/">png</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>). Revision 2. </p> <p>If a pixel array is defined in numpy, it can be saved as a PNG image VERY fast if you use PyMuPDF.</p> Decrypt a PDF using fitz / MuPDF (PyMuPDF) (Python) 2016-03-17T12:22:10-07:00Harald Liederhttp://code.activestate.com/recipes/users/4191581/http://code.activestate.com/recipes/580627-decrypt-a-pdf-using-fitz-mupdf-pymupdf/ <p style="color: grey"> Python recipe 580627 by <a href="/recipes/users/4191581/">Harald Lieder</a> (<a href="/recipes/tags/decompression/">decompression</a>, <a href="/recipes/tags/decryption/">decryption</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/repair/">repair</a>). </p> <p>It's more a code snippet. Shows how to dynamically check whether a PDF is password protected. If it is, decrypt it and save it back to disk un-encrypted.</p> New Version: GUI PDF Table of Contents Editor using fitz / MuPDF, wxPython (Python) 2016-06-22T11:34:20-07:00Harald Liederhttp://code.activestate.com/recipes/users/4191581/http://code.activestate.com/recipes/580623-new-version-gui-pdf-table-of-contents-editor-using/ <p style="color: grey"> Python recipe 580623 by <a href="/recipes/users/4191581/">Harald Lieder</a> (<a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/toc/">toc</a>). Revision 2. </p> <p>Create or modify the bookmarks list of a PDF (ToC - table of contents). Supports arbitrary hierarchy levels. Display PDF while editing to control bookmark targets. PDF meta data are maintainable. Save PDF under the same or a different name.</p> PDF Joiner / Splitter using wxPython, PyMuPDF (fitz / MuPDF) (Python) 2016-03-15T19:07:35-07:00Harald Liederhttp://code.activestate.com/recipes/users/4191581/http://code.activestate.com/recipes/580622-pdf-joiner-splitter-using-wxpython-pymupdf-fitz-mu/ <p style="color: grey"> Python recipe 580622 by <a href="/recipes/users/4191581/">Harald Lieder</a> (<a href="/recipes/tags/join/">join</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/split/">split</a>). </p> <p>Full featured PDF joiner. Join several PDF files into one output PDF. Page ranges can be specified as well as page orientation for each output page range. Tables of contents are intelligently preserved for each page range (can also be switched off). Output PDF metadata editable.</p> Python: Determine Name and Directory of the Top Level Running Script (Python) 2015-02-03T01:37:09-08:00Harald Liederhttp://code.activestate.com/recipes/users/4191581/http://code.activestate.com/recipes/579018-python-determine-name-and-directory-of-the-top-lev/ <p style="color: grey"> Python recipe 579018 by <a href="/recipes/users/4191581/">Harald Lieder</a> . </p> <p>Yet another way to provide this information. I wanted to get the right answers in ANY situation: Python 2 or 3, compiled or interpreted (interactive or batch). The following code has been tested under Windows, Python 2.7, Python 3.4, IDLE, IPython (sh and Qt), PyInstaller, cx_Freeze, py2exe.</p>