|
| 1 | +Stapler |
| 2 | +======= |
| 3 | + |
| 4 | +Stapler is a pure Python alternative to |
| 5 | +`PDFtk <http://www.pdfhacks.com/pdftk/>`__, a tool for manipulating PDF |
| 6 | +documents from the command line. |
| 7 | + |
| 8 | +History |
| 9 | +------- |
| 10 | + |
| 11 | +PDFtk was written in Java and C++, and is natively compiled with gcj. |
| 12 | +Sadly, it has been discontinued a few years ago and bitrot is setting in |
| 13 | +(e.g., it does not compile easily on a number of platforms). |
| 14 | + |
| 15 | +Philip Stark decided to look for an alternative and found pypdf, a PDF |
| 16 | +library written in pure Python. He couldn't find a tool which actually |
| 17 | +used the library, so he started writing his own. |
| 18 | + |
| 19 | +Version 0.3 of stapler was completely refactored by Fred Wenzel. He also |
| 20 | +added tests and awesome functionality. |
| 21 | + |
| 22 | +Like pdftk, stapler is a command-line tool. If you would like to add a |
| 23 | +GUI, compile it into a binary for your favorite platform, or contribute |
| 24 | +anything else, feel free to fork and send a pull request. |
| 25 | + |
| 26 | +Contributors and Authorship |
| 27 | +--------------------------- |
| 28 | + |
| 29 | +Stapler version 0.2 was written in 2009 by Philip Stark. Stapler version |
| 30 | +0.3 was written in 2010 by Fred Wenzel. |
| 31 | + |
| 32 | +For a list of contributors, check the ``CONTRIBUTORS`` file. |
| 33 | + |
| 34 | +Change log (sorta) |
| 35 | +------------------ |
| 36 | + |
| 37 | +- **0.3.3** include try-except blocks for supporting legacy pyPdf |
| 38 | + if needed. Also fixes some PyPI issues like the missing License Trove |
| 39 | + classifier and some dependencies. |
| 40 | + |
| 41 | +- **0.3.0** Refactoring by Fred Wenzel and now using PyPDF2 |
| 42 | + |
| 43 | +- **0.2.0** Feature completeness using original pyPdf |
| 44 | + |
| 45 | +License |
| 46 | +------- |
| 47 | + |
| 48 | +Stapler is distributed under a BSD license. A copy of the BSD Style |
| 49 | +License used can be found in the file ``LICENSE``. |
| 50 | + |
| 51 | +Usage |
| 52 | +----- |
| 53 | + |
| 54 | +There are the following modes in Stapler: |
| 55 | + |
| 56 | +select/delete (called with ``sel`` and ``del``, respectively) |
| 57 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 58 | + |
| 59 | +``sel`` is also available as ``cat`` for compatibility with my |
| 60 | +personal muscle memory. :) |
| 61 | + |
| 62 | +With select, you can cherry-pick pages from pdfs and concatenate them |
| 63 | +into a new pdf file. |
| 64 | + |
| 65 | +Syntax: |
| 66 | + |
| 67 | +:: |
| 68 | + |
| 69 | + stapler sel input1 page_or_range [page_or_range ...] [input2 p_o_r ...] |
| 70 | + |
| 71 | +Examples: |
| 72 | + |
| 73 | +:: |
| 74 | + |
| 75 | + # concatenate a and b into output.pdf |
| 76 | + stapler sel a.pdf b.pdf output.pdf |
| 77 | + |
| 78 | + # generate a pdf file called output.pdf with the following pages: |
| 79 | + # 1, 4-8 in 180° (D for down), 20-40 from a.pdf, 1-5 from b.pdf in |
| 80 | + # this order |
| 81 | + stapler sel a.pdf 1 4-8D 20-40 b.pdf 1-5 output.pdf |
| 82 | + |
| 83 | + # reverse some of the pages in a.pdf by specifying a negative range |
| 84 | + stapler sel a.pdf 1-3 9-6 10 output.pdf |
| 85 | + |
| 86 | +The ``sele`` command is an extension of ``sel``. The usage is the same as that |
| 87 | +of ``sel``, but ``sele`` inserts an empty page after each input file if that |
| 88 | +input file has an odd number of pages so that each input file starts with an |
| 89 | +even page number in the generated output. The empty page shall have the same |
| 90 | +size as the page previous to it. You may find this mode useful if you read in |
| 91 | +double-page layout or if you want to print the concatenated output. |
| 92 | + |
| 93 | +The delete command works almost exactly the same as select, but inverse. |
| 94 | +It uses the pages and ranges which you *didn't* specify. |
| 95 | + |
| 96 | + |
| 97 | +split/burst: |
| 98 | +~~~~~~~~~~~~ |
| 99 | + |
| 100 | +Splits the specified pdf files into their single pages and writes each |
| 101 | +page into it's own pdf file with this naming scheme: |
| 102 | + |
| 103 | +:: |
| 104 | + |
| 105 | + ${origname}_${zero-padded page no}.pdf |
| 106 | + |
| 107 | +Syntax: |
| 108 | + |
| 109 | +:: |
| 110 | + |
| 111 | + stapler split input1 [input2 input3 ...] |
| 112 | + |
| 113 | +Example for a file foobar.pdf with 20 pages: |
| 114 | + |
| 115 | +:: |
| 116 | + |
| 117 | + $ stapler split foobar.pdf |
| 118 | + $ ls |
| 119 | + foobar_01.pdf foobar_02.pdf ... foobar_19.pdf foobar_20.pdf |
| 120 | + |
| 121 | +Multiple files can be specified, they will be processed as if you called |
| 122 | +single instances of stapler. |
| 123 | + |
| 124 | +zip: |
| 125 | +~~~~ |
| 126 | + |
| 127 | +With zip, you can cherry-pick pages from pdfs (like select). The pages |
| 128 | +from each pdf are merged together in an interleaving manner. This can be |
| 129 | +used to collate a pdf with odd pages and a pdf with even pages into a |
| 130 | +single file. |
| 131 | + |
| 132 | +Syntax: stapler zip input1 [range[rotation]] [range ...] [input2 |
| 133 | +[range...] ...] out |
| 134 | + |
| 135 | +Examples: |
| 136 | + |
| 137 | +:: |
| 138 | + |
| 139 | + # combine a pdf with odd pages and a pdf with even pages into output.pdf |
| 140 | + stapler zip odd.pdf even.pdf output.pdf |
| 141 | + |
| 142 | + # combine a.pdf b.pdf and c.pdf, but use only some pages of c.pdf and |
| 143 | + # rotate b.pdf right (90° clockwise) and rotate c.pdf left (90° counter- |
| 144 | + # clockwise) |
| 145 | + stapler zip a.pdf b.pdf 1-endR c.pdf 1-3L output.pdf |
| 146 | + |
| 147 | +If one of the ranges is shorter than the others, stapler will continue |
| 148 | +to merge the remaining pages. |
| 149 | + |
| 150 | +info: |
| 151 | +~~~~~ |
| 152 | + |
| 153 | +Shows information on the metadata stored inside a PDF file. |
| 154 | + |
| 155 | +Syntax: |
| 156 | + |
| 157 | +:: |
| 158 | + |
| 159 | + stapler info foo.pdf |
| 160 | + |
| 161 | +Example output: |
| 162 | + |
| 163 | +:: |
| 164 | + |
| 165 | + \*\*\* Metadata for foo.pdf |
| 166 | + |
| 167 | + /ModDate: D:20100313082451+01'00' |
| 168 | + /CreationDate: D:20100313082451+01'00' |
| 169 | + /Producer: GPL Ghostscript 8.70 |
| 170 | + /Title: foo.pdf |
| 171 | + /Creator: PDFCreator Version 0.9.9 |
| 172 | + /Keywords: |
| 173 | + /Author: John Doe |
| 174 | + /Subject: |
0 commit comments