pdfcrowd-cli 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.
- pdfcrowd_cli-1.0.0/LICENSE +22 -0
- pdfcrowd_cli-1.0.0/MANIFEST.in +2 -0
- pdfcrowd_cli-1.0.0/PKG-INFO +120 -0
- pdfcrowd_cli-1.0.0/README.md +99 -0
- pdfcrowd_cli-1.0.0/makefile +23 -0
- pdfcrowd_cli-1.0.0/package_download.py +17 -0
- pdfcrowd_cli-1.0.0/pyproject.toml +3 -0
- pdfcrowd_cli-1.0.0/release.json +7 -0
- pdfcrowd_cli-1.0.0/setup.cfg +4 -0
- pdfcrowd_cli-1.0.0/setup.py +35 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli/__init__.py +24 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli/__main__.py +28 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli/adapter.py +143 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli/catalog.py +46 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli/command-spec.json +16717 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli/entrypoints.py +228 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli/help.py +385 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli/parser.py +189 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli/state.py +368 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli/windows.py +173 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli.egg-info/PKG-INFO +120 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli.egg-info/SOURCES.txt +24 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli.egg-info/dependency_links.txt +1 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli.egg-info/entry_points.txt +10 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli.egg-info/requires.txt +2 -0
- pdfcrowd_cli-1.0.0/src/pdfcrowd_cli.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (C) 2009-2026 pdfcrowd.com
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
|
4
|
+
obtaining a copy of this software and associated documentation
|
|
5
|
+
files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use,
|
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the
|
|
9
|
+
Software is furnished to do so, subject to the following
|
|
10
|
+
conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: pdfcrowd-cli
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Command-line converters for the PDFCrowd API.
|
|
5
|
+
Home-page: https://pdfcrowd.com/api/
|
|
6
|
+
Author: PDFCrowd Team
|
|
7
|
+
License: MIT
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: pdfcrowd<7.1.0,>=7.0.0
|
|
12
|
+
Requires-Dist: platformdirs<5,>=4.3.6
|
|
13
|
+
Dynamic: author
|
|
14
|
+
Dynamic: description
|
|
15
|
+
Dynamic: description-content-type
|
|
16
|
+
Dynamic: home-page
|
|
17
|
+
Dynamic: license
|
|
18
|
+
Dynamic: requires-dist
|
|
19
|
+
Dynamic: requires-python
|
|
20
|
+
Dynamic: summary
|
|
21
|
+
|
|
22
|
+
# PDFCrowd CLI
|
|
23
|
+
|
|
24
|
+
Install with Python 3.8 or newer using pipx or uv:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
pipx install pdfcrowd-cli
|
|
28
|
+
# Alternatively: uv tool install pdfcrowd-cli
|
|
29
|
+
pdfcrowd html2pdf --output example.pdf https://example.com
|
|
30
|
+
pdfcrowd --help
|
|
31
|
+
pdfcrowd html2pdf help page-margins
|
|
32
|
+
pdfcrowd html2pdf help --json
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The CLI package also provides the converter commands directly:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
html2pdf --output example.pdf https://example.com
|
|
39
|
+
html2pdf --help
|
|
40
|
+
html2pdf help page-margins
|
|
41
|
+
html2pdf help --json
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The available commands are `html2pdf`, `html2image`, `image2pdf`,
|
|
45
|
+
`image2image`, `pdf2pdf`, `pdf2html`, `pdf2text`, and `pdf2image`.
|
|
46
|
+
Without personal credentials, conversions use the demo account and produce
|
|
47
|
+
marked output. Set `PDFCROWD_USERNAME` and `PDFCROWD_API_KEY`, or save your
|
|
48
|
+
account with `pdfcrowd auth login`. For unattended login, set both environment
|
|
49
|
+
variables and run `pdfcrowd auth login --non-interactive`. Conversions never
|
|
50
|
+
prompt for credentials.
|
|
51
|
+
|
|
52
|
+
Environment credentials take priority over the saved account. To use demo
|
|
53
|
+
even when personal credentials are saved:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
PDFCROWD_USERNAME=demo PDFCROWD_API_KEY=demo \
|
|
57
|
+
html2pdf --output example.pdf https://example.com
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Long options use `--name`. Account credentials are not accepted as arguments.
|
|
61
|
+
Boolean conversion options accept `true` or `false`. Compound option arguments
|
|
62
|
+
are separate values: `--page-margins 10mm 10mm 10mm 10mm`. Quote each value
|
|
63
|
+
individually when needed; semicolons inside values are preserved. Use
|
|
64
|
+
`--option=VALUE` for values that match an option name. Compound options can
|
|
65
|
+
also take a JSON array: `--http-auth='["username", "password"]'`.
|
|
66
|
+
|
|
67
|
+
`help`, version, and JSON help work offline. Conversion output uses
|
|
68
|
+
`--output FILE` or redirected stdout; only `pdf2text` writes results directly
|
|
69
|
+
to a terminal. Failed file conversions preserve the previous output.
|
|
70
|
+
Options can appear between input files:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
pdfcrowd pdf2pdf first.pdf -o merged.pdf second.pdf
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Diagnostics use stderr. Service errors preserve the SDK's complete message,
|
|
77
|
+
including URLs, option values, and documentation links.
|
|
78
|
+
Exit status 1 means an output
|
|
79
|
+
pipe closed; Ctrl-C exits with status 130.
|
|
80
|
+
|
|
81
|
+
Converter settings are read from a per-converter sectionless INI file, but
|
|
82
|
+
command invocations never automatically save settings. `--init-config` creates
|
|
83
|
+
a commented starter; `--show-config` inspects effective defaults; `--no-config`
|
|
84
|
+
bypasses saved conversion defaults while keeping credentials available.
|
|
85
|
+
`--show-config` lists conversion settings from the file and command line;
|
|
86
|
+
other options use their API defaults. Compound configuration values use JSON
|
|
87
|
+
arrays of strings. `auth login` explicitly saves shared credentials;
|
|
88
|
+
`auth logout` removes them. Use `help configuration` and `help authentication`
|
|
89
|
+
for paths, precedence, examples, and details.
|
|
90
|
+
|
|
91
|
+
For example:
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
pdfcrowd html2pdf --init-config
|
|
95
|
+
# Open the created file and uncomment the settings you want to use.
|
|
96
|
+
pdfcrowd html2pdf --show-config
|
|
97
|
+
pdfcrowd html2pdf help --init-config
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
For scripts, integrations, and AI agents, `pdfcrowd html2pdf help --json`
|
|
101
|
+
describes available options, argument types, defaults, and exit codes as JSON.
|
|
102
|
+
Use `pdfcrowd help --json` for all converters.
|
|
103
|
+
|
|
104
|
+
pipx and uv expose `pdfcrowd` and all eight converter commands. The CLI
|
|
105
|
+
installation includes the compatible SDK automatically.
|
|
106
|
+
|
|
107
|
+
The Python SDK contains only the API clients. All commands are provided by
|
|
108
|
+
`pdfcrowd-cli`, so the SDK and CLI can share a virtual environment:
|
|
109
|
+
|
|
110
|
+
```sh
|
|
111
|
+
python -m pip install pdfcrowd-cli
|
|
112
|
+
html2pdf --help
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
This public source builds independently of the private generator checkout:
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
python -m pip install .
|
|
119
|
+
make build
|
|
120
|
+
```
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# PDFCrowd CLI
|
|
2
|
+
|
|
3
|
+
Install with Python 3.8 or newer using pipx or uv:
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pipx install pdfcrowd-cli
|
|
7
|
+
# Alternatively: uv tool install pdfcrowd-cli
|
|
8
|
+
pdfcrowd html2pdf --output example.pdf https://example.com
|
|
9
|
+
pdfcrowd --help
|
|
10
|
+
pdfcrowd html2pdf help page-margins
|
|
11
|
+
pdfcrowd html2pdf help --json
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The CLI package also provides the converter commands directly:
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
html2pdf --output example.pdf https://example.com
|
|
18
|
+
html2pdf --help
|
|
19
|
+
html2pdf help page-margins
|
|
20
|
+
html2pdf help --json
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The available commands are `html2pdf`, `html2image`, `image2pdf`,
|
|
24
|
+
`image2image`, `pdf2pdf`, `pdf2html`, `pdf2text`, and `pdf2image`.
|
|
25
|
+
Without personal credentials, conversions use the demo account and produce
|
|
26
|
+
marked output. Set `PDFCROWD_USERNAME` and `PDFCROWD_API_KEY`, or save your
|
|
27
|
+
account with `pdfcrowd auth login`. For unattended login, set both environment
|
|
28
|
+
variables and run `pdfcrowd auth login --non-interactive`. Conversions never
|
|
29
|
+
prompt for credentials.
|
|
30
|
+
|
|
31
|
+
Environment credentials take priority over the saved account. To use demo
|
|
32
|
+
even when personal credentials are saved:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
PDFCROWD_USERNAME=demo PDFCROWD_API_KEY=demo \
|
|
36
|
+
html2pdf --output example.pdf https://example.com
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Long options use `--name`. Account credentials are not accepted as arguments.
|
|
40
|
+
Boolean conversion options accept `true` or `false`. Compound option arguments
|
|
41
|
+
are separate values: `--page-margins 10mm 10mm 10mm 10mm`. Quote each value
|
|
42
|
+
individually when needed; semicolons inside values are preserved. Use
|
|
43
|
+
`--option=VALUE` for values that match an option name. Compound options can
|
|
44
|
+
also take a JSON array: `--http-auth='["username", "password"]'`.
|
|
45
|
+
|
|
46
|
+
`help`, version, and JSON help work offline. Conversion output uses
|
|
47
|
+
`--output FILE` or redirected stdout; only `pdf2text` writes results directly
|
|
48
|
+
to a terminal. Failed file conversions preserve the previous output.
|
|
49
|
+
Options can appear between input files:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
pdfcrowd pdf2pdf first.pdf -o merged.pdf second.pdf
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Diagnostics use stderr. Service errors preserve the SDK's complete message,
|
|
56
|
+
including URLs, option values, and documentation links.
|
|
57
|
+
Exit status 1 means an output
|
|
58
|
+
pipe closed; Ctrl-C exits with status 130.
|
|
59
|
+
|
|
60
|
+
Converter settings are read from a per-converter sectionless INI file, but
|
|
61
|
+
command invocations never automatically save settings. `--init-config` creates
|
|
62
|
+
a commented starter; `--show-config` inspects effective defaults; `--no-config`
|
|
63
|
+
bypasses saved conversion defaults while keeping credentials available.
|
|
64
|
+
`--show-config` lists conversion settings from the file and command line;
|
|
65
|
+
other options use their API defaults. Compound configuration values use JSON
|
|
66
|
+
arrays of strings. `auth login` explicitly saves shared credentials;
|
|
67
|
+
`auth logout` removes them. Use `help configuration` and `help authentication`
|
|
68
|
+
for paths, precedence, examples, and details.
|
|
69
|
+
|
|
70
|
+
For example:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
pdfcrowd html2pdf --init-config
|
|
74
|
+
# Open the created file and uncomment the settings you want to use.
|
|
75
|
+
pdfcrowd html2pdf --show-config
|
|
76
|
+
pdfcrowd html2pdf help --init-config
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
For scripts, integrations, and AI agents, `pdfcrowd html2pdf help --json`
|
|
80
|
+
describes available options, argument types, defaults, and exit codes as JSON.
|
|
81
|
+
Use `pdfcrowd help --json` for all converters.
|
|
82
|
+
|
|
83
|
+
pipx and uv expose `pdfcrowd` and all eight converter commands. The CLI
|
|
84
|
+
installation includes the compatible SDK automatically.
|
|
85
|
+
|
|
86
|
+
The Python SDK contains only the API clients. All commands are provided by
|
|
87
|
+
`pdfcrowd-cli`, so the SDK and CLI can share a virtual environment:
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
python -m pip install pdfcrowd-cli
|
|
91
|
+
html2pdf --help
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
This public source builds independently of the private generator checkout:
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
python -m pip install .
|
|
98
|
+
make build
|
|
99
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
PYTHON ?= python3
|
|
2
|
+
TWINE ?= twine
|
|
3
|
+
|
|
4
|
+
.PHONY: build dist clean check publish publish-to-testpypi
|
|
5
|
+
|
|
6
|
+
build:
|
|
7
|
+
@$(MAKE) clean
|
|
8
|
+
@$(PYTHON) -m build
|
|
9
|
+
|
|
10
|
+
dist: build
|
|
11
|
+
$(PYTHON) package_download.py
|
|
12
|
+
|
|
13
|
+
check: build
|
|
14
|
+
@$(TWINE) check --strict dist/*
|
|
15
|
+
|
|
16
|
+
publish: check
|
|
17
|
+
@$(TWINE) upload --skip-existing --verbose dist/*
|
|
18
|
+
|
|
19
|
+
publish-to-testpypi: check
|
|
20
|
+
@$(TWINE) upload --repository testpypi --skip-existing --verbose dist/*
|
|
21
|
+
|
|
22
|
+
clean:
|
|
23
|
+
rm -rf build dist *.egg-info src/*.egg-info
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Build the source download from the same independently buildable inputs."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import zipfile
|
|
6
|
+
|
|
7
|
+
root = Path(__file__).resolve().parent
|
|
8
|
+
version = json.loads((root / 'release.json').read_text())['version']
|
|
9
|
+
name = f'pdfcrowd-{version}-cli'
|
|
10
|
+
destination = root / 'dist' / f'{name}.zip'
|
|
11
|
+
excluded = {'dist', 'build', '.git', '__pycache__'}
|
|
12
|
+
with zipfile.ZipFile(destination, 'w', zipfile.ZIP_DEFLATED) as archive:
|
|
13
|
+
for path in sorted(root.rglob('*')):
|
|
14
|
+
relative = path.relative_to(root)
|
|
15
|
+
if (path.is_file() and not any(part in excluded or
|
|
16
|
+
part.endswith('.egg-info') for part in relative.parts)):
|
|
17
|
+
archive.write(path, Path(name) / relative)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from setuptools import find_packages, setup
|
|
5
|
+
|
|
6
|
+
release = json.loads(Path('release.json').read_text())
|
|
7
|
+
setup(
|
|
8
|
+
name='pdfcrowd-cli',
|
|
9
|
+
version=release['version'],
|
|
10
|
+
description='Command-line converters for the PDFCrowd API.',
|
|
11
|
+
long_description=Path('README.md').read_text(),
|
|
12
|
+
long_description_content_type='text/markdown',
|
|
13
|
+
url='https://pdfcrowd.com/api/',
|
|
14
|
+
author='PDFCrowd Team',
|
|
15
|
+
license='MIT',
|
|
16
|
+
python_requires=release['requires_python'],
|
|
17
|
+
package_dir={'': 'src'},
|
|
18
|
+
packages=find_packages('src'),
|
|
19
|
+
package_data={'pdfcrowd_cli': ['command-spec.json']},
|
|
20
|
+
install_requires=[
|
|
21
|
+
f'pdfcrowd>={release["sdk_minimum"]},<{release["sdk_maximum"]}',
|
|
22
|
+
'platformdirs>=4.3.6,<5',
|
|
23
|
+
],
|
|
24
|
+
entry_points={'console_scripts': [
|
|
25
|
+
'pdfcrowd=pdfcrowd_cli.entrypoints:cli_main',
|
|
26
|
+
'html2pdf=pdfcrowd_cli.entrypoints:html2pdf',
|
|
27
|
+
'html2image=pdfcrowd_cli.entrypoints:html2image',
|
|
28
|
+
'image2image=pdfcrowd_cli.entrypoints:image2image',
|
|
29
|
+
'pdf2pdf=pdfcrowd_cli.entrypoints:pdf2pdf',
|
|
30
|
+
'image2pdf=pdfcrowd_cli.entrypoints:image2pdf',
|
|
31
|
+
'pdf2html=pdfcrowd_cli.entrypoints:pdf2html',
|
|
32
|
+
'pdf2text=pdfcrowd_cli.entrypoints:pdf2text',
|
|
33
|
+
'pdf2image=pdfcrowd_cli.entrypoints:pdf2image',
|
|
34
|
+
]},
|
|
35
|
+
)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Copyright (C) 2009-2026 pdfcrowd.com
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person
|
|
4
|
+
# obtaining a copy of this software and associated documentation
|
|
5
|
+
# files (the "Software"), to deal in the Software without
|
|
6
|
+
# restriction, including without limitation the rights to use,
|
|
7
|
+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the
|
|
9
|
+
# Software is furnished to do so, subject to the following
|
|
10
|
+
# conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
"""PDFCrowd command-line application, independent of SDK imports."""
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (C) 2009-2026 pdfcrowd.com
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person
|
|
4
|
+
# obtaining a copy of this software and associated documentation
|
|
5
|
+
# files (the "Software"), to deal in the Software without
|
|
6
|
+
# restriction, including without limitation the rights to use,
|
|
7
|
+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the
|
|
9
|
+
# Software is furnished to do so, subject to the following
|
|
10
|
+
# conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
import sys
|
|
25
|
+
|
|
26
|
+
from .entrypoints import cli_main
|
|
27
|
+
|
|
28
|
+
sys.exit(cli_main())
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Copyright (C) 2009-2026 pdfcrowd.com
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person
|
|
4
|
+
# obtaining a copy of this software and associated documentation
|
|
5
|
+
# files (the "Software"), to deal in the Software without
|
|
6
|
+
# restriction, including without limitation the rights to use,
|
|
7
|
+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the
|
|
9
|
+
# Software is furnished to do so, subject to the following
|
|
10
|
+
# conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
"""Invoke exact SDK bindings, with no parsing or saved-state discovery."""
|
|
25
|
+
|
|
26
|
+
import os
|
|
27
|
+
import re
|
|
28
|
+
import sys
|
|
29
|
+
import tempfile
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
|
|
32
|
+
from .catalog import CLIError
|
|
33
|
+
from .parser import option_value
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def validate_sources(converter, sources):
|
|
37
|
+
if not sources:
|
|
38
|
+
raise CLIError('An input source is required. '
|
|
39
|
+
f'Run {converter["name"]} --help for examples.')
|
|
40
|
+
if converter['name'] == 'pdf2pdf':
|
|
41
|
+
if any(not Path(source).is_file() for source in sources):
|
|
42
|
+
raise CLIError('PDF manipulation requires existing input files.')
|
|
43
|
+
elif len(sources) != 1:
|
|
44
|
+
raise CLIError('This converter requires exactly one input source.')
|
|
45
|
+
elif sources[0] != '-' and not re.match(r'(?i)^https?://', sources[0]):
|
|
46
|
+
if not Path(sources[0]).is_file():
|
|
47
|
+
raise CLIError('Input must be an HTTP(S) URL, an existing file, '
|
|
48
|
+
"or '-' for stdin.")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def service_failure(error):
|
|
52
|
+
status = str(error.getStatusCode())
|
|
53
|
+
code = 3 if status in ('401', '403') else 2 if status == '470' else 4
|
|
54
|
+
return CLIError(str(error), code, prefix='PDFCrowd Error')
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def sdk_module(catalog):
|
|
58
|
+
import pdfcrowd
|
|
59
|
+
version = tuple(int(part) for part in pdfcrowd.__version__.split('.'))
|
|
60
|
+
release = catalog['release']
|
|
61
|
+
minimum = tuple(int(part) for part in release['sdk_minimum'].split('.'))
|
|
62
|
+
maximum = tuple(int(part) for part in release['sdk_maximum'].split('.'))
|
|
63
|
+
if not minimum <= version < maximum:
|
|
64
|
+
raise CLIError('The installed PDFCrowd SDK is incompatible with this '
|
|
65
|
+
'CLI. Reinstall pdfcrowd-cli with its dependencies.', 4)
|
|
66
|
+
return pdfcrowd
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def convert(converter, settings, credentials, sources, destination, catalog,
|
|
70
|
+
output_info=(), invocation_options=()):
|
|
71
|
+
validate_sources(converter, sources)
|
|
72
|
+
# Resolve local values before opening output or contacting the service.
|
|
73
|
+
# Invocation setters also override saved setters sharing the same fields.
|
|
74
|
+
options = sorted(converter['options'], key=lambda option:
|
|
75
|
+
option['name'] in invocation_options)
|
|
76
|
+
calls = []
|
|
77
|
+
for option in options:
|
|
78
|
+
if option['name'] not in settings:
|
|
79
|
+
continue
|
|
80
|
+
values = settings[option['name']]
|
|
81
|
+
values = values if option['repeatable'] else [values]
|
|
82
|
+
for value in values:
|
|
83
|
+
calls.append((option['sdk_method'], option_value(
|
|
84
|
+
option, value, converter['name'])))
|
|
85
|
+
sdk = sdk_module(catalog)
|
|
86
|
+
client = getattr(sdk, converter['sdk_class'])(*credentials)
|
|
87
|
+
|
|
88
|
+
def perform(output):
|
|
89
|
+
client.setClientUserAgent('pdfcrowd_cli_client/1.0.0 (https://pdfcrowd.com)')
|
|
90
|
+
for method, arguments in calls:
|
|
91
|
+
getattr(client, method)(*arguments)
|
|
92
|
+
bindings = converter['input']
|
|
93
|
+
if converter['name'] == 'pdf2pdf':
|
|
94
|
+
for source in sources:
|
|
95
|
+
getattr(client, bindings['add_file'])(source)
|
|
96
|
+
output.write(getattr(client, bindings['convert'])())
|
|
97
|
+
else:
|
|
98
|
+
source = sources[0]
|
|
99
|
+
if source == '-':
|
|
100
|
+
if not sys.stdin.buffer.peek(1):
|
|
101
|
+
raise CLIError('Input from stdin must not be empty.')
|
|
102
|
+
method, argument = bindings['stream'], sys.stdin.buffer
|
|
103
|
+
elif re.match(r'(?i)^https?://', source):
|
|
104
|
+
method, argument = bindings['url'], source
|
|
105
|
+
else:
|
|
106
|
+
method, argument = bindings['file'], source
|
|
107
|
+
# The generated SDK has matching streaming-output variants.
|
|
108
|
+
getattr(client, method + 'ToStream')(argument, output)
|
|
109
|
+
|
|
110
|
+
temporary = None
|
|
111
|
+
try:
|
|
112
|
+
if destination == '-':
|
|
113
|
+
if os.name == 'nt':
|
|
114
|
+
import msvcrt
|
|
115
|
+
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
|
|
116
|
+
perform(sys.stdout.buffer)
|
|
117
|
+
sys.stdout.buffer.flush()
|
|
118
|
+
else:
|
|
119
|
+
target = Path(destination)
|
|
120
|
+
with tempfile.NamedTemporaryFile(
|
|
121
|
+
mode='wb', dir=target.parent, prefix=f'.{target.name}.',
|
|
122
|
+
delete=False) as output:
|
|
123
|
+
temporary = output.name
|
|
124
|
+
perform(output)
|
|
125
|
+
os.replace(temporary, target)
|
|
126
|
+
temporary = None
|
|
127
|
+
except sdk.Error as error:
|
|
128
|
+
raise service_failure(error) from None
|
|
129
|
+
except BrokenPipeError:
|
|
130
|
+
raise
|
|
131
|
+
except (OSError, ValueError):
|
|
132
|
+
raise CLIError('Could not read input or write output. '
|
|
133
|
+
'Check file paths and access permissions.', 4) from None
|
|
134
|
+
finally:
|
|
135
|
+
if temporary is not None:
|
|
136
|
+
try:
|
|
137
|
+
os.unlink(temporary)
|
|
138
|
+
except OSError:
|
|
139
|
+
pass
|
|
140
|
+
|
|
141
|
+
for option in output_info:
|
|
142
|
+
value = getattr(client, option['sdk_method'])()
|
|
143
|
+
print(f'{option["label"]}: {value}', file=sys.stderr)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Copyright (C) 2009-2026 pdfcrowd.com
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person
|
|
4
|
+
# obtaining a copy of this software and associated documentation
|
|
5
|
+
# files (the "Software"), to deal in the Software without
|
|
6
|
+
# restriction, including without limitation the rights to use,
|
|
7
|
+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the
|
|
9
|
+
# Software is furnished to do so, subject to the following
|
|
10
|
+
# conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
"""Load the build-generated command contract without importing the SDK."""
|
|
25
|
+
|
|
26
|
+
import json
|
|
27
|
+
import pkgutil
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def command_options(converter, catalog):
|
|
31
|
+
return catalog['command_options'] + converter.get('output_info', [])
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class CLIError(Exception):
|
|
35
|
+
def __init__(self, message, code=2, prefix='PDFCrowd'):
|
|
36
|
+
super().__init__(message)
|
|
37
|
+
self.code = code
|
|
38
|
+
self.prefix = prefix
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def load_catalog():
|
|
42
|
+
catalog = json.loads(pkgutil.get_data('pdfcrowd_cli', 'command-spec.json'))
|
|
43
|
+
if catalog.get('schema_version') != 1:
|
|
44
|
+
raise CLIError('The CLI help data is incompatible with this '
|
|
45
|
+
'installation. Reinstall pdfcrowd-cli.')
|
|
46
|
+
return catalog
|