Popular recipes tagged "meta:license=gpl3" but not "python"http://code.activestate.com/recipes/tags/meta:license=gpl3-python/2017-06-18T17:43:47-07:00ActiveState Code RecipesCreate Calendars on PDF with a few lines (Python) 2017-06-13T10:57:34-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580805-create-calendars-on-pdf-with-a-few-lines/ <p style="color: grey"> Python recipe 580805 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/calendar/">calendar</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>). Revision 2. </p> <p>PyMuPDF (fitz) provides easy to use ways to create PDF documents out of simple texts.</p> <p>An example is the text output of Python's calendar module. Here we take a starting year as script parameter and output a 3-page (A4 landscape) document with calendars for this and the following two years - in less than 20 lines of code.</p> PDF Text Extraction using fitz / MuPDF (PyMuPDF) (Python) 2016-03-17T12:00:06-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580626-pdf-text-extraction-using-fitz-mupdf-pymupdf/ <p style="color: grey"> Python recipe 580626 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/cbz/">cbz</a>, <a href="/recipes/tags/epub/">epub</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/openxps/">openxps</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>, <a href="/recipes/tags/text_extraction/">text_extraction</a>, <a href="/recipes/tags/xps/">xps</a>). </p> <p>Extract all the text of a PDF (or other supported container types) at very high speed. In general, text pieces of a PDF page are not arranged in natural reading order, but in the order they were entered during PDF creation. This script re-arranges text blocks according to their pixel coordinates to achieve a more readable output, i.e. top-down, left-right.</p> How to Create a PDF with a Caustic Drawing (Python) 2017-06-18T17:43:47-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580806-how-to-create-a-pdf-with-a-caustic-drawing/ <p style="color: grey"> Python recipe 580806 by <a href="/recipes/users/4193772/">Jorj X. McKie</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>). </p> <p>Just a little demo on how to create simple drawings with PyMuPDF.</p> <p>This script simulates what you see looking into your coffee mug, early in the morning after a long night of programming ...</p> Rotate a PDF page in 3 lines (Python) 2016-11-06T11:33:59-08:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580713-rotate-a-pdf-page-in-3-lines/ <p style="color: grey"> Python recipe 580713 by <a href="/recipes/users/4193772/">Jorj X. McKie</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>). Revision 2. </p> <p>PyMuPDF v1.9.3 now supports several new features for manipulating PDFs.</p> <p>Here is an example to rotate a page with just a few lines of Python 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> How to parse a table in a PDF document (Python) 2016-04-10T22:43:57-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580635-how-to-parse-a-table-in-a-pdf-document/ <p style="color: grey"> Python recipe 580635 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/cbz/">cbz</a>, <a href="/recipes/tags/epub/">epub</a>, <a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/openxps/">openxps</a>, <a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>, <a href="/recipes/tags/table/">table</a>, <a href="/recipes/tags/xps/">xps</a>). Revision 4. </p> <p>A Python function that converts a table contained in a page of a PDF (or OpenXPS, EPUB, CBZ, XPS) document to a matrix-like Python object (list of lists of strings).</p> PDF 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> 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> wxPython PDF / XPS Viewer using PyMuPDF (binding for fitz / MuPDF) (Python) 2016-09-28T12:21:03-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580621-wxpython-pdf-xps-viewer-using-pymupdf-binding-for-/ <p style="color: grey"> Python recipe 580621 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/cbz/">cbz</a>, <a href="/recipes/tags/epub/">epub</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/wxpython/">wxpython</a>, <a href="/recipes/tags/xps/">xps</a>). Revision 2. </p> <p>A simple program to display a PDF (or XPS, EPUB, CBZ) document with forward / backward buttons and a field for directly jumping to a specific page. It uses the Python binding PyMuPDF for fitz, the high-performance / high-quality graphics library of MuPDF. It obviously can also be used to display XPS documents on non-Windows platforms.</p> <p>This new version also supports any links contained in a page.</p> Create Tiles of Images with fitz / MuPDF (PyMuPDF) (Python) 2016-04-26T19:54:31-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580629-create-tiles-of-images-with-fitz-mupdf-pymupdf/ <p style="color: grey"> Python recipe 580629 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/png/">png</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>, <a href="/recipes/tags/tiles/">tiles</a>). Revision 4. </p> <p>Take an image file (like PNG) and create a new one consisting of arbitrary tiles of the original (or overlay an existing image with selective tiles of another).</p> nbitarray (Python) 2016-04-21T14:12:33-07:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/580649-nbitarray/ <p style="color: grey"> Python recipe 580649 by <a href="/recipes/users/4184815/">yota</a> . </p> <p>library to store n bits data (n &gt; 0) in a python array</p> Create Sierpinski Carpet (Fractal) FAST (Python) 2016-03-16T08:56:08-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580624-create-sierpinski-carpet-fractal-fast/ <p style="color: grey"> Python recipe 580624 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/sierpinski/">sierpinski</a>). </p> <p>Create a Sierpinski carpet using MuPDF's graphics library fitz (binding PyMuPDF) at high speed.</p> ed25519 (Python) 2015-09-21T12:58:34-07:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/579102-ed25519/ <p style="color: grey"> Python recipe 579102 by <a href="/recipes/users/4184815/">yota</a> (<a href="/recipes/tags/cryptography/">cryptography</a>). Revision 2. </p> <p>This is a re-implementation of the ed25519 signature algorithm as proposed on this page : <a href="http://ed25519.cr.yp.to/python/ed25519.py." rel="nofollow">http://ed25519.cr.yp.to/python/ed25519.py.</a></p> <p>Do not use for production, only for the eyes o_O</p> <p>Code is tab indented, space indentation kills kitten...</p> least square fitting (Python) 2015-10-03T15:32:28-07:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/579106-least-square-fitting/ <p style="color: grey"> Python recipe 579106 by <a href="/recipes/users/4184815/">yota</a> (<a href="/recipes/tags/fitting/">fitting</a>). Revision 2. </p> <p>a generic python code to fit points to a given curve, was made for a paraboloid, but can be easily expanded to many kind of curves</p> pick all combinations of items in buckets (Python) 2015-09-05T07:39:42-07:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/579098-pick-all-combinations-of-items-in-buckets/ <p style="color: grey"> Python recipe 579098 by <a href="/recipes/users/4184815/">yota</a> (<a href="/recipes/tags/combinatorics/">combinatorics</a>). </p> <p>Let be a number of buckets, containing each, a variable number of items. This function return all combinations possible of one item picked out of each bucket</p> <p>example, with three buckets {ba, be, bi}, {ka, ko, ku, ke} and {to, ty}, the function enumerate as such: </p> <pre class="prettyprint"><code> 0. ba-ka-to 1. ba-ka-ty 2. ba-ko-to 3. ba-ko-ty 4. ba-ku-to 5. ba-ku-ty 6. ba-ke-to 7. ba-ke-ty 8. be-ka-to 9. be-ka-ty 10. be-ko-to 11. be-ko-ty 12. be-ku-to 13. be-ku-ty 14. be-ke-to 15. be-ke-ty 16. bi-ka-to 17. bi-ka-ty 18. bi-ko-to 19. bi-ko-ty 20. bi-ku-to 21. bi-ku-ty 22. bi-ke-to 23. bi-ke-ty </code></pre> Simple video with ctypes and Xvid (Tkinter,pygame,...) (Python) 2015-06-29T13:59:38-07:00Jiri Justrahttp://code.activestate.com/recipes/users/4192188/http://code.activestate.com/recipes/579073-simple-video-with-ctypes-and-xvid-tkinterpygame/ <p style="color: grey"> Python recipe 579073 by <a href="/recipes/users/4192188/">Jiri Justra</a> (<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/video/">video</a>, <a href="/recipes/tags/xvid/">xvid</a>). </p> <p>This is simple library for playing avi video clips. Videos must be SOUNDLESS (and maybe Xvid encoded wont hurt), to work it properly. I am using it to play intro. It suites good to this purpose, since it can play one clip at a time only.</p> smart copy (Python) 2015-02-06T09:45:12-08:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/579020-smart-copy/ <p style="color: grey"> Python recipe 579020 by <a href="/recipes/users/4184815/">yota</a> (<a href="/recipes/tags/shutil/">shutil</a>). </p> <p>take a glob expression, a source directory and a destination directory to copy each files matching the glob in the appropriate directory</p> <pre class="prettyprint"><code>glob = */*.txt src_dir = ./a/b dst_dir = /z/x/y </code></pre> <p>if the glob match a file <code>./a/b/c/foo.txt</code>, it will copy it in <code>/z/x/y/c/foo.txt</code> (and create the missing directory if needed)</p> <p>Require Python3.4, code tab indented</p> asskick.py (Python) 2014-09-20T08:16:57-07:00p@ntut$http://code.activestate.com/recipes/users/4183895/http://code.activestate.com/recipes/578940-asskickpy/ <p style="color: grey"> Python recipe 578940 by <a href="/recipes/users/4183895/">p@ntut$</a> (<a href="/recipes/tags/kickass/">kickass</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/torrents/">torrents</a>). </p> <p>URL: <a href="http://pantuts.com/2014/09/20/asskick-py-python-script-search-download-torrents-kickass/" rel="nofollow">http://pantuts.com/2014/09/20/asskick-py-python-script-search-download-torrents-kickass/</a></p> <p>Python script to search and download torrents from KickAss torrents.</p> Pasting python data into a spread sheet (Python) 2014-09-16T15:49:07-07:00Tomas Nordinhttp://code.activestate.com/recipes/users/4189558/http://code.activestate.com/recipes/578933-pasting-python-data-into-a-spread-sheet/ <p style="color: grey"> Python recipe 578933 by <a href="/recipes/users/4189558/">Tomas Nordin</a> (<a href="/recipes/tags/clipboard/">clipboard</a>, <a href="/recipes/tags/spreadsheet/">spreadsheet</a>). Revision 3. </p> <p>A smooth way to paste data you are working with in python into a spreadsheet. Put into the system clipboard, select a cell and do ctrl-v (at least with ms office and libre-office).</p> lru_timestamp - cache entry aging for functools.lru_cache (Python) 2014-02-02T21:28:25-08:00Peter Santorohttp://code.activestate.com/recipes/users/4189027/http://code.activestate.com/recipes/578817-lru_timestamp-cache-entry-aging-for-functoolslru_c/ <p style="color: grey"> Python recipe 578817 by <a href="/recipes/users/4189027/">Peter Santoro</a> (<a href="/recipes/tags/age/">age</a>, <a href="/recipes/tags/lru_cache/">lru_cache</a>). </p> <p>Return a timestamp string for @lru_cache decorated functions.</p> <p>The returned timestamp is used as the value of an extra parameter to @lru_cache decorated functions, allowing for more control over how often cache entries are refreshed. The lru_timestamp function should be called with the same refresh_interval value for a given @lru_cache decorated function. The returned timestamp is for the benefit of the @lru_cache decorator and is normally not used by the decorated function.</p> <p>Positional arguments: refresh_interval -- in minutes (default 60), values less than 1 are coerced to 1, values more than 1440 are coerced to 1440</p>