|
1 | 1 | # PDF Metadata Scanner |
2 | 2 |
|
3 | | -A Python tool to recursively scan a folder for PDF files and extract: |
| 3 | +A command-line tool to recursively scan folders for PDF files and extract: |
4 | 4 |
|
5 | 5 | - PDF metadata (Info dictionary via `pikepdf`) |
6 | 6 | - XMP and RDF metadata |
7 | | -- Metadata from embedded images (JPEG, PNG, TIFF — EXIF, text, and other supported fields) |
| 7 | +- Embedded image metadata (JPEG, PNG, TIFF — EXIF, text, and other supported fields) |
8 | 8 |
|
9 | | -### 🛠 Features |
| 9 | +--- |
| 10 | + |
| 11 | +## 🛠 Features |
10 | 12 |
|
11 | | -- Recursive folder scanning |
12 | | -- Clean separation of logs (warnings/errors) and metadata output |
13 | | -- Supports multiple image formats (via Pillow) |
14 | | -- Handles XMP/RDF and embedded image metadata |
| 13 | +- 🔍 Recursive folder scanning |
| 14 | +- 🧼 Clean separation of metadata output and error/warning logs |
| 15 | +- 🖼 Embedded image metadata support via Pillow (JPEG, PNG, TIFF) |
| 16 | +- 📑 XMP/RDF metadata parsing |
| 17 | +- ⚙️ Optional progress bar and verbose logging |
15 | 18 |
|
16 | 19 | --- |
17 | 20 |
|
18 | | -## ✅ Requirements |
| 21 | +## 📦 Installation |
| 22 | + |
| 23 | +Install directly from PyPI: |
19 | 24 |
|
20 | 25 | ```bash |
21 | | -pip install -r requirements.txt |
| 26 | +pip install pdf-metadata-scanner |
22 | 27 | ```` |
23 | 28 |
|
| 29 | +Or from source: |
| 30 | + |
| 31 | +```bash |
| 32 | +git clone https://github.com/yourname/pdf-metadata-scanner.git |
| 33 | +cd pdf-metadata-scanner |
| 34 | +pip install . |
| 35 | +``` |
| 36 | + |
24 | 37 | --- |
25 | 38 |
|
26 | 39 | ## 🚀 Usage |
27 | 40 |
|
| 41 | +After installing: |
| 42 | + |
28 | 43 | ```bash |
29 | | -python scanner.py <folder> [--log LOG_FILE] [--out OUTPUT_FILE] [--verbose] [--progress] |
| 44 | +pdfscan <folder> [--log LOG_FILE] [--out OUTPUT_FILE] [--verbose] [--progress] |
30 | 45 | ``` |
31 | 46 |
|
32 | | -Or if you want to install: |
| 47 | +If running from source without installation: |
33 | 48 |
|
34 | 49 | ```bash |
35 | | -pip install . |
36 | | -pdfscan <folder> [--log LOG_FILE] [--out OUTPUT_FILE] [--verbose] [--progress] |
37 | | -
|
| 50 | +python scanner.py <folder> [--log LOG_FILE] [--out OUTPUT_FILE] [--verbose] [--progress] |
38 | 51 | ``` |
39 | 52 |
|
40 | 53 | ### Arguments: |
41 | 54 |
|
42 | | -| Flag | Description | Default | |
43 | | -| ------------ | -------------------------------------------- | ------------------------- | |
44 | | -| `folder` | Folder to recursively scan for PDFs | *required* | |
45 | | -| `--log` | Log file for warnings/errors | `scanner_warnings.log` | |
46 | | -| `--out` | Output file for extracted metadata | `pdf_metadata_output.txt` | |
47 | | -| `--verbose` | Output logs to both file and console | | |
48 | | -| `--progress` | Show a live progress bar while scanning PDFs | | |
49 | | - |
| 55 | +| Flag | Shorthand | Description | Default | |
| 56 | +| ------------------- | --------- | -------------------------------------------- | ------------------------- | |
| 57 | +| `folder` | | Folder to recursively scan for PDFs | *required* | |
| 58 | +| `--log LOG_FILE` | `-l` | Log file for warnings/errors | `scanner_warnings.log` | |
| 59 | +| `--out OUTPUT_FILE` | `-o` | Output file for extracted metadata | `pdf_metadata_output.txt` | |
| 60 | +| `--verbose` | `-v` | Output logs to both file and console | *(off)* | |
| 61 | +| `--progress` | `-p` | Show a live progress bar while scanning PDFs | *(off)* | |
50 | 62 |
|
51 | 63 | --- |
52 | 64 |
|
53 | 65 | ## 🧾 Example |
54 | 66 |
|
55 | 67 | ```bash |
56 | | -python scanner.py ./documents --log logs.txt --out metadata.txt |
| 68 | +pdfscan ./documents --log logs.txt --out metadata.txt --verbose --progress |
57 | 69 | ``` |
58 | 70 |
|
59 | 71 | * `logs.txt`: Contains only errors or warnings. |
60 | 72 | * `metadata.txt`: Contains all extracted metadata. |
61 | 73 |
|
62 | 74 | --- |
63 | 75 |
|
64 | | -## 📦 Output Structure |
65 | | - |
66 | | -Metadata output (`--out`) includes: |
| 76 | +## 📄 Output Format |
67 | 77 |
|
68 | 78 | ``` |
69 | | -[PDF Metadata] ... |
70 | | - /Author: John Doe |
71 | | - /Title: Sample |
72 | | -[XMP Metadata] ... |
73 | | -[Image Metadata] ... |
74 | | - 306: 2023:12:31 12:34:56 |
75 | | - dpi: (300, 300) |
| 79 | +[PDF Metadata] test.pdf |
| 80 | + /Author: Jane Doe |
| 81 | + /Title: Example Document |
| 82 | +
|
| 83 | +[XMP Metadata] test.pdf |
| 84 | + <dc:title>Example</dc:title> |
| 85 | + <dc:creator>Jane Doe</dc:creator> |
| 86 | +
|
| 87 | +[Image Metadata] test.pdf - Page 1 - Im0 |
| 88 | + DateTimeOriginal: 2024:01:01 12:00:00 |
| 89 | + DPI: (300, 300) |
76 | 90 | ``` |
77 | 91 |
|
78 | 92 | --- |
79 | 93 |
|
80 | | -## 🧪 Unit Testing |
| 94 | +## 🧪 Testing |
81 | 95 |
|
82 | | -This project includes unit tests to ensure core functionality works correctly. |
| 96 | +This project includes unit tests for core functionality. |
83 | 97 |
|
84 | | -### Running Tests |
85 | | - |
86 | | -Make sure you have `unittest` (comes with Python standard library) and the required dependencies installed: |
| 98 | +### Run tests: |
87 | 99 |
|
88 | 100 | ```bash |
89 | 101 | pip install -r requirements-dev.txt |
90 | | -```` |
91 | | -
|
92 | | -To run the tests, execute: |
93 | | -
|
94 | | -```bash |
95 | 102 | python -m unittest test_scanner.py |
96 | 103 | ``` |
97 | 104 |
|
98 | | -### What is Tested? |
99 | | -
|
100 | | -* Extraction of PDF metadata using mocked PDF files |
101 | | -* Parsing of XMP and RDF metadata |
102 | | -* Extraction of image metadata from embedded images (JPEG, PNG) |
103 | | -* Proper handling of non-image PDF objects |
104 | | -
|
105 | | -### Adding Tests |
106 | | -
|
107 | | -Feel free to add more tests in `test_scanner.py` for new features or edge cases. |
| 105 | +--- |
108 | 106 |
|
109 | 107 | ## 🔒 Notes |
110 | 108 |
|
111 | | -* Some image formats in PDFs (e.g. CCITT, JBIG2) are skipped due to incompatibility. |
112 | | -* PNG metadata (text fields) and EXIF from JPEG/TIFF are both supported. |
113 | | -* This tool does not modify the PDFs — it only reads metadata. |
| 109 | +* Some image formats (e.g. CCITT, JBIG2) are skipped due to decoding limitations. |
| 110 | +* PNG and JPEG/TIFF metadata is extracted where available. |
| 111 | +* The tool is read-only — it does **not** modify PDFs. |
114 | 112 |
|
115 | 113 | --- |
116 | 114 |
|
117 | | -## 📃 License |
| 115 | +## 🧾 License |
118 | 116 |
|
119 | 117 | MIT License |
| 118 | + |
0 commit comments