pdfsplit 0.1.0
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.
- checksums.yaml +7 -0
- data/.idea/.gitignore +10 -0
- data/.idea/modules.xml +8 -0
- data/.idea/pdfsplit.iml +54 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/CHANGELOG.md +6 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +122 -0
- data/Rakefile +12 -0
- data/exe/pdfsplit +7 -0
- data/lib/pdfsplit/cli.rb +85 -0
- data/lib/pdfsplit/splitter.rb +32 -0
- data/lib/pdfsplit/version.rb +5 -0
- data/lib/pdfsplit.rb +11 -0
- data/sig/pdfsplit.rbs +4 -0
- metadata +78 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 88ab14a47b95bfccc2da78ae1225171ec58d24cc4e184929e0fdbb47bf35c8b1
|
|
4
|
+
data.tar.gz: ee799c83c1c7f5b1c8741b60f6434ae9c7c5f9e4c10c5bc05b87a36f4efa0d65
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d397ef0239901506a6cb8bb7ce275b6289fdd851dc73ce894635c7aacdf52c1c7c5c351102689a203fe42dd875f9854bc4c376cfd5b679a8f1065455b65d0cf5
|
|
7
|
+
data.tar.gz: b9d0b912fc487c98e13c19a029d0887adafcf4757fb3fad7d365c101cc5b0867f576e91c4303e9a7610b5679895dc2716359f71ba5384faca0a06ea6c5915296
|
data/.idea/.gitignore
ADDED
data/.idea/modules.xml
ADDED
data/.idea/pdfsplit.iml
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
|
4
|
+
<shared />
|
|
5
|
+
</component>
|
|
6
|
+
<component name="NewModuleRootManager">
|
|
7
|
+
<content url="file://$MODULE_DIR$">
|
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
|
10
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
|
11
|
+
</content>
|
|
12
|
+
<orderEntry type="jdk" jdkName="ruby-3.4.7-p58" jdkType="RUBY_SDK" />
|
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.3, ruby-3.4.7-p58) [gem]" level="application" />
|
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.6.9, ruby-3.4.7-p58) [gem]" level="application" />
|
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="cmdparse (v3.0.7, ruby-3.4.7-p58) [gem]" level="application" />
|
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="date (v3.5.1, ruby-3.4.7-p58) [gem]" level="application" />
|
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.6.2, ruby-3.4.7-p58) [gem]" level="application" />
|
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="erb (v6.0.1, ruby-3.4.7-p58) [gem]" level="application" />
|
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="geom2d (v0.4.1, ruby-3.4.7-p58) [gem]" level="application" />
|
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="hexapdf (v1.5.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="io-console (v0.8.2, ruby-3.4.7-p58) [gem]" level="application" />
|
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="irb (v1.16.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="json (v2.18.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="language_server-protocol (v3.17.0.5, ruby-3.4.7-p58) [gem]" level="application" />
|
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="lint_roller (v1.1.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="openssl (v4.0.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.27.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="parser (v3.3.10.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="pp (v0.6.3, ruby-3.4.7-p58) [gem]" level="application" />
|
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="prettyprint (v0.2.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="prism (v1.7.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
33
|
+
<orderEntry type="library" scope="PROVIDED" name="psych (v5.3.1, ruby-3.4.7-p58) [gem]" level="application" />
|
|
34
|
+
<orderEntry type="library" scope="PROVIDED" name="racc (v1.8.1, ruby-3.4.7-p58) [gem]" level="application" />
|
|
35
|
+
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, ruby-3.4.7-p58) [gem]" level="application" />
|
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.3.1, ruby-3.4.7-p58) [gem]" level="application" />
|
|
37
|
+
<orderEntry type="library" scope="PROVIDED" name="rdoc (v7.0.1, ruby-3.4.7-p58) [gem]" level="application" />
|
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.11.3, ruby-3.4.7-p58) [gem]" level="application" />
|
|
39
|
+
<orderEntry type="library" scope="PROVIDED" name="reline (v0.6.3, ruby-3.4.7-p58) [gem]" level="application" />
|
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.13.2, ruby-3.4.7-p58) [gem]" level="application" />
|
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.13.6, ruby-3.4.7-p58) [gem]" level="application" />
|
|
42
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.13.5, ruby-3.4.7-p58) [gem]" level="application" />
|
|
43
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.13.7, ruby-3.4.7-p58) [gem]" level="application" />
|
|
44
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.13.6, ruby-3.4.7-p58) [gem]" level="application" />
|
|
45
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.82.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
46
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.48.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
47
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.13.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
48
|
+
<orderEntry type="library" scope="PROVIDED" name="stringio (v3.2.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
49
|
+
<orderEntry type="library" scope="PROVIDED" name="strscan (v3.1.6, ruby-3.4.7-p58) [gem]" level="application" />
|
|
50
|
+
<orderEntry type="library" scope="PROVIDED" name="tsort (v0.2.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
51
|
+
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v3.2.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
52
|
+
<orderEntry type="library" scope="PROVIDED" name="unicode-emoji (v4.2.0, ruby-3.4.7-p58) [gem]" level="application" />
|
|
53
|
+
</component>
|
|
54
|
+
</module>
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official email address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
[INSERT CONTACT METHOD].
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shiyano
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Pdfsplit
|
|
2
|
+
|
|
3
|
+
`pdfsplit` is a Ruby CLI tool that splits a multi-page PDF into smaller PDF files with a fixed number of pages per part.
|
|
4
|
+
|
|
5
|
+
- Cross-platform: Linux / Windows (with Ruby installed)
|
|
6
|
+
- No external PDF utilities required (no `pdftk`, `qpdf`, etc.)
|
|
7
|
+
- Uses the **HexaPDF** gem to handle PDF files
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- Splits `input.pdf` into files like `input_part001.pdf`, `input_part002.pdf`, ...
|
|
14
|
+
- Part size is configured via `--pages N`
|
|
15
|
+
- Output directory is configured via `--out DIR` (defaults to current directory `.`)
|
|
16
|
+
- `--help`, `--version`
|
|
17
|
+
- Clear error messages and proper exit codes (0 = success, 1 = error)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Requirements
|
|
22
|
+
|
|
23
|
+
- Ruby (3.1+ recommended)
|
|
24
|
+
- Bundler
|
|
25
|
+
|
|
26
|
+
> On Linux you may need system development packages (headers/libs) to build native extensions if Bundler fails while installing dependencies.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Installation (from the repository)
|
|
31
|
+
|
|
32
|
+
Clone the repository and install dependencies:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
bundle install
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
### Split a PDF into parts of N pages
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
bundle exec pdfsplit input.pdf --pages 10
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Outputs will be created in the current directory:
|
|
47
|
+
|
|
48
|
+
- `input_part001.pdf`
|
|
49
|
+
- `input_part002.pdf`
|
|
50
|
+
- ...
|
|
51
|
+
|
|
52
|
+
### Specify an output directory
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
bundle exec pdfsplit input.pdf --pages 10 --out out
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Files will be created in `out/`.
|
|
59
|
+
|
|
60
|
+
### Help
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
bundle exec pdfsplit --help
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Version
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
bundle exec pdfsplit --version
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Output naming
|
|
75
|
+
|
|
76
|
+
Given an input file `input.pdf`, the tool writes:
|
|
77
|
+
|
|
78
|
+
- `input_part001.pdf`
|
|
79
|
+
- `input_part002.pdf`
|
|
80
|
+
- `input_part003.pdf`
|
|
81
|
+
- ...
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Errors & behavior
|
|
86
|
+
|
|
87
|
+
- Missing input file → exit 1 + Usage
|
|
88
|
+
- Missing --pages / --pages <= 0 → exit 1 + Usage
|
|
89
|
+
- More than one input file provided → exit 1 + Usage
|
|
90
|
+
- Input file does not exist → exit 1 + OS error message
|
|
91
|
+
- Input is not a valid PDF → exit 1 + Error: invalid PDF
|
|
92
|
+
- --out points to an existing file → exit 1 + Error: --out must be a directory
|
|
93
|
+
- Output directory is not writable → exit 1 + OS error message
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
Run tests:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
bundle exec rspec
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Install the gem locally (to test it as an installed gem):
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
bundle exec rake install
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Open an interactive console (Bundler-generated helper):
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
bin/console
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
MIT License
|
|
122
|
+
|
data/Rakefile
ADDED
data/exe/pdfsplit
ADDED
data/lib/pdfsplit/cli.rb
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "optparse"
|
|
4
|
+
|
|
5
|
+
module Pdfsplit
|
|
6
|
+
class CLI
|
|
7
|
+
def self.start(argv)
|
|
8
|
+
pages = nil
|
|
9
|
+
out_dir = nil
|
|
10
|
+
|
|
11
|
+
parser = OptionParser.new do |opts|
|
|
12
|
+
opts.banner = "Usage: pdfsplit .pdf --pages N [--out DIR]"
|
|
13
|
+
|
|
14
|
+
opts.on("-h", "--help", "Show help") do
|
|
15
|
+
puts opts
|
|
16
|
+
return 0
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
opts.on("--pages N", Integer, "Pages per part") do |n|
|
|
20
|
+
pages = n
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
opts.on("--version", "Show version") do
|
|
24
|
+
puts Pdfsplit::VERSION
|
|
25
|
+
return 0
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
opts.on("--out DIR", String, "Output directory") do |dir|
|
|
29
|
+
out_dir = dir
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
parser.parse!(argv)
|
|
34
|
+
|
|
35
|
+
if argv.empty?
|
|
36
|
+
warn "Error: missing .pdf"
|
|
37
|
+
warn parser.to_s
|
|
38
|
+
return 1
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
if argv.size != 1
|
|
42
|
+
warn "Error: only one input .pdf is allowed"
|
|
43
|
+
warn parser.to_s
|
|
44
|
+
return 1
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
if pages.nil?
|
|
48
|
+
warn "Error: missing --pages"
|
|
49
|
+
warn parser.to_s
|
|
50
|
+
return 1
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
if pages <= 0
|
|
54
|
+
warn "Error: --pages must be > 0"
|
|
55
|
+
warn parser.to_s
|
|
56
|
+
return 1
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
input_path = argv.first
|
|
61
|
+
out_dir ||="."
|
|
62
|
+
|
|
63
|
+
if File.exist?(out_dir) && !File.directory?(out_dir)
|
|
64
|
+
warn "Error: --out must be a directory"
|
|
65
|
+
return 1
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
Pdfsplit::Splitter.split(input_path: input_path, pages_per_part: pages, out_dir: out_dir)
|
|
69
|
+
0
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
rescue OptionParser::ParseError => e
|
|
73
|
+
warn e.message
|
|
74
|
+
warn parser.to_s
|
|
75
|
+
1
|
|
76
|
+
rescue HexaPDF::Error
|
|
77
|
+
warn "Error: invalid PDF"
|
|
78
|
+
1
|
|
79
|
+
rescue SystemCallError, Pdfsplit::Error => e
|
|
80
|
+
warn e.message
|
|
81
|
+
1
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "hexapdf"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
|
|
6
|
+
module Pdfsplit
|
|
7
|
+
class Splitter
|
|
8
|
+
def self.split(input_path:, pages_per_part:, out_dir:)
|
|
9
|
+
raise ArgumentError, "pages_per_part must be > 0" if pages_per_part.to_i <= 0
|
|
10
|
+
|
|
11
|
+
FileUtils.mkdir_p(out_dir)
|
|
12
|
+
|
|
13
|
+
doc = HexaPDF::Document.open(input_path)
|
|
14
|
+
pages = doc.pages.to_a
|
|
15
|
+
|
|
16
|
+
base = File.basename(input_path, File.extname(input_path))
|
|
17
|
+
|
|
18
|
+
pages.each_slice(pages_per_part).with_index(1) do |slice, idx|
|
|
19
|
+
out_doc = HexaPDF::Document.new
|
|
20
|
+
slice.each do |page|
|
|
21
|
+
out_doc.pages << out_doc.import(page)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
out_path = File.join(out_dir, format("%s_part%03d.pdf", base, idx))
|
|
25
|
+
out_doc.write(out_path)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
true
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/pdfsplit.rb
ADDED
data/sig/pdfsplit.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: pdfsplit
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Shiyano
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: hexapdf
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.5'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.5'
|
|
26
|
+
description: pdfsplit is a command-line utility that splits a multi-page PDF into
|
|
27
|
+
multiple smaller PDF files. You can specify how many pages should be included in
|
|
28
|
+
each output part.
|
|
29
|
+
email:
|
|
30
|
+
- shiyanotetsu@gmail.com
|
|
31
|
+
executables:
|
|
32
|
+
- pdfsplit
|
|
33
|
+
extensions: []
|
|
34
|
+
extra_rdoc_files: []
|
|
35
|
+
files:
|
|
36
|
+
- ".idea/.gitignore"
|
|
37
|
+
- ".idea/modules.xml"
|
|
38
|
+
- ".idea/pdfsplit.iml"
|
|
39
|
+
- ".rspec"
|
|
40
|
+
- ".rubocop.yml"
|
|
41
|
+
- CHANGELOG.md
|
|
42
|
+
- CODE_OF_CONDUCT.md
|
|
43
|
+
- LICENSE.txt
|
|
44
|
+
- README.md
|
|
45
|
+
- Rakefile
|
|
46
|
+
- exe/pdfsplit
|
|
47
|
+
- lib/pdfsplit.rb
|
|
48
|
+
- lib/pdfsplit/cli.rb
|
|
49
|
+
- lib/pdfsplit/splitter.rb
|
|
50
|
+
- lib/pdfsplit/version.rb
|
|
51
|
+
- sig/pdfsplit.rbs
|
|
52
|
+
homepage: https://github.com/ShiyanoTetsu/pdfsplit.git
|
|
53
|
+
licenses:
|
|
54
|
+
- MIT
|
|
55
|
+
metadata:
|
|
56
|
+
homepage_uri: https://github.com/ShiyanoTetsu/pdfsplit.git
|
|
57
|
+
source_code_uri: https://github.com/ShiyanoTetsu/pdfsplit.git
|
|
58
|
+
changelog_uri: https://github.com/ShiyanoTetsu/pdfsplit.git/blob/main/CHANGELOG.md
|
|
59
|
+
rubygems_mfa_required: 'true'
|
|
60
|
+
rdoc_options: []
|
|
61
|
+
require_paths:
|
|
62
|
+
- lib
|
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 3.1.0
|
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - ">="
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '0'
|
|
73
|
+
requirements: []
|
|
74
|
+
rubygems_version: 3.6.9
|
|
75
|
+
specification_version: 4
|
|
76
|
+
summary: is a Ruby CLI tool that splits a multi-page PDF into smaller PDF files with
|
|
77
|
+
a fixed number of pages per part
|
|
78
|
+
test_files: []
|