pdf2epub 0.1.2 → 0.1.4
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.
- package/README.md +30 -124
- package/package.json +9 -44
- package/pdf2epub.js +582 -0
- package/LICENSE +0 -22
- package/bin/pdf2epub.js +0 -14
- package/lib/cli.js +0 -134
- package/lib/paths.js +0 -44
- package/lib/python.js +0 -76
- package/lib/setup.js +0 -152
- package/vendor/pdf2epub/LICENSE +0 -9
- package/vendor/pdf2epub/README.md +0 -217
- package/vendor/pdf2epub/UPSTREAM.json +0 -8
- package/vendor/pdf2epub/main.py +0 -118
- package/vendor/pdf2epub/modules/__init__.py +0 -0
- package/vendor/pdf2epub/modules/mark2epub.py +0 -696
- package/vendor/pdf2epub/modules/pdf2md.py +0 -172
- package/vendor/pdf2epub/modules/postprocessing/__init__.py +0 -0
- package/vendor/pdf2epub/modules/postprocessing/prompt.txt +0 -41
- package/vendor/pdf2epub/modules/postprocessing/template.py +0 -177
- package/vendor/pdf2epub/requirements.txt +0 -8
package/README.md
CHANGED
|
@@ -1,141 +1,47 @@
|
|
|
1
|
-
# pdf2epub
|
|
1
|
+
# pdf2epub
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
from the command line with a single `npm i pdf2epub`.
|
|
5
|
-
|
|
6
|
-
pdf2epub converts PDF files to cleanly structured Markdown and EPUB using
|
|
7
|
-
[marker-pdf](https://github.com/datalab-to/marker) for AI layout detection,
|
|
8
|
-
OCR, table and image extraction. The upstream project is written in Python;
|
|
9
|
-
this package bundles a pinned copy of its source and takes care of creating a
|
|
10
|
-
private Python environment for it the first time you run it.
|
|
3
|
+
Convert a PDF into a reflowable EPUB 3 ebook that works on Kindle (via Send-to-Kindle / Calibre), Kobo, Apple Books and other readers.
|
|
11
4
|
|
|
12
5
|
## Install
|
|
13
6
|
|
|
14
7
|
```bash
|
|
15
|
-
npm
|
|
16
|
-
npx pdf2epub --version
|
|
8
|
+
npm install
|
|
17
9
|
```
|
|
18
10
|
|
|
19
|
-
This adds `pdf2epub` to your project; run it with `npx pdf2epub ...` or from an
|
|
20
|
-
npm script. (A global install with `npm i -g pdf2epub` gives you a plain
|
|
21
|
-
`pdf2epub` command instead.)
|
|
22
|
-
|
|
23
|
-
Requirements:
|
|
24
|
-
|
|
25
|
-
- Node.js 18 or newer
|
|
26
|
-
- Either [uv](https://docs.astral.sh/uv/) (recommended; it fetches Python 3.13 by itself)
|
|
27
|
-
or Python 3.10–3.13 on your `PATH` (`python3.13`, `python3.12`, ...).
|
|
28
|
-
- Disk space and a network connection for the first run: PyTorch and marker-pdf
|
|
29
|
-
(several hundred MB) are installed once, and marker-pdf downloads its models
|
|
30
|
-
from Hugging Face the first time it converts a document.
|
|
31
|
-
|
|
32
11
|
## Usage
|
|
33
12
|
|
|
34
13
|
```bash
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
All arguments are passed straight through to upstream's `main.py`:
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
input_path PDF file or directory (default: ./input/*.pdf)
|
|
58
|
-
output_path Output directory (default: directory named after the PDF)
|
|
59
|
-
--max-pages INT Maximum number of pages to process
|
|
60
|
-
--start-page INT Page number to start from (requires --max-pages)
|
|
61
|
-
--skip-epub Only create Markdown; no interactive EPUB prompts
|
|
62
|
-
--skip-md Reuse existing Markdown, only build the EPUB
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
EPUB generation asks for metadata (title, author, language, ...) interactively,
|
|
66
|
-
so it needs a terminal. In scripts and CI use `--skip-epub`, or feed the answers
|
|
67
|
-
on stdin: seven metadata prompts (Enter keeps the default) followed by `n` to
|
|
68
|
-
skip the Markdown review step:
|
|
69
|
-
|
|
70
|
-
```bash
|
|
71
|
-
printf 'My Title\nJane Doe\n\n\n\n\n\nn\n' | npx pdf2epub book.pdf out --skip-md
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Output layout:
|
|
75
|
-
|
|
76
|
-
```
|
|
77
|
-
output_directory/
|
|
78
|
-
└── document_name/
|
|
79
|
-
├── document_name.md
|
|
80
|
-
├── document_name.epub
|
|
81
|
-
├── document_name_metadata.json
|
|
82
|
-
└── images/
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### Wrapper commands
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
npx pdf2epub setup [--force] # create (or recreate) the Python environment now
|
|
89
|
-
npx pdf2epub info # where things live, which Python, which upstream commit
|
|
90
|
-
npx pdf2epub clean # delete the Python environment
|
|
91
|
-
npx pdf2epub --version
|
|
92
|
-
npx pdf2epub help
|
|
93
|
-
npx pdf2epub -- --help # anything after "--" goes to upstream untouched
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### Environment variables
|
|
97
|
-
|
|
98
|
-
| Variable | Purpose | Default |
|
|
99
|
-
| -------------------- | -------------------------------------------------------------------- | -------------- |
|
|
100
|
-
| `PDF2EPUB_HOME` | Directory holding the Python venv and install state | `~/.pdf2epub` |
|
|
101
|
-
| `PDF2EPUB_PYTHON` | Interpreter to use (a path, or a version like `3.12` when using uv) | auto-detected |
|
|
102
|
-
| `PDF2EPUB_INSTALLER` | `auto` (uv if present, else `venv` + `pip`) or `pip` | `auto` |
|
|
103
|
-
| `HF_HOME` | Hugging Face cache where marker-pdf stores its models | HF default |
|
|
104
|
-
| `TORCH_DEVICE` | Force a device for marker-pdf (`cpu`, `cuda`, `mps`) | auto |
|
|
14
|
+
node pdf2epub.js book.pdf # -> book.epub
|
|
15
|
+
node pdf2epub.js book.pdf -o out.epub -t "Title" -a "Author" -l vi
|
|
16
|
+
node pdf2epub.js book.pdf -c cover.jpg # embed a cover image
|
|
17
|
+
node pdf2epub.js book.pdf --split pages --pages-per-chapter 5
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
| Option | Description |
|
|
21
|
+
|---|---|
|
|
22
|
+
| `-o, --output <file>` | Output path (default: input name with `.epub`) |
|
|
23
|
+
| `-t, --title <text>` | Override title (default: PDF metadata, then filename) |
|
|
24
|
+
| `-a, --author <text>` | Override author |
|
|
25
|
+
| `-l, --lang <code>` | Language code, e.g. `en`, `vi` (default `en`) |
|
|
26
|
+
| `-c, --cover <image>` | JPG/PNG cover image to embed |
|
|
27
|
+
| `--split <mode>` | `auto`, `outline` (PDF bookmarks), `headings` (font size), `pages` |
|
|
28
|
+
| `--pages-per-chapter <n>` | Pages per chapter in `pages` mode (default 10) |
|
|
29
|
+
| `--keep-headers` | Keep repeating page headers/footers and page numbers |
|
|
30
|
+
| `--font-scale <n>` | Heading detection threshold relative to body font (default 1.15) |
|
|
105
31
|
|
|
106
32
|
## How it works
|
|
107
33
|
|
|
108
|
-
1.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
3. Every invocation then runs `python main.py <your args>` inside that venv.
|
|
114
|
-
Upgrading the npm package to a version with different requirements or a new
|
|
115
|
-
upstream commit triggers a reinstall automatically.
|
|
116
|
-
|
|
117
|
-
GPU acceleration follows upstream: the default PyTorch wheel supports CUDA on
|
|
118
|
-
Linux/Windows and MPS on Apple Silicon. For ROCm or a specific CUDA build,
|
|
119
|
-
reinstall torch inside the venv (`npx pdf2epub info` shows its location), following
|
|
120
|
-
[pytorch.org/get-started/locally](https://pytorch.org/get-started/locally/).
|
|
34
|
+
1. Extracts positioned text from every page with `pdfjs-dist`.
|
|
35
|
+
2. Rebuilds lines and paragraphs from coordinates, joins wrapped lines and undoes end-of-line hyphenation.
|
|
36
|
+
3. Strips running headers, footers and page numbers that repeat across pages.
|
|
37
|
+
4. Detects headings by font size; splits chapters from PDF bookmarks when present.
|
|
38
|
+
5. Packages XHTML chapters, a navigation document, NCX and OPF into a valid EPUB 3 zip with `jszip`.
|
|
121
39
|
|
|
122
|
-
##
|
|
40
|
+
## Privacy
|
|
123
41
|
|
|
124
|
-
|
|
125
|
-
`transformers<5`. Published advisories for transformers 4.x concern loading
|
|
126
|
-
model files or remote code from untrusted sources; pdf2epub only loads the fixed
|
|
127
|
-
marker-pdf models from Hugging Face. Do not point it at untrusted model
|
|
128
|
-
repositories.
|
|
129
|
-
|
|
130
|
-
## Development
|
|
131
|
-
|
|
132
|
-
```bash
|
|
133
|
-
npm test # fast unit tests (no Python required)
|
|
134
|
-
npm run test:e2e # also builds a real venv and runs upstream --help
|
|
135
|
-
npm run sync-upstream -- v1.1.0 # re-vendor a specific upstream ref
|
|
136
|
-
```
|
|
42
|
+
pdf2epub makes no network requests of its own: it reads your PDF and writes an EPUB, nothing else. (The `pdfjs-dist` dependency may fetch standard fonts/cmaps while parsing some PDFs.)
|
|
137
43
|
|
|
138
|
-
##
|
|
44
|
+
## Limitations
|
|
139
45
|
|
|
140
|
-
|
|
141
|
-
|
|
46
|
+
- Scanned (image-only) PDFs have no text layer. Run OCR first, e.g. `ocrmypdf in.pdf out.pdf`.
|
|
47
|
+
- Images, tables and multi-column layouts are converted to plain text; figures are not embedded.
|
package/package.json
CHANGED
|
@@ -1,52 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf2epub",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
"pdf",
|
|
7
|
-
"epub",
|
|
8
|
-
"markdown",
|
|
9
|
-
"pdf2epub",
|
|
10
|
-
"pdf-to-epub",
|
|
11
|
-
"marker-pdf",
|
|
12
|
-
"ocr",
|
|
13
|
-
"ebook",
|
|
14
|
-
"converter",
|
|
15
|
-
"cli"
|
|
16
|
-
],
|
|
17
|
-
"homepage": "https://github.com/overcuriousity/pdf2epub#readme",
|
|
18
|
-
"bugs": "https://github.com/overcuriousity/pdf2epub/issues",
|
|
19
|
-
"license": "MIT",
|
|
20
|
-
"author": "dalt4sec",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "Convert PDF files to EPUB ebooks",
|
|
5
|
+
"type": "module",
|
|
21
6
|
"bin": {
|
|
22
|
-
"pdf2epub": "
|
|
7
|
+
"pdf2epub": "./pdf2epub.js"
|
|
23
8
|
},
|
|
24
|
-
"files": [
|
|
25
|
-
"bin",
|
|
26
|
-
"lib",
|
|
27
|
-
"vendor",
|
|
28
|
-
"!**/__pycache__",
|
|
29
|
-
"!**/*.pyc",
|
|
30
|
-
"README.md",
|
|
31
|
-
"LICENSE"
|
|
32
|
-
],
|
|
33
9
|
"scripts": {
|
|
34
|
-
"
|
|
35
|
-
"test:e2e": "PDF2EPUB_E2E=1 node --test \"test/*.test.js\"",
|
|
36
|
-
"sync-upstream": "node scripts/sync-upstream.js",
|
|
37
|
-
"prepublishOnly": "npm test"
|
|
38
|
-
},
|
|
39
|
-
"engines": {
|
|
40
|
-
"node": ">=18"
|
|
10
|
+
"start": "node pdf2epub.js"
|
|
41
11
|
},
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"upstream": {
|
|
47
|
-
"repo": "overcuriousity/pdf2epub",
|
|
48
|
-
"ref": "v1.1.0",
|
|
49
|
-
"commit": "5eae669d1c897b4735f369fb2ff4086237db3a81"
|
|
50
|
-
}
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"jszip": "^3.10.1",
|
|
15
|
+
"pdfjs-dist": "^4.10.38"
|
|
51
16
|
}
|
|
52
17
|
}
|