readpdf-cli 0.1.0__py3-none-any.whl

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.
readpdf.py ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env python3
2
+ """readpdf - Convert PDF to text for token-efficient AI reading"""
3
+
4
+ import argparse
5
+ import subprocess
6
+ import sys
7
+ from pathlib import Path
8
+
9
+
10
+ def main():
11
+ parser = argparse.ArgumentParser(
12
+ description="Convert PDF to text for token-efficient AI agent reading"
13
+ )
14
+ parser.add_argument("pdf", help="PDF file path")
15
+ parser.add_argument("-o", "--output", help="Output text file (default: stdout)")
16
+ parser.add_argument("-p", "--page", type=int, help="Extract specific page only")
17
+ parser.add_argument("--pages", help="Page range, e.g. 3-7", metavar="START-END")
18
+ args = parser.parse_args()
19
+
20
+ pdf_path = Path(args.pdf)
21
+ if not pdf_path.exists():
22
+ print(f"Error: {pdf_path} not found", file=sys.stderr)
23
+ sys.exit(1)
24
+
25
+ cmd = ["pdftotext", "-layout"]
26
+
27
+ if args.page:
28
+ cmd += ["-f", str(args.page), "-l", str(args.page)]
29
+ elif args.pages:
30
+ try:
31
+ start, end = args.pages.split("-")
32
+ cmd += ["-f", start.strip(), "-l", end.strip()]
33
+ except ValueError:
34
+ print("Error: --pages format must be START-END, e.g. 3-7", file=sys.stderr)
35
+ sys.exit(1)
36
+
37
+ if args.output:
38
+ cmd += [str(pdf_path), args.output]
39
+ else:
40
+ cmd += [str(pdf_path), "-"]
41
+
42
+ try:
43
+ result = subprocess.run(cmd, capture_output=True, text=True)
44
+ if result.returncode != 0:
45
+ print(f"Error: {result.stderr}", file=sys.stderr)
46
+ sys.exit(1)
47
+ if not args.output:
48
+ print(result.stdout, end="")
49
+ except FileNotFoundError:
50
+ print(
51
+ "Error: pdftotext not found.\n"
52
+ " macOS: brew install poppler\n"
53
+ " Linux: apt install poppler-utils",
54
+ file=sys.stderr,
55
+ )
56
+ sys.exit(1)
57
+
58
+
59
+ if __name__ == "__main__":
60
+ main()
@@ -0,0 +1,71 @@
1
+ Metadata-Version: 2.4
2
+ Name: readpdf-cli
3
+ Version: 0.1.0
4
+ Summary: Convert PDF to text for token-efficient AI agent reading
5
+ Project-URL: Homepage, https://github.com/xodn348/readpdf
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+
11
+ # readpdf
12
+
13
+ Convert PDFs to text for token-efficient AI agent reading.
14
+
15
+ ## Why
16
+
17
+ Reading PDFs with vision costs 100–500 tokens per page. Converting to text first lets any AI agent read only the sections it needs — saving **up to 90% of tokens**.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ pip install readpdf
23
+ ```
24
+
25
+ Requires `pdftotext`:
26
+ ```bash
27
+ # macOS
28
+ brew install poppler
29
+
30
+ # Linux
31
+ apt install poppler-utils
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ```bash
37
+ # Convert to file, then read selectively
38
+ readpdf paper.pdf -o paper.txt
39
+
40
+ # Extract a single page
41
+ readpdf paper.pdf -o paper.txt -p 3
42
+
43
+ # Extract a page range
44
+ readpdf paper.pdf -o paper.txt --pages 3-7
45
+
46
+ # Print to stdout
47
+ readpdf paper.pdf
48
+ ```
49
+
50
+ Works with any AI agent that has shell access: Claude, GPT-4, Gemini, Cursor, etc.
51
+
52
+ ## How it works
53
+
54
+ ```
55
+ Without readpdf:
56
+ PDF → AI vision → ~200 tokens/page × 30 pages = 6,000 tokens (full doc, every time)
57
+
58
+ With readpdf:
59
+ PDF → pdftotext → paper.txt (on disk, 0 tokens)
60
+ AI reads only offset/limit chunks it needs → ~300 tokens total
61
+ ```
62
+
63
+ **Step 1.** `readpdf paper.pdf -o paper.txt` runs `pdftotext` locally — no AI tokens consumed.
64
+
65
+ **Step 2.** The AI uses a file-reading tool (e.g. Read with `offset`/`limit`) to load only the relevant lines. Because the text file already exists on disk, the AI never pays the cost of processing the entire PDF.
66
+
67
+ **Why not MCP?** MCP tool results return the full content back into the AI's context window — same cost as reading directly. A disk file lets the AI pull exactly the slice it needs, nothing more.
68
+
69
+ ## License
70
+
71
+ MIT
@@ -0,0 +1,6 @@
1
+ readpdf.py,sha256=vkz8m4Gu2VdGrkc4O2bCp0Qt3u2QEh2DgWSyQ8OSO10,1842
2
+ readpdf_cli-0.1.0.dist-info/METADATA,sha256=j_To4Y1I38Pm8NqJXvGzpcD9v7zfXror96YB1gu5jdE,1814
3
+ readpdf_cli-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
4
+ readpdf_cli-0.1.0.dist-info/entry_points.txt,sha256=FRsrAhal_wa5bud0rSofbYsEm-4UWcn6liUzZod4jkU,41
5
+ readpdf_cli-0.1.0.dist-info/licenses/LICENSE,sha256=2pRddN1trfdXxktpmiIzZqgb-PwbONYWD0A-LV1coKY,1068
6
+ readpdf_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ readpdf = readpdf:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Junhyuk Lee
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.