Skip to content

Commit d17c498

Browse files
committed
Merge remote-tracking branch 'upstream/master'
Add mode ``sele``. It inserts an empty page at the end of each input file if necessary to make sure each input file has an even number of pages in the generated output file. This is good for people reading in double-page layout or if they want to print the generated pdf file.
2 parents b0a7e4b + dc496c5 commit d17c498

19 files changed

Lines changed: 820 additions & 385 deletions

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.py[co]
2+
pip-log.txt
3+
build
4+
dist
5+
*egg-info*
6+
/venv
7+
/.idea

CONTRIBUTORS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Philip Stark <heller.barde at gmail dot com>
2+
Fred Wenzel <fwenzel at mozilla dot coms>
3+
Emanuele Santoro <manu at santoro dot tk>
4+
David Gay <oddshocks at gmail dot com>
5+
Carlchristian Eckert <Carli-Eckert at gmx dot de>

COPYING

Whitespace-only changes.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2009, Philip Stark
1+
# Copyright (c) 2009, Philip Stark, Fred Wenzel
22
# All rights reserved.
33
#
44
# Redistribution and use in source and binary forms, with or without

README

Lines changed: 0 additions & 96 deletions
This file was deleted.

README.rst

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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:

TODO

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Comparison with pdftk features:
2+
[x] = done, [?] = maybe, [ ] = to do
3+
4+
[ ] Python 3 Support (pypdf can do it, I think)
5+
[x] Merge PDF Documents
6+
[x] Split PDF Pages into a New Document
7+
[x] Rotate PDF Pages or Documents
8+
[x] Decrypt Input as Necessary (Password Required)
9+
[x] Encrypt Output as Desired
10+
[?] Fill PDF Forms with FDF Data or XFDF Data and/or Flatten Forms
11+
[?] Apply a Background Watermark or a Foreground Stamp
12+
[ ] Report on PDF Metrics such as Metadata, Bookmarks, and Page Labels
13+
[?] Update PDF Metadata
14+
[?] Attach Files to PDF Pages or the PDF Document
15+
[?] Unpack PDF Attachments
16+
[x] Burst a PDF Document into Single Pages
17+
[ ] Uncompress and Re-Compress Page Streams
18+
[x] Repair Corrupted PDF (Where Possible)
19+
20+
Known issues:
21+
- The same page of the same input file cannot be added to the output twice
22+
with two different rotations (e.g., ``cat foo.pdf 1R 1D`` won't do what
23+
you'd hope).

legacy-pypdf-setup.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from setuptools import setup, find_packages
2+
3+
version = "0.3.3"
4+
5+
setup(name="stapler",
6+
version=version,
7+
description="Manipulate PDF documents from the command line",
8+
keywords="pdf utility cli concatenate tool",
9+
10+
author="Philip Stark, Fred Wenzel",
11+
author_email="git@codechaos.ch",
12+
url="https://github.com/hellerbarde/stapler",
13+
14+
install_requires = [
15+
"PyPDF>=1.12",
16+
#"PyPDF2>=1.24",
17+
],
18+
19+
#include_package_data=True,
20+
packages=find_packages(),
21+
package_data={"": ["LICENSE", "CONTRIBUTORS", "README.md", ]},
22+
entry_points="""
23+
[console_scripts]
24+
stapler = staplelib:main
25+
pdf-stapler = staplelib:main
26+
""",
27+
28+
classifiers=[
29+
"Development Status :: 5 - Production/Stable",
30+
"Programming Language :: Python :: 2",
31+
"Intended Audience :: Science/Research",
32+
"Topic :: Utilities",
33+
"License :: OSI Approved :: BSD License"
34+
],
35+
)

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--index-url https://pypi.python.org/simple/
2+
3+
-e .
4+

setup.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from setuptools import setup, find_packages
2+
3+
version = "0.3.3"
4+
5+
setup(name="stapler",
6+
version=version,
7+
description="Manipulate PDF documents from the command line",
8+
keywords="pdf utility cli concatenate tool",
9+
10+
author="Philip Stark, Fred Wenzel",
11+
author_email="git@codechaos.ch",
12+
url="https://github.com/hellerbarde/stapler",
13+
14+
install_requires = [
15+
"PyPDF2>=1.24",
16+
"more-itertools>=2.2"
17+
],
18+
19+
#include_package_data=True,
20+
packages=find_packages(),
21+
package_data={"": ["LICENSE", "CONTRIBUTORS", "README.md", ]},
22+
entry_points="""
23+
[console_scripts]
24+
stapler = staplelib:main
25+
pdf-stapler = staplelib:main
26+
""",
27+
28+
classifiers=[
29+
"Development Status :: 5 - Production/Stable",
30+
"Programming Language :: Python :: 2",
31+
"Intended Audience :: Science/Research",
32+
"Topic :: Utilities",
33+
"License :: OSI Approved :: BSD License"
34+
],
35+
)

0 commit comments

Comments
 (0)