perfect-binding-converter 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Amr Bassem
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,95 @@
1
+ Metadata-Version: 2.4
2
+ Name: perfect-binding-converter
3
+ Version: 0.1.0
4
+ Summary: Perfect binding converter: imposes PDF pages into A4 cut-stack layout with a center fold line
5
+ License: MIT License
6
+
7
+ Copyright (c) 2026 Amr Bassem
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+
27
+ Classifier: Programming Language :: Python :: 3
28
+ Classifier: License :: OSI Approved :: MIT License
29
+ Classifier: Operating System :: POSIX :: Linux
30
+ Classifier: Operating System :: MacOS
31
+ Classifier: Topic :: Printing
32
+ Requires-Python: >=3.9
33
+ Description-Content-Type: text/markdown
34
+ License-File: LICENSE
35
+ Requires-Dist: pypdf>=3.0
36
+ Dynamic: license-file
37
+
38
+ # perfect-binding-converter
39
+
40
+ Imposes a PDF into a **perfect-binding** cut-stack layout for A4 booklet
41
+ printing. Pairs pages in opposite halves of the document onto landscape A4
42
+ sheets with a spine gutter, and draws a dashed center cut/fold line on each
43
+ sheet.
44
+
45
+ The CLI command is **`pbc`** (the bare `pbc` name is taken on PyPI by an
46
+ unrelated project, so the package is published under this longer name).
47
+
48
+ ## Install
49
+
50
+ Requires Python 3.9+.
51
+
52
+ ### PyPI (pip / pipx)
53
+
54
+ ```sh
55
+ pip install perfect-binding-converter
56
+ # or, isolated:
57
+ pipx install perfect-binding-converter
58
+ ```
59
+
60
+ The `pbc` command will then be on your PATH.
61
+
62
+ ### Arch Linux (AUR, system-wide)
63
+
64
+ A PKGBUILD is provided in `packaging/aur/PKGBUILD`. It builds the PyPI
65
+ package and installs the `pbc` binary into `/usr/bin`:
66
+
67
+ ```sh
68
+ cd packaging/aur
69
+ makepkg -si # build + install with pacman
70
+ # or, once published to the AUR:
71
+ # yay -S python-perfect-binding-converter
72
+ ```
73
+
74
+ Installing this way puts `pbc` on your system PATH for all users, with no venv.
75
+
76
+ ## Usage
77
+
78
+ ```sh
79
+ pbc input.pdf [-o output.pdf] [-g gutter_mm]
80
+ ```
81
+
82
+ - `input` (required): PDF to impose.
83
+ - `-o, --output`: output path (default `cut_stack_output.pdf`).
84
+ - `-g, --gutter`: spine gutter in millimeters (default `12`).
85
+
86
+ ### Example
87
+
88
+ ```sh
89
+ pbc my_book.pdf -o print_ready.pdf
90
+ ```
91
+
92
+ Each output sheet holds two source pages side by side on a landscape A4 page,
93
+ with the second half of the book mapped behind the first for cut-and-stack
94
+ collation. The dashed vertical line marks the fold/cut position.
95
+ # perfect-binding-converter
@@ -0,0 +1,58 @@
1
+ # perfect-binding-converter
2
+
3
+ Imposes a PDF into a **perfect-binding** cut-stack layout for A4 booklet
4
+ printing. Pairs pages in opposite halves of the document onto landscape A4
5
+ sheets with a spine gutter, and draws a dashed center cut/fold line on each
6
+ sheet.
7
+
8
+ The CLI command is **`pbc`** (the bare `pbc` name is taken on PyPI by an
9
+ unrelated project, so the package is published under this longer name).
10
+
11
+ ## Install
12
+
13
+ Requires Python 3.9+.
14
+
15
+ ### PyPI (pip / pipx)
16
+
17
+ ```sh
18
+ pip install perfect-binding-converter
19
+ # or, isolated:
20
+ pipx install perfect-binding-converter
21
+ ```
22
+
23
+ The `pbc` command will then be on your PATH.
24
+
25
+ ### Arch Linux (AUR, system-wide)
26
+
27
+ A PKGBUILD is provided in `packaging/aur/PKGBUILD`. It builds the PyPI
28
+ package and installs the `pbc` binary into `/usr/bin`:
29
+
30
+ ```sh
31
+ cd packaging/aur
32
+ makepkg -si # build + install with pacman
33
+ # or, once published to the AUR:
34
+ # yay -S python-perfect-binding-converter
35
+ ```
36
+
37
+ Installing this way puts `pbc` on your system PATH for all users, with no venv.
38
+
39
+ ## Usage
40
+
41
+ ```sh
42
+ pbc input.pdf [-o output.pdf] [-g gutter_mm]
43
+ ```
44
+
45
+ - `input` (required): PDF to impose.
46
+ - `-o, --output`: output path (default `cut_stack_output.pdf`).
47
+ - `-g, --gutter`: spine gutter in millimeters (default `12`).
48
+
49
+ ### Example
50
+
51
+ ```sh
52
+ pbc my_book.pdf -o print_ready.pdf
53
+ ```
54
+
55
+ Each output sheet holds two source pages side by side on a landscape A4 page,
56
+ with the second half of the book mapped behind the first for cut-and-stack
57
+ collation. The dashed vertical line marks the fold/cut position.
58
+ # perfect-binding-converter
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "perfect-binding-converter"
7
+ version = "0.1.0"
8
+ description = "Perfect binding converter: imposes PDF pages into A4 cut-stack layout with a center fold line"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { file = "LICENSE" }
12
+ classifiers = [
13
+ "Programming Language :: Python :: 3",
14
+ "License :: OSI Approved :: MIT License",
15
+ "Operating System :: POSIX :: Linux",
16
+ "Operating System :: MacOS",
17
+ "Topic :: Printing",
18
+ ]
19
+ dependencies = ["pypdf>=3.0"]
20
+
21
+ [project.scripts]
22
+ pbc = "pbc.cli:main"
23
+
24
+ [tool.setuptools.packages.find]
25
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,113 @@
1
+ import argparse
2
+
3
+ from pypdf import PdfReader, PdfWriter, Transformation
4
+ from pypdf import PdfReader, PdfWriter, Transformation
5
+ from pypdf.generic import (
6
+ ArrayObject,
7
+ DictionaryObject,
8
+ NameObject,
9
+ StreamObject,
10
+ )
11
+
12
+ SPINE_GUTTER_MM = 12
13
+ A4_W, A4_H = 595.28, 841.89
14
+
15
+
16
+ def mm_to_pt(mm):
17
+ return mm * 2.83465
18
+
19
+
20
+ def build_cutline_page(out_w, out_h):
21
+ # Center spine of the imposed landscape page is the fold/cut location.
22
+ x = out_w / 2
23
+ content = (
24
+ f"{x:.4f} 0 m\n"
25
+ f"{x:.4f} {out_h:.4f} l\n"
26
+ "2 w\n"
27
+ "[4 4] 0 d\n"
28
+ "0.75 0.75 0.75 RG\n"
29
+ "S\n"
30
+ )
31
+ writer = PdfWriter()
32
+ page = writer.add_blank_page(out_w, out_h)
33
+ resources = DictionaryObject(
34
+ {
35
+ NameObject("/ProcSet"): ArrayObject([NameObject("/PDF")]),
36
+ }
37
+ )
38
+ page[NameObject("/Resources")] = resources
39
+ stream = StreamObject()
40
+ stream.set_data(content.encode("latin-1"))
41
+ page[NameObject("/Contents")] = stream
42
+ return page
43
+
44
+
45
+ def main(argv=None):
46
+ parser = argparse.ArgumentParser(
47
+ prog="pbc",
48
+ description="Impose a PDF into cut-stack layout for A4 booklet printing.",
49
+ )
50
+ parser.add_argument("input", help="Input PDF path")
51
+ parser.add_argument(
52
+ "-o", "--output", default="cut_stack_output.pdf", help="Output PDF path"
53
+ )
54
+ parser.add_argument(
55
+ "-g", "--gutter", type=float, default=SPINE_GUTTER_MM,
56
+ help=("Spine gutter width in millimeters "
57
+ f"(default {SPINE_GUTTER_MM})"),
58
+ )
59
+ args = parser.parse_args(argv)
60
+
61
+ reader = PdfReader(args.input)
62
+ pages = reader.pages
63
+ n = len(pages)
64
+ if n < 2:
65
+ parser.error("input PDF must have at least 2 pages")
66
+
67
+ out_w = A4_H
68
+ out_h = A4_W
69
+ g = mm_to_pt(args.gutter)
70
+
71
+ half = n // 2
72
+ half_w = (out_w - g) / 2
73
+
74
+ writer = PdfWriter()
75
+
76
+ for i in range(half):
77
+ if i % 2 == 0:
78
+ left_page = pages[i]
79
+ right_page = pages[i + half]
80
+ else:
81
+ left_page = pages[i + half]
82
+ right_page = pages[i]
83
+
84
+ new_page = writer.add_blank_page(out_w, out_h)
85
+
86
+ lw = float(left_page.mediabox.width)
87
+ lh = float(left_page.mediabox.height)
88
+ lsx = half_w / lw
89
+ lsy = out_h / lh
90
+ new_page.merge_transformed_page(
91
+ left_page, Transformation().scale(lsx, lsy).translate(0, 0), over=True
92
+ )
93
+
94
+ rw = float(right_page.mediabox.width)
95
+ rh = float(right_page.mediabox.height)
96
+ rsx = half_w / rw
97
+ rsy = out_h / rh
98
+ new_page.merge_transformed_page(
99
+ right_page,
100
+ Transformation().scale(rsx, rsy).translate(out_w / 2 + g / 2, 0),
101
+ over=True,
102
+ )
103
+
104
+ new_page.merge_page(build_cutline_page(out_w, out_h), over=True)
105
+
106
+ writer.write(args.output)
107
+ writer.close()
108
+
109
+ print(f"Done: {args.output} ({half} imposed pages)")
110
+
111
+
112
+ if __name__ == "__main__":
113
+ main()
@@ -0,0 +1,95 @@
1
+ Metadata-Version: 2.4
2
+ Name: perfect-binding-converter
3
+ Version: 0.1.0
4
+ Summary: Perfect binding converter: imposes PDF pages into A4 cut-stack layout with a center fold line
5
+ License: MIT License
6
+
7
+ Copyright (c) 2026 Amr Bassem
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+
27
+ Classifier: Programming Language :: Python :: 3
28
+ Classifier: License :: OSI Approved :: MIT License
29
+ Classifier: Operating System :: POSIX :: Linux
30
+ Classifier: Operating System :: MacOS
31
+ Classifier: Topic :: Printing
32
+ Requires-Python: >=3.9
33
+ Description-Content-Type: text/markdown
34
+ License-File: LICENSE
35
+ Requires-Dist: pypdf>=3.0
36
+ Dynamic: license-file
37
+
38
+ # perfect-binding-converter
39
+
40
+ Imposes a PDF into a **perfect-binding** cut-stack layout for A4 booklet
41
+ printing. Pairs pages in opposite halves of the document onto landscape A4
42
+ sheets with a spine gutter, and draws a dashed center cut/fold line on each
43
+ sheet.
44
+
45
+ The CLI command is **`pbc`** (the bare `pbc` name is taken on PyPI by an
46
+ unrelated project, so the package is published under this longer name).
47
+
48
+ ## Install
49
+
50
+ Requires Python 3.9+.
51
+
52
+ ### PyPI (pip / pipx)
53
+
54
+ ```sh
55
+ pip install perfect-binding-converter
56
+ # or, isolated:
57
+ pipx install perfect-binding-converter
58
+ ```
59
+
60
+ The `pbc` command will then be on your PATH.
61
+
62
+ ### Arch Linux (AUR, system-wide)
63
+
64
+ A PKGBUILD is provided in `packaging/aur/PKGBUILD`. It builds the PyPI
65
+ package and installs the `pbc` binary into `/usr/bin`:
66
+
67
+ ```sh
68
+ cd packaging/aur
69
+ makepkg -si # build + install with pacman
70
+ # or, once published to the AUR:
71
+ # yay -S python-perfect-binding-converter
72
+ ```
73
+
74
+ Installing this way puts `pbc` on your system PATH for all users, with no venv.
75
+
76
+ ## Usage
77
+
78
+ ```sh
79
+ pbc input.pdf [-o output.pdf] [-g gutter_mm]
80
+ ```
81
+
82
+ - `input` (required): PDF to impose.
83
+ - `-o, --output`: output path (default `cut_stack_output.pdf`).
84
+ - `-g, --gutter`: spine gutter in millimeters (default `12`).
85
+
86
+ ### Example
87
+
88
+ ```sh
89
+ pbc my_book.pdf -o print_ready.pdf
90
+ ```
91
+
92
+ Each output sheet holds two source pages side by side on a landscape A4 page,
93
+ with the second half of the book mapped behind the first for cut-and-stack
94
+ collation. The dashed vertical line marks the fold/cut position.
95
+ # perfect-binding-converter
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/pbc/cli.py
5
+ src/perfect_binding_converter.egg-info/PKG-INFO
6
+ src/perfect_binding_converter.egg-info/SOURCES.txt
7
+ src/perfect_binding_converter.egg-info/dependency_links.txt
8
+ src/perfect_binding_converter.egg-info/entry_points.txt
9
+ src/perfect_binding_converter.egg-info/requires.txt
10
+ src/perfect_binding_converter.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pbc = pbc.cli:main