pdf-section-binding 1.0.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.
- pdf_section_binding-1.0.0/LICENSE +21 -0
- pdf_section_binding-1.0.0/MANIFEST.in +15 -0
- pdf_section_binding-1.0.0/PKG-INFO +324 -0
- pdf_section_binding-1.0.0/README.md +278 -0
- pdf_section_binding-1.0.0/pyproject.toml +98 -0
- pdf_section_binding-1.0.0/requirements.txt +2 -0
- pdf_section_binding-1.0.0/setup.cfg +4 -0
- pdf_section_binding-1.0.0/setup.py +88 -0
- pdf_section_binding-1.0.0/src/pdf_section_binding/__init__.py +15 -0
- pdf_section_binding-1.0.0/src/pdf_section_binding/cli.py +380 -0
- pdf_section_binding-1.0.0/src/pdf_section_binding/core.py +252 -0
- pdf_section_binding-1.0.0/src/pdf_section_binding/version.py +8 -0
- pdf_section_binding-1.0.0/src/pdf_section_binding.egg-info/PKG-INFO +324 -0
- pdf_section_binding-1.0.0/src/pdf_section_binding.egg-info/SOURCES.txt +19 -0
- pdf_section_binding-1.0.0/src/pdf_section_binding.egg-info/dependency_links.txt +1 -0
- pdf_section_binding-1.0.0/src/pdf_section_binding.egg-info/entry_points.txt +3 -0
- pdf_section_binding-1.0.0/src/pdf_section_binding.egg-info/not-zip-safe +1 -0
- pdf_section_binding-1.0.0/src/pdf_section_binding.egg-info/requires.txt +12 -0
- pdf_section_binding-1.0.0/src/pdf_section_binding.egg-info/top_level.txt +1 -0
- pdf_section_binding-1.0.0/tests/test-data/.gitkeep +2 -0
- pdf_section_binding-1.0.0/tests/test_section_binding.py +296 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Your Name
|
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,15 @@
|
|
1
|
+
include README.md
|
2
|
+
include LICENSE
|
3
|
+
include pyproject.toml
|
4
|
+
include requirements.txt
|
5
|
+
recursive-include src/pdf_section_binding *.py
|
6
|
+
recursive-include tests *.py
|
7
|
+
include tests/test-data/.gitkeep
|
8
|
+
|
9
|
+
# Exclude moved utility files from distribution
|
10
|
+
exclude src/demo.py
|
11
|
+
exclude src/section_binding.py
|
12
|
+
exclude src/test_section_binding.py
|
13
|
+
exclude src/create_test_pdf.py
|
14
|
+
exclude src/example_usage.py
|
15
|
+
exclude src/add_page_numbers.py
|
@@ -0,0 +1,324 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: pdf-section-binding
|
3
|
+
Version: 1.0.0
|
4
|
+
Summary: A CLI tool for reordering PDF pages for section binding (bookbinding)
|
5
|
+
Home-page: https://github.com/sravankumarrekandar/pdf-section-binding
|
6
|
+
Author: Sravan Kumar Rekandar
|
7
|
+
Author-email: Sravan Kumar Rekandar <sravankumarrekandar@example.com>
|
8
|
+
License: MIT
|
9
|
+
Project-URL: Homepage, https://github.com/yourusername/pdf-section-binding
|
10
|
+
Project-URL: Bug Reports, https://github.com/yourusername/pdf-section-binding/issues
|
11
|
+
Project-URL: Source, https://github.com/yourusername/pdf-section-binding
|
12
|
+
Project-URL: Documentation, https://github.com/yourusername/pdf-section-binding#readme
|
13
|
+
Keywords: pdf,bookbinding,section-binding,printing,cli,page-reordering,signatures,folding
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
15
|
+
Classifier: Intended Audience :: End Users/Desktop
|
16
|
+
Classifier: Intended Audience :: Developers
|
17
|
+
Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
|
18
|
+
Classifier: Topic :: Printing
|
19
|
+
Classifier: Topic :: Utilities
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
21
|
+
Classifier: Programming Language :: Python :: 3.7
|
22
|
+
Classifier: Programming Language :: Python :: 3.8
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
26
|
+
Classifier: Programming Language :: Python :: 3.12
|
27
|
+
Classifier: Operating System :: OS Independent
|
28
|
+
Classifier: Environment :: Console
|
29
|
+
Requires-Python: >=3.7
|
30
|
+
Description-Content-Type: text/markdown
|
31
|
+
License-File: LICENSE
|
32
|
+
Requires-Dist: PyPDF2>=3.0.0
|
33
|
+
Provides-Extra: dev
|
34
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
35
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
36
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
37
|
+
Requires-Dist: flake8>=5.0.0; extra == "dev"
|
38
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
39
|
+
Provides-Extra: test
|
40
|
+
Requires-Dist: pytest>=7.0.0; extra == "test"
|
41
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
|
42
|
+
Dynamic: author
|
43
|
+
Dynamic: home-page
|
44
|
+
Dynamic: license-file
|
45
|
+
Dynamic: requires-python
|
46
|
+
|
47
|
+
# PDF Section Binding Tool
|
48
|
+
|
49
|
+
This tool reorders PDF pages for section binding (bookbinding), where pages are arranged in signatures (folded sheets) so that when printed and folded, they appear in the correct reading order.
|
50
|
+
|
51
|
+
## Installation
|
52
|
+
|
53
|
+
### From PyPI (Recommended)
|
54
|
+
|
55
|
+
```bash
|
56
|
+
pip install pdf-section-binding
|
57
|
+
```
|
58
|
+
|
59
|
+
### From Source
|
60
|
+
|
61
|
+
1. Clone the repository:
|
62
|
+
```bash
|
63
|
+
git clone https://github.com/yourusername/pdf-section-binding.git
|
64
|
+
cd pdf-section-binding
|
65
|
+
```
|
66
|
+
|
67
|
+
2. Create and activate virtual environment:
|
68
|
+
```bash
|
69
|
+
python3 -m venv venv
|
70
|
+
source venv/bin/activate # On macOS/Linux
|
71
|
+
# or
|
72
|
+
venv\Scripts\activate # On Windows
|
73
|
+
```
|
74
|
+
|
75
|
+
3. Install in development mode:
|
76
|
+
```bash
|
77
|
+
pip install -e .
|
78
|
+
```
|
79
|
+
|
80
|
+
## Usage
|
81
|
+
|
82
|
+
After installation, use the `pdf-section-binding` command (or the shorter `section-binding` alias):
|
83
|
+
|
84
|
+
```bash
|
85
|
+
pdf-section-binding input.pdf [options]
|
86
|
+
```
|
87
|
+
|
88
|
+
### Command Line Options
|
89
|
+
|
90
|
+
- `-o, --output`: Output PDF file path (default: `input_name_section_bound.pdf`)
|
91
|
+
- `-s, --signature-size`: Pages per signature - must be multiple of 4 (default: 8)
|
92
|
+
- `--dry-run`: Preview analysis without creating output file
|
93
|
+
- `-v, --verbose`: Enable verbose output with progress tracking
|
94
|
+
- `-q, --quiet`: Suppress all output except errors
|
95
|
+
- `--force`: Overwrite output file if it exists
|
96
|
+
- `--version`: Show version information
|
97
|
+
- `-h, --help`: Show help message
|
98
|
+
|
99
|
+
### Examples
|
100
|
+
|
101
|
+
```bash
|
102
|
+
# Basic usage with 8-page signatures (2 papers per signature)
|
103
|
+
pdf-section-binding book.pdf
|
104
|
+
|
105
|
+
# Specify output file and 4-page signatures (1 paper per signature)
|
106
|
+
pdf-section-binding book.pdf -o output.pdf -s 4
|
107
|
+
|
108
|
+
# Use 16-page signatures (4 papers per signature)
|
109
|
+
pdf-section-binding book.pdf -s 16
|
110
|
+
|
111
|
+
# Use 40-page signatures (10 papers per signature)
|
112
|
+
pdf-section-binding book.pdf -s 40
|
113
|
+
|
114
|
+
# Preview without creating file (dry run)
|
115
|
+
pdf-section-binding book.pdf --dry-run
|
116
|
+
|
117
|
+
# Verbose output with progress tracking
|
118
|
+
pdf-section-binding book.pdf -v
|
119
|
+
|
120
|
+
# Quiet mode (minimal output)
|
121
|
+
pdf-section-binding book.pdf -q
|
122
|
+
|
123
|
+
# Force overwrite existing output
|
124
|
+
pdf-section-binding book.pdf --force
|
125
|
+
```
|
126
|
+
|
127
|
+
## Features
|
128
|
+
|
129
|
+
✨ **Enhanced CLI Tool**
|
130
|
+
- 🎨 **Colorized output** for better user experience
|
131
|
+
- 📊 **Progress tracking** for large documents
|
132
|
+
- 🔍 **Dry run mode** to preview without creating files
|
133
|
+
- ⚡ **Fast processing** with optimized algorithms
|
134
|
+
- 🛡️ **Robust error handling** with helpful suggestions
|
135
|
+
- 📏 **Flexible signature sizes** (any multiple of 4)
|
136
|
+
|
137
|
+
🔧 **Advanced Options**
|
138
|
+
- Verbose and quiet modes
|
139
|
+
- Force overwrite protection
|
140
|
+
- Input validation with helpful error messages
|
141
|
+
- Multiple command aliases (`pdf-section-binding` or `section-binding`)
|
142
|
+
|
143
|
+
📦 **Library Usage**
|
144
|
+
- Use as a Python library in your own projects
|
145
|
+
- Clean API with `SectionBindingProcessor` class
|
146
|
+
- Comprehensive test suite included
|
147
|
+
|
148
|
+
## CLI Features in Detail
|
149
|
+
|
150
|
+
### Smart Error Messages
|
151
|
+
The tool provides helpful suggestions when you make mistakes:
|
152
|
+
|
153
|
+
```bash
|
154
|
+
$ pdf-section-binding book.pdf -s 15
|
155
|
+
Error: Signature size must be a multiple of 4 (each paper = 4 pages).
|
156
|
+
You specified 15. Try: 12 or 16
|
157
|
+
```
|
158
|
+
|
159
|
+
### Progress Tracking
|
160
|
+
For large documents, see progress in real-time:
|
161
|
+
|
162
|
+
```bash
|
163
|
+
$ pdf-section-binding large-book.pdf -v
|
164
|
+
PDF Section Binding Tool v1.0.0
|
165
|
+
==================================================
|
166
|
+
[INFO] Reading PDF: large-book.pdf
|
167
|
+
[INFO] Total pages: 1500
|
168
|
+
[INFO] Signature size: 8
|
169
|
+
[INFO] Creating reordered PDF...
|
170
|
+
Creating PDF: [████████████████████████████████████████████████] 100% (1500/1500)
|
171
|
+
[INFO] Writing output: large-book_section_bound.pdf
|
172
|
+
✅ Successfully created: large-book_section_bound.pdf
|
173
|
+
```
|
174
|
+
|
175
|
+
### Dry Run Analysis
|
176
|
+
Preview the binding setup without creating files:
|
177
|
+
|
178
|
+
```bash
|
179
|
+
$ pdf-section-binding book.pdf --dry-run
|
180
|
+
🔍 DRY RUN ANALYSIS:
|
181
|
+
Would process 701 pages
|
182
|
+
Would create 88 signatures
|
183
|
+
Would need 176 papers total
|
184
|
+
Would save to: book_section_bound.pdf
|
185
|
+
```
|
186
|
+
|
187
|
+
Section binding involves:
|
188
|
+
|
189
|
+
1. **Signature Creation**: Pages are grouped into signatures (folded sheets)
|
190
|
+
2. **Page Reordering**: Pages are rearranged so that when printed double-sided and folded, they appear in correct reading order
|
191
|
+
3. **Printing**: Print the reordered PDF double-sided
|
192
|
+
4. **Folding**: Fold each signature in half
|
193
|
+
5. **Binding**: Stack signatures and bind along the fold
|
194
|
+
|
195
|
+
## Signature Sizes
|
196
|
+
|
197
|
+
- **4 pages**: Each signature uses 1 paper (2 pages front, 2 pages back)
|
198
|
+
- **8 pages**: Each signature uses 2 papers (4 pages front, 4 pages back)
|
199
|
+
- **16 pages**: Each signature uses 4 papers (8 pages front, 8 pages back)
|
200
|
+
- **32 pages**: Each signature uses 8 papers (16 pages front, 16 pages back)
|
201
|
+
- **40 pages**: Each signature uses 10 papers (20 pages front, 20 pages back)
|
202
|
+
- **Custom sizes**: Any multiple of 4 pages (e.g., 12=3 papers, 20=5 papers, 24=6 papers)
|
203
|
+
|
204
|
+
## Paper Calculation
|
205
|
+
|
206
|
+
**Formula**: `Papers per signature = Signature size ÷ 4`
|
207
|
+
|
208
|
+
Examples:
|
209
|
+
- 10 papers = 40 pages per signature
|
210
|
+
- 6 papers = 24 pages per signature
|
211
|
+
- 3 papers = 12 pages per signature
|
212
|
+
|
213
|
+
## Example Output
|
214
|
+
|
215
|
+
For a 4-page signature with pages 1, 2, 3, 4:
|
216
|
+
- The reordered sequence would be: [4, 1, 3, 2]
|
217
|
+
- When printed double-sided and folded, you get pages in order: 1, 2, 3, 4
|
218
|
+
|
219
|
+
## Generated Files
|
220
|
+
|
221
|
+
This tool was used to process the book in `data/book.pdf`:
|
222
|
+
|
223
|
+
- `data/book_section_bound.pdf` - Default 8-page signatures (2 papers each)
|
224
|
+
- `data/book_40page_signature.pdf` - 40-page signatures (10 papers each)
|
225
|
+
|
226
|
+
## Publishing to PyPI
|
227
|
+
|
228
|
+
This package is ready for PyPI publication! Here's how to publish it:
|
229
|
+
|
230
|
+
### Prerequisites
|
231
|
+
|
232
|
+
1. Create accounts on [PyPI](https://pypi.org/) and [TestPyPI](https://test.pypi.org/)
|
233
|
+
2. Install build tools:
|
234
|
+
```bash
|
235
|
+
pip install build twine
|
236
|
+
```
|
237
|
+
|
238
|
+
### Build and Upload
|
239
|
+
|
240
|
+
1. **Build the package:**
|
241
|
+
```bash
|
242
|
+
python -m build
|
243
|
+
```
|
244
|
+
|
245
|
+
2. **Test on TestPyPI first:**
|
246
|
+
```bash
|
247
|
+
twine upload --repository testpypi dist/*
|
248
|
+
```
|
249
|
+
|
250
|
+
3. **Upload to PyPI:**
|
251
|
+
```bash
|
252
|
+
twine upload dist/*
|
253
|
+
```
|
254
|
+
|
255
|
+
### Package Structure
|
256
|
+
|
257
|
+
The package follows modern Python packaging standards:
|
258
|
+
|
259
|
+
```
|
260
|
+
pdf-section-binding/
|
261
|
+
├── src/pdf_section_binding/ # Source code
|
262
|
+
│ ├── __init__.py
|
263
|
+
│ ├── cli.py # Enhanced CLI interface
|
264
|
+
│ ├── core.py # Core processing logic
|
265
|
+
│ └── version.py # Version and metadata
|
266
|
+
├── tests/ # Comprehensive test suite
|
267
|
+
├── pyproject.toml # Modern packaging config
|
268
|
+
├── setup.py # Fallback setup config
|
269
|
+
├── LICENSE # MIT license
|
270
|
+
├── README.md # This file
|
271
|
+
└── requirements.txt # Dependencies
|
272
|
+
|
273
|
+
```
|
274
|
+
|
275
|
+
### Development Setup
|
276
|
+
|
277
|
+
For development work:
|
278
|
+
|
279
|
+
```bash
|
280
|
+
# Clone and setup
|
281
|
+
git clone <your-repo-url>
|
282
|
+
cd pdf-section-binding
|
283
|
+
|
284
|
+
# Create virtual environment
|
285
|
+
python -m venv venv
|
286
|
+
source venv/bin/activate # or venv\Scripts\activate on Windows
|
287
|
+
|
288
|
+
# Install in development mode
|
289
|
+
pip install -e .[dev]
|
290
|
+
|
291
|
+
# Run tests
|
292
|
+
pytest
|
293
|
+
|
294
|
+
# Run with coverage
|
295
|
+
pytest --cov=pdf_section_binding
|
296
|
+
|
297
|
+
# Format code
|
298
|
+
black src/ tests/
|
299
|
+
|
300
|
+
# Lint code
|
301
|
+
pylint src/ tests/
|
302
|
+
|
303
|
+
# Type checking
|
304
|
+
mypy src/
|
305
|
+
```
|
306
|
+
|
307
|
+
## Requirements
|
308
|
+
|
309
|
+
- Python 3.7+
|
310
|
+
- PyPDF2 library
|
311
|
+
|
312
|
+
## Binding Instructions
|
313
|
+
|
314
|
+
After running the script:
|
315
|
+
|
316
|
+
1. Print the output PDF double-sided (flip on long edge)
|
317
|
+
2. Cut or separate the printed sheets by signature
|
318
|
+
3. Fold each signature in half along the center
|
319
|
+
4. Stack all signatures in order
|
320
|
+
5. Bind along the folded edge using:
|
321
|
+
- Saddle stitching (stapling)
|
322
|
+
- Perfect binding (glue)
|
323
|
+
- Spiral binding
|
324
|
+
- Or other binding methods
|
@@ -0,0 +1,278 @@
|
|
1
|
+
# PDF Section Binding Tool
|
2
|
+
|
3
|
+
This tool reorders PDF pages for section binding (bookbinding), where pages are arranged in signatures (folded sheets) so that when printed and folded, they appear in the correct reading order.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
### From PyPI (Recommended)
|
8
|
+
|
9
|
+
```bash
|
10
|
+
pip install pdf-section-binding
|
11
|
+
```
|
12
|
+
|
13
|
+
### From Source
|
14
|
+
|
15
|
+
1. Clone the repository:
|
16
|
+
```bash
|
17
|
+
git clone https://github.com/yourusername/pdf-section-binding.git
|
18
|
+
cd pdf-section-binding
|
19
|
+
```
|
20
|
+
|
21
|
+
2. Create and activate virtual environment:
|
22
|
+
```bash
|
23
|
+
python3 -m venv venv
|
24
|
+
source venv/bin/activate # On macOS/Linux
|
25
|
+
# or
|
26
|
+
venv\Scripts\activate # On Windows
|
27
|
+
```
|
28
|
+
|
29
|
+
3. Install in development mode:
|
30
|
+
```bash
|
31
|
+
pip install -e .
|
32
|
+
```
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
After installation, use the `pdf-section-binding` command (or the shorter `section-binding` alias):
|
37
|
+
|
38
|
+
```bash
|
39
|
+
pdf-section-binding input.pdf [options]
|
40
|
+
```
|
41
|
+
|
42
|
+
### Command Line Options
|
43
|
+
|
44
|
+
- `-o, --output`: Output PDF file path (default: `input_name_section_bound.pdf`)
|
45
|
+
- `-s, --signature-size`: Pages per signature - must be multiple of 4 (default: 8)
|
46
|
+
- `--dry-run`: Preview analysis without creating output file
|
47
|
+
- `-v, --verbose`: Enable verbose output with progress tracking
|
48
|
+
- `-q, --quiet`: Suppress all output except errors
|
49
|
+
- `--force`: Overwrite output file if it exists
|
50
|
+
- `--version`: Show version information
|
51
|
+
- `-h, --help`: Show help message
|
52
|
+
|
53
|
+
### Examples
|
54
|
+
|
55
|
+
```bash
|
56
|
+
# Basic usage with 8-page signatures (2 papers per signature)
|
57
|
+
pdf-section-binding book.pdf
|
58
|
+
|
59
|
+
# Specify output file and 4-page signatures (1 paper per signature)
|
60
|
+
pdf-section-binding book.pdf -o output.pdf -s 4
|
61
|
+
|
62
|
+
# Use 16-page signatures (4 papers per signature)
|
63
|
+
pdf-section-binding book.pdf -s 16
|
64
|
+
|
65
|
+
# Use 40-page signatures (10 papers per signature)
|
66
|
+
pdf-section-binding book.pdf -s 40
|
67
|
+
|
68
|
+
# Preview without creating file (dry run)
|
69
|
+
pdf-section-binding book.pdf --dry-run
|
70
|
+
|
71
|
+
# Verbose output with progress tracking
|
72
|
+
pdf-section-binding book.pdf -v
|
73
|
+
|
74
|
+
# Quiet mode (minimal output)
|
75
|
+
pdf-section-binding book.pdf -q
|
76
|
+
|
77
|
+
# Force overwrite existing output
|
78
|
+
pdf-section-binding book.pdf --force
|
79
|
+
```
|
80
|
+
|
81
|
+
## Features
|
82
|
+
|
83
|
+
✨ **Enhanced CLI Tool**
|
84
|
+
- 🎨 **Colorized output** for better user experience
|
85
|
+
- 📊 **Progress tracking** for large documents
|
86
|
+
- 🔍 **Dry run mode** to preview without creating files
|
87
|
+
- ⚡ **Fast processing** with optimized algorithms
|
88
|
+
- 🛡️ **Robust error handling** with helpful suggestions
|
89
|
+
- 📏 **Flexible signature sizes** (any multiple of 4)
|
90
|
+
|
91
|
+
🔧 **Advanced Options**
|
92
|
+
- Verbose and quiet modes
|
93
|
+
- Force overwrite protection
|
94
|
+
- Input validation with helpful error messages
|
95
|
+
- Multiple command aliases (`pdf-section-binding` or `section-binding`)
|
96
|
+
|
97
|
+
📦 **Library Usage**
|
98
|
+
- Use as a Python library in your own projects
|
99
|
+
- Clean API with `SectionBindingProcessor` class
|
100
|
+
- Comprehensive test suite included
|
101
|
+
|
102
|
+
## CLI Features in Detail
|
103
|
+
|
104
|
+
### Smart Error Messages
|
105
|
+
The tool provides helpful suggestions when you make mistakes:
|
106
|
+
|
107
|
+
```bash
|
108
|
+
$ pdf-section-binding book.pdf -s 15
|
109
|
+
Error: Signature size must be a multiple of 4 (each paper = 4 pages).
|
110
|
+
You specified 15. Try: 12 or 16
|
111
|
+
```
|
112
|
+
|
113
|
+
### Progress Tracking
|
114
|
+
For large documents, see progress in real-time:
|
115
|
+
|
116
|
+
```bash
|
117
|
+
$ pdf-section-binding large-book.pdf -v
|
118
|
+
PDF Section Binding Tool v1.0.0
|
119
|
+
==================================================
|
120
|
+
[INFO] Reading PDF: large-book.pdf
|
121
|
+
[INFO] Total pages: 1500
|
122
|
+
[INFO] Signature size: 8
|
123
|
+
[INFO] Creating reordered PDF...
|
124
|
+
Creating PDF: [████████████████████████████████████████████████] 100% (1500/1500)
|
125
|
+
[INFO] Writing output: large-book_section_bound.pdf
|
126
|
+
✅ Successfully created: large-book_section_bound.pdf
|
127
|
+
```
|
128
|
+
|
129
|
+
### Dry Run Analysis
|
130
|
+
Preview the binding setup without creating files:
|
131
|
+
|
132
|
+
```bash
|
133
|
+
$ pdf-section-binding book.pdf --dry-run
|
134
|
+
🔍 DRY RUN ANALYSIS:
|
135
|
+
Would process 701 pages
|
136
|
+
Would create 88 signatures
|
137
|
+
Would need 176 papers total
|
138
|
+
Would save to: book_section_bound.pdf
|
139
|
+
```
|
140
|
+
|
141
|
+
Section binding involves:
|
142
|
+
|
143
|
+
1. **Signature Creation**: Pages are grouped into signatures (folded sheets)
|
144
|
+
2. **Page Reordering**: Pages are rearranged so that when printed double-sided and folded, they appear in correct reading order
|
145
|
+
3. **Printing**: Print the reordered PDF double-sided
|
146
|
+
4. **Folding**: Fold each signature in half
|
147
|
+
5. **Binding**: Stack signatures and bind along the fold
|
148
|
+
|
149
|
+
## Signature Sizes
|
150
|
+
|
151
|
+
- **4 pages**: Each signature uses 1 paper (2 pages front, 2 pages back)
|
152
|
+
- **8 pages**: Each signature uses 2 papers (4 pages front, 4 pages back)
|
153
|
+
- **16 pages**: Each signature uses 4 papers (8 pages front, 8 pages back)
|
154
|
+
- **32 pages**: Each signature uses 8 papers (16 pages front, 16 pages back)
|
155
|
+
- **40 pages**: Each signature uses 10 papers (20 pages front, 20 pages back)
|
156
|
+
- **Custom sizes**: Any multiple of 4 pages (e.g., 12=3 papers, 20=5 papers, 24=6 papers)
|
157
|
+
|
158
|
+
## Paper Calculation
|
159
|
+
|
160
|
+
**Formula**: `Papers per signature = Signature size ÷ 4`
|
161
|
+
|
162
|
+
Examples:
|
163
|
+
- 10 papers = 40 pages per signature
|
164
|
+
- 6 papers = 24 pages per signature
|
165
|
+
- 3 papers = 12 pages per signature
|
166
|
+
|
167
|
+
## Example Output
|
168
|
+
|
169
|
+
For a 4-page signature with pages 1, 2, 3, 4:
|
170
|
+
- The reordered sequence would be: [4, 1, 3, 2]
|
171
|
+
- When printed double-sided and folded, you get pages in order: 1, 2, 3, 4
|
172
|
+
|
173
|
+
## Generated Files
|
174
|
+
|
175
|
+
This tool was used to process the book in `data/book.pdf`:
|
176
|
+
|
177
|
+
- `data/book_section_bound.pdf` - Default 8-page signatures (2 papers each)
|
178
|
+
- `data/book_40page_signature.pdf` - 40-page signatures (10 papers each)
|
179
|
+
|
180
|
+
## Publishing to PyPI
|
181
|
+
|
182
|
+
This package is ready for PyPI publication! Here's how to publish it:
|
183
|
+
|
184
|
+
### Prerequisites
|
185
|
+
|
186
|
+
1. Create accounts on [PyPI](https://pypi.org/) and [TestPyPI](https://test.pypi.org/)
|
187
|
+
2. Install build tools:
|
188
|
+
```bash
|
189
|
+
pip install build twine
|
190
|
+
```
|
191
|
+
|
192
|
+
### Build and Upload
|
193
|
+
|
194
|
+
1. **Build the package:**
|
195
|
+
```bash
|
196
|
+
python -m build
|
197
|
+
```
|
198
|
+
|
199
|
+
2. **Test on TestPyPI first:**
|
200
|
+
```bash
|
201
|
+
twine upload --repository testpypi dist/*
|
202
|
+
```
|
203
|
+
|
204
|
+
3. **Upload to PyPI:**
|
205
|
+
```bash
|
206
|
+
twine upload dist/*
|
207
|
+
```
|
208
|
+
|
209
|
+
### Package Structure
|
210
|
+
|
211
|
+
The package follows modern Python packaging standards:
|
212
|
+
|
213
|
+
```
|
214
|
+
pdf-section-binding/
|
215
|
+
├── src/pdf_section_binding/ # Source code
|
216
|
+
│ ├── __init__.py
|
217
|
+
│ ├── cli.py # Enhanced CLI interface
|
218
|
+
│ ├── core.py # Core processing logic
|
219
|
+
│ └── version.py # Version and metadata
|
220
|
+
├── tests/ # Comprehensive test suite
|
221
|
+
├── pyproject.toml # Modern packaging config
|
222
|
+
├── setup.py # Fallback setup config
|
223
|
+
├── LICENSE # MIT license
|
224
|
+
├── README.md # This file
|
225
|
+
└── requirements.txt # Dependencies
|
226
|
+
|
227
|
+
```
|
228
|
+
|
229
|
+
### Development Setup
|
230
|
+
|
231
|
+
For development work:
|
232
|
+
|
233
|
+
```bash
|
234
|
+
# Clone and setup
|
235
|
+
git clone <your-repo-url>
|
236
|
+
cd pdf-section-binding
|
237
|
+
|
238
|
+
# Create virtual environment
|
239
|
+
python -m venv venv
|
240
|
+
source venv/bin/activate # or venv\Scripts\activate on Windows
|
241
|
+
|
242
|
+
# Install in development mode
|
243
|
+
pip install -e .[dev]
|
244
|
+
|
245
|
+
# Run tests
|
246
|
+
pytest
|
247
|
+
|
248
|
+
# Run with coverage
|
249
|
+
pytest --cov=pdf_section_binding
|
250
|
+
|
251
|
+
# Format code
|
252
|
+
black src/ tests/
|
253
|
+
|
254
|
+
# Lint code
|
255
|
+
pylint src/ tests/
|
256
|
+
|
257
|
+
# Type checking
|
258
|
+
mypy src/
|
259
|
+
```
|
260
|
+
|
261
|
+
## Requirements
|
262
|
+
|
263
|
+
- Python 3.7+
|
264
|
+
- PyPDF2 library
|
265
|
+
|
266
|
+
## Binding Instructions
|
267
|
+
|
268
|
+
After running the script:
|
269
|
+
|
270
|
+
1. Print the output PDF double-sided (flip on long edge)
|
271
|
+
2. Cut or separate the printed sheets by signature
|
272
|
+
3. Fold each signature in half along the center
|
273
|
+
4. Stack all signatures in order
|
274
|
+
5. Bind along the folded edge using:
|
275
|
+
- Saddle stitching (stapling)
|
276
|
+
- Perfect binding (glue)
|
277
|
+
- Spiral binding
|
278
|
+
- Or other binding methods
|