indic-pdf-check 0.2.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.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: indic-pdf-check
3
+ Version: 0.2.0
4
+ Summary: Can a screen reader, search engine or AI read this PDF? Detects scanned and broken text layers in Indian and South/Southeast Asian script PDFs.
5
+ Author-email: Novain Shibu <georgeshibu380@gmail.com>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/novain-shibu/indic-pdf-check
8
+ Project-URL: Research report, https://github.com/novain-shibu/finepdfs-audit
9
+ Keywords: pdf,accessibility,screen reader,indic,unicode,malayalam,hindi,tamil,khmer,myanmar
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Topic :: Text Processing
13
+ Classifier: Intended Audience :: Developers
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: pymupdf>=1.23
18
+ Dynamic: license-file
19
+
20
+ # indic-pdf-check
21
+
22
+ **Can a screen reader, a search engine or an AI read the text of this PDF?**
23
+
24
+ Many PDFs in Indian and other South/Southeast Asian scripts look perfect on screen but carry a broken text layer: copy-paste,
25
+ search, screen readers and AI pipelines get garbled words. Microsoft Word's "Save as PDF" is a common cause (see the
26
+ [research report](https://github.com/novain-shibu/finepdfs-audit)). Others are scans with no text at all. This tool reads a
27
+ PDF's own text layer and tells you which case you have, in a second, on your own computer.
28
+
29
+ **Next steps after `BROKEN`:** recover the text with [Unshape](https://github.com/novain-shibu/unshape); verify that extracted text matches what people see with [SeenRead](https://github.com/novain-shibu/seenread).
30
+
31
+ ```bash
32
+ pip install indic-pdf-check
33
+ indic-pdf-check circular.pdf notice.pdf
34
+ ```
35
+
36
+ ```
37
+ circular.pdf: BROKEN script=Malayalam letters=1994 broken=29.4% tagged=True creator='Microsoft® Word for Microsoft '
38
+ notice.pdf: NO_TEXT script=None letters=0 broken=0.0% tagged=False creator='Canon '
39
+ -- 2 PDFs: BROKEN 1, NO_TEXT 1
40
+ ```
41
+
42
+ | verdict | meaning | what to do |
43
+ |---|---|---|
44
+ | `NO_TEXT` | almost no text at all: usually a scan or an image | run OCR (e.g. OCRmyPDF with Tesseract language packs) before publishing |
45
+ | `INSUFFICIENT_TEXT` | some text in a supported script, but under 200 letters: too little to judge | check by hand (e.g. a short notice) |
46
+ | `UNSUPPORTED_SCRIPT` | plenty of text, but none in a supported script (e.g. English only) | this tool cannot judge it |
47
+ | `BROKEN` | the main script, or any other supported script with 200+ letters, has more than 5% impossible spellings (e.g. a vowel sign or virama with no consonant before it) | re-export with another tool and check again; or recover the text with [Unshape](https://github.com/novain-shibu/unshape) (needs the document's original font) |
48
+ | `OK` | no problem detected by these checks | - (this is not a full accessibility check: reading order, headings, tables and alternative text are not checked) |
49
+
50
+ Pages whose own text has a high share of impossible spellings are listed as `suspicious_pages` (with `--json`), so damage
51
+ confined to some pages or to a second script is visible.
52
+
53
+ Also reported: the script, the share of broken words, whether the PDF is tagged for accessibility, and the program that
54
+ made it. `--json` gives machine-readable output; the exit code is 1 if any file is `NO_TEXT` or `BROKEN` (useful in CI).
55
+
56
+ **Scripts:** Devanagari (Hindi, Marathi, Nepali...), Bengali/Assamese, Gurmukhi, Gujarati, Odia, Tamil, Telugu, Kannada,
57
+ Malayalam, Sinhala, Thai, Lao, Khmer, Myanmar, Thaana (Divehi).
58
+
59
+ **Python:**
60
+ ```python
61
+ from indic_pdf_check import check, check_text
62
+ check("notice.pdf")["verdict"] # 'BROKEN' | 'OK' | 'NO_TEXT' | 'INSUFFICIENT_TEXT' | 'UNSUPPORTED_SCRIPT'
63
+ ```
64
+
65
+ ## How well it works (tested before release)
66
+ - Word for Microsoft 365 PDFs with known-broken text in 14 scripts: 12 flagged `BROKEN`; Kannada was passed as `OK`
67
+ (only 4% impossible spellings although many words are wrong - see limits).
68
+ - Clean source text in the same 14 scripts: 0 false alarms.
69
+ - Microsoft Edge PDFs of the same text are flagged in 3 of 4 scripts: they really do contain doubled vowel signs, which a
70
+ screen reader also reads.
71
+
72
+ ## Limits
73
+ - It finds *impossible* spellings. Garbled text can still be spelled legally (e.g. a wrong consonant), so `OK` means "no
74
+ sign of breakage", not "verified correct".
75
+ - Scripts not listed (Arabic, Hebrew, Latin, Chinese...) come out as `UNSUPPORTED_SCRIPT` (version 0.1.0 said `NO_TEXT`).
76
+ - Version 0.2.0 kept every verdict of the release tests above unchanged; it only splits the old `NO_TEXT` into three
77
+ clearer cases and adds per-script and per-page checks.
78
+ - It reads only the text layer; it does not look at how the page renders.
79
+
80
+ Apache-2.0 · Novain Shibu · [github.com/novain-shibu](https://github.com/novain-shibu)
81
+
82
+ It uses PyMuPDF (installed separately), which is licensed under AGPL-3.0 or a commercial licence from Artifex; using the two
83
+ together is subject to PyMuPDF's licence.
@@ -0,0 +1,64 @@
1
+ # indic-pdf-check
2
+
3
+ **Can a screen reader, a search engine or an AI read the text of this PDF?**
4
+
5
+ Many PDFs in Indian and other South/Southeast Asian scripts look perfect on screen but carry a broken text layer: copy-paste,
6
+ search, screen readers and AI pipelines get garbled words. Microsoft Word's "Save as PDF" is a common cause (see the
7
+ [research report](https://github.com/novain-shibu/finepdfs-audit)). Others are scans with no text at all. This tool reads a
8
+ PDF's own text layer and tells you which case you have, in a second, on your own computer.
9
+
10
+ **Next steps after `BROKEN`:** recover the text with [Unshape](https://github.com/novain-shibu/unshape); verify that extracted text matches what people see with [SeenRead](https://github.com/novain-shibu/seenread).
11
+
12
+ ```bash
13
+ pip install indic-pdf-check
14
+ indic-pdf-check circular.pdf notice.pdf
15
+ ```
16
+
17
+ ```
18
+ circular.pdf: BROKEN script=Malayalam letters=1994 broken=29.4% tagged=True creator='Microsoft® Word for Microsoft '
19
+ notice.pdf: NO_TEXT script=None letters=0 broken=0.0% tagged=False creator='Canon '
20
+ -- 2 PDFs: BROKEN 1, NO_TEXT 1
21
+ ```
22
+
23
+ | verdict | meaning | what to do |
24
+ |---|---|---|
25
+ | `NO_TEXT` | almost no text at all: usually a scan or an image | run OCR (e.g. OCRmyPDF with Tesseract language packs) before publishing |
26
+ | `INSUFFICIENT_TEXT` | some text in a supported script, but under 200 letters: too little to judge | check by hand (e.g. a short notice) |
27
+ | `UNSUPPORTED_SCRIPT` | plenty of text, but none in a supported script (e.g. English only) | this tool cannot judge it |
28
+ | `BROKEN` | the main script, or any other supported script with 200+ letters, has more than 5% impossible spellings (e.g. a vowel sign or virama with no consonant before it) | re-export with another tool and check again; or recover the text with [Unshape](https://github.com/novain-shibu/unshape) (needs the document's original font) |
29
+ | `OK` | no problem detected by these checks | - (this is not a full accessibility check: reading order, headings, tables and alternative text are not checked) |
30
+
31
+ Pages whose own text has a high share of impossible spellings are listed as `suspicious_pages` (with `--json`), so damage
32
+ confined to some pages or to a second script is visible.
33
+
34
+ Also reported: the script, the share of broken words, whether the PDF is tagged for accessibility, and the program that
35
+ made it. `--json` gives machine-readable output; the exit code is 1 if any file is `NO_TEXT` or `BROKEN` (useful in CI).
36
+
37
+ **Scripts:** Devanagari (Hindi, Marathi, Nepali...), Bengali/Assamese, Gurmukhi, Gujarati, Odia, Tamil, Telugu, Kannada,
38
+ Malayalam, Sinhala, Thai, Lao, Khmer, Myanmar, Thaana (Divehi).
39
+
40
+ **Python:**
41
+ ```python
42
+ from indic_pdf_check import check, check_text
43
+ check("notice.pdf")["verdict"] # 'BROKEN' | 'OK' | 'NO_TEXT' | 'INSUFFICIENT_TEXT' | 'UNSUPPORTED_SCRIPT'
44
+ ```
45
+
46
+ ## How well it works (tested before release)
47
+ - Word for Microsoft 365 PDFs with known-broken text in 14 scripts: 12 flagged `BROKEN`; Kannada was passed as `OK`
48
+ (only 4% impossible spellings although many words are wrong - see limits).
49
+ - Clean source text in the same 14 scripts: 0 false alarms.
50
+ - Microsoft Edge PDFs of the same text are flagged in 3 of 4 scripts: they really do contain doubled vowel signs, which a
51
+ screen reader also reads.
52
+
53
+ ## Limits
54
+ - It finds *impossible* spellings. Garbled text can still be spelled legally (e.g. a wrong consonant), so `OK` means "no
55
+ sign of breakage", not "verified correct".
56
+ - Scripts not listed (Arabic, Hebrew, Latin, Chinese...) come out as `UNSUPPORTED_SCRIPT` (version 0.1.0 said `NO_TEXT`).
57
+ - Version 0.2.0 kept every verdict of the release tests above unchanged; it only splits the old `NO_TEXT` into three
58
+ clearer cases and adds per-script and per-page checks.
59
+ - It reads only the text layer; it does not look at how the page renders.
60
+
61
+ Apache-2.0 · Novain Shibu · [github.com/novain-shibu](https://github.com/novain-shibu)
62
+
63
+ It uses PyMuPDF (installed separately), which is licensed under AGPL-3.0 or a commercial licence from Artifex; using the two
64
+ together is subject to PyMuPDF's licence.
@@ -0,0 +1,26 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "indic-pdf-check"
7
+ version = "0.2.0"
8
+ description = "Can a screen reader, search engine or AI read this PDF? Detects scanned and broken text layers in Indian and South/Southeast Asian script PDFs."
9
+ readme = "README.md"
10
+ license = {text = "Apache-2.0"}
11
+ authors = [{name = "Novain Shibu", email = "georgeshibu380@gmail.com"}]
12
+ requires-python = ">=3.9"
13
+ dependencies = ["pymupdf>=1.23"]
14
+ keywords = ["pdf", "accessibility", "screen reader", "indic", "unicode", "malayalam", "hindi", "tamil", "khmer", "myanmar"]
15
+ classifiers = ["Programming Language :: Python :: 3", "License :: OSI Approved :: Apache Software License",
16
+ "Topic :: Text Processing", "Intended Audience :: Developers"]
17
+
18
+ [project.urls]
19
+ Homepage = "https://github.com/novain-shibu/indic-pdf-check"
20
+ "Research report" = "https://github.com/novain-shibu/finepdfs-audit"
21
+
22
+ [project.scripts]
23
+ indic-pdf-check = "indic_pdf_check.cli:main"
24
+
25
+ [tool.setuptools.packages.find]
26
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,95 @@
1
+ """indic-pdf-check: can a screen reader, search engine or AI read the text of this PDF?
2
+
3
+ Many PDFs in Indian and other South/Southeast Asian scripts look correct on screen but carry a broken text layer (for
4
+ example Microsoft Word's "Save as PDF"), or carry no text at all (scans). This tool reads the PDF's own text layer - the
5
+ text that copy-paste, search, screen readers and AI pipelines get - and reports one verdict per PDF:
6
+
7
+ NO_TEXT almost no text at all: usually a scan/image (needs OCR)
8
+ INSUFFICIENT_TEXT some text in a supported script, but too little to judge (under 200 letters)
9
+ UNSUPPORTED_SCRIPT plenty of text, but none in a supported script, so this tool cannot judge it
10
+ BROKEN the main script, or any other supported script with 200+ letters, has more than 5% impossible
11
+ spellings (e.g. a vowel sign or virama with no consonant before it)
12
+ OK no problem detected by these checks (this does not mean "accessible": reading order, headings,
13
+ tables and alternative text are not checked)
14
+ Pages whose own text has a high share of impossible spellings are listed as "suspicious_pages" (for information).
15
+
16
+ Supported scripts: Devanagari, Bengali/Assamese, Gurmukhi, Gujarati, Odia, Tamil, Telugu, Kannada, Malayalam, Sinhala,
17
+ Thai, Lao, Khmer, Myanmar, Thaana. It cannot prove text is *correct* (a garbled text can still be spelled legally); it
18
+ catches the impossible spellings that broken PDF text layers produce. Nothing is uploaded; files are only read.
19
+ """
20
+ from pathlib import Path
21
+ import unicodedata
22
+
23
+ from .rules import BASE, OTHER, scan_text
24
+
25
+ __version__ = "0.2.0"
26
+ SCRIPTS = list(BASE) + list(OTHER)
27
+ NAMES = {"Deva": "Devanagari", "Beng": "Bengali", "Guru": "Gurmukhi", "Gujr": "Gujarati", "Orya": "Odia", "Taml": "Tamil",
28
+ "Telu": "Telugu", "Knda": "Kannada", "Mlym": "Malayalam", "Sinh": "Sinhala", "Thai": "Thai", "Laoo": "Lao",
29
+ "Khmr": "Khmer", "Mymr": "Myanmar", "Thaa": "Thaana"}
30
+
31
+
32
+ def _block(script):
33
+ if script in BASE:
34
+ return BASE[script], BASE[script] + 0x7F
35
+ return OTHER[script][0]
36
+
37
+
38
+ MIN_LETTERS = 200 # below this the text is too short to judge
39
+ NO_TEXT_CHARS = 20 # fewer non-space characters than this in total: treat as no text layer
40
+ PAGE_WORDS = 30 # pages need at least this many words in a script to be listed as suspicious
41
+
42
+
43
+ def _letters(text, script):
44
+ lo, hi = _block(script)
45
+ return sum(1 for c in text if lo <= ord(c) <= hi and unicodedata.category(c)[0] in "LM")
46
+
47
+
48
+ def _script_stats(text):
49
+ """[(script, letters, words, bad)] for every supported script present, most letters first."""
50
+ out = []
51
+ for s in SCRIPTS:
52
+ n = _letters(text, s)
53
+ if n:
54
+ w, b = scan_text(text, s)
55
+ out.append((s, n, w, b))
56
+ return sorted(out, key=lambda t: -t[1])
57
+
58
+
59
+ def check_text(text):
60
+ """Verdict for a text string (the text layer of a PDF)."""
61
+ stats = _script_stats(text)
62
+ script, letters, words, bad = stats[0] if stats else (None, 0, 0, 0)
63
+ share = bad / words if words else 0.0
64
+ others = [(s, b / w) for s, n, w, b in stats[1:] if n >= MIN_LETTERS and w and b / w > 0.05]
65
+ if letters >= MIN_LETTERS:
66
+ verdict = "BROKEN" if share > 0.05 or others else "OK"
67
+ elif letters > 0:
68
+ verdict = "INSUFFICIENT_TEXT"
69
+ elif sum(1 for c in text if not c.isspace()) < NO_TEXT_CHARS:
70
+ verdict = "NO_TEXT"
71
+ else:
72
+ verdict = "UNSUPPORTED_SCRIPT"
73
+ return {"verdict": verdict, "script": NAMES[script] if script else None, "letters": letters, "words": words,
74
+ "broken_share": round(share, 4),
75
+ "other_broken_scripts": [{"script": NAMES[s], "broken_share": round(x, 4)} for s, x in others]}
76
+
77
+
78
+ def check(path):
79
+ """Verdict for a PDF file: dict with verdict, script, letters, words, broken_share, pages, tagged, producer, creator."""
80
+ import pymupdf
81
+ pymupdf.TOOLS.mupdf_display_errors(False)
82
+ doc = pymupdf.open(path)
83
+ pages = [page.get_text() for page in doc]
84
+ r = check_text("".join(pages))
85
+ sus = []
86
+ for i, t in enumerate(pages, 1):
87
+ for s, n, w, b in _script_stats(t):
88
+ if w >= PAGE_WORDS and b / w > 0.05:
89
+ sus.append({"page": i, "script": NAMES[s], "broken_share": round(b / w, 4)})
90
+ r["suspicious_pages"] = sus
91
+ md = doc.metadata or {}
92
+ cat = doc.pdf_catalog()
93
+ r.update({"file": Path(path).name, "pages": len(doc), "tagged": bool(cat and "StructTreeRoot" in doc.xref_object(cat)),
94
+ "producer": md.get("producer", ""), "creator": md.get("creator", "")})
95
+ return r
@@ -0,0 +1,34 @@
1
+ """Command line: indic-pdf-check file1.pdf [file2.pdf ...] [--json]"""
2
+ import collections, json, sys
3
+ from . import __version__, check
4
+
5
+
6
+ def main(argv=None):
7
+ argv = sys.argv[1:] if argv is None else argv
8
+ if not argv or argv[0] in ("-h", "--help"):
9
+ print(__doc__ + "\nVerdicts: NO_TEXT (no text layer, usually a scan), INSUFFICIENT_TEXT (too little text to judge), UNSUPPORTED_SCRIPT, BROKEN (garbled text layer), OK (no problem detected; not a full accessibility check)."); return 0
10
+ if argv[0] == "--version":
11
+ print(__version__); return 0
12
+ as_json = "--json" in argv
13
+ rows = []
14
+ for f in (a for a in argv if a != "--json"):
15
+ try:
16
+ rows.append(check(f))
17
+ except Exception as e:
18
+ rows.append({"file": f, "verdict": "ERROR", "error": repr(e)[:120]})
19
+ if as_json:
20
+ print(json.dumps(rows, ensure_ascii=False, indent=1))
21
+ else:
22
+ for r in rows:
23
+ if r["verdict"] == "ERROR":
24
+ print(f"{r['file']}: ERROR {r['error']}"); continue
25
+ print(f"{r['file']}: {r['verdict']:18s} script={r['script']} letters={r['letters']} broken={r['broken_share']:.1%} "
26
+ f"tagged={r['tagged']} creator={r['creator'][:30]!r}"
27
+ + (f" suspicious_pages={len(r['suspicious_pages'])}" if r.get("suspicious_pages") else ""))
28
+ c = collections.Counter(r["verdict"] for r in rows)
29
+ print(f"-- {len(rows)} PDFs: " + ", ".join(f"{k} {v}" for k, v in c.most_common()))
30
+ return 1 if any(r["verdict"] in ("BROKEN", "NO_TEXT") for r in rows) else 0
31
+
32
+
33
+ if __name__ == "__main__":
34
+ sys.exit(main())
@@ -0,0 +1,119 @@
1
+ """Orthographic validity checker for Brahmic-script text (Devanagari, Bengali, Tamil, Malayalam).
2
+ Scrambled PDF text layers (visual-order vowel signs, ToUnicode lies, dropped glyphs) create sequences that cannot occur in
3
+ correctly spelled Unicode text. Rules (Unicode block offsets are shared across these ISCII-derived blocks):
4
+ R1 dependent vowel sign not preceded by a consonant / nukta (or a vowel sign for the length marks)
5
+ R2 virama not preceded by a consonant / nukta
6
+ R3 candrabindu / anusvara / visarga at the start of a word
7
+ A word = maximal run of characters from the script's block (+ ZWJ/ZWNJ). Metric: share of words with >= 1 violation.
8
+ Usage: python -I validity.py <finepdfs_sample.json> [...] (also checks Wikipedia baselines via --wiki)
9
+ """
10
+ import json, re, sys, statistics, unicodedata
11
+ BASE = {"Deva": 0x0900, "Beng": 0x0980, "Guru": 0x0A00, "Gujr": 0x0A80, "Orya": 0x0B00, "Taml": 0x0B80,
12
+ "Telu": 0x0C00, "Knda": 0x0C80, "Mlym": 0x0D00} # Sinhala (0D80) has a different layout: not covered
13
+
14
+ def classes(base):
15
+ cons = set(range(base + 0x15, base + 0x3A)) | set(range(base + 0x58, base + 0x60))
16
+ if base == 0x0D00:
17
+ cons |= {0x0D3A}
18
+ if base == 0x0B00:
19
+ cons |= {0x0B71}
20
+ if base == 0x0980:
21
+ cons |= {0x09F0, 0x09F1} # Assamese ra / wa (skeptic-style fix: Assamese Wikipedia scored 26% without these)
22
+ dv = set(range(base + 0x3E, base + 0x4D)) | {base + 0x62, base + 0x63}
23
+ length = {base + 0x55, base + 0x56, base + 0x57}
24
+ signs = {base + 0x01, base + 0x02, base + 0x03}
25
+ if base == 0x0B80:
26
+ signs = {0x0B82} # Tamil aytham (U+0B83) is a letter, legal at word start
27
+ viramas, nukta = {base + 0x4D}, base + 0x3C
28
+ if base == 0x0D00: # skeptic fixes: U+0D3B/0D3C are viramas (no nukta in Malayalam); chillus 0D7A-0D7F
29
+ viramas, nukta = {0x0D4D, 0x0D3B, 0x0D3C}, None
30
+ return cons, dv, length, viramas, nukta, signs
31
+
32
+ # Non-ISCII complex scripts: (block range, base letters, marks that must follow a base or another mark, word-start-only bad)
33
+ OTHER = {
34
+ "Thai": ((0x0E00, 0x0E7F), set(range(0x0E01, 0x0E2F)), {0x0E31} | set(range(0x0E34, 0x0E3B)) | set(range(0x0E47, 0x0E4F))),
35
+ "Khmr": ((0x1780, 0x17FF), set(range(0x1780, 0x17B4)), set(range(0x17B6, 0x17D4))),
36
+ "Sinh": ((0x0D80, 0x0DFF), set(range(0x0D85, 0x0DC7)), set(range(0x0DCA, 0x0DE0)) | {0x0DF2, 0x0DF3, 0x0D82, 0x0D83}),
37
+ "Mymr": ((0x1000, 0x109F), set(range(0x1000, 0x102B)) | set(range(0x103F, 0x1056)), set(range(0x102B, 0x103F)) | set(range(0x1056, 0x105A))),
38
+ "Laoo": ((0x0E80, 0x0EFF), set(range(0x0E81, 0x0EB1)) | {0x0EB2, 0x0EB3} | set(range(0x0EDC, 0x0EE0)), {0x0EB1} | set(range(0x0EB4, 0x0EBD)) | set(range(0x0EC8, 0x0ECE))),
39
+ "Thaa": ((0x0780, 0x07BF), set(range(0x0780, 0x07A6)) | {0x07B1}, set(range(0x07A6, 0x07B1))),
40
+ }
41
+ PUA_THAI = set(range(0xF700, 0xF71B)) # legacy Thai font glyph-variant code points leaking into text = broken text layer
42
+
43
+
44
+ def other_word_ok(w, script):
45
+ (lo, hi), base, marks = OTHER[script]
46
+ cps = [ord(c) for c in w if c not in "‌‍"]
47
+ for i, c in enumerate(cps):
48
+ if c in PUA_THAI:
49
+ return False
50
+ if c in marks:
51
+ if i == 0:
52
+ return False
53
+ p = cps[i - 1]
54
+ if p not in base and p not in marks:
55
+ return False
56
+ return True
57
+
58
+
59
+ def scan_other(text, script, collect=None):
60
+ text = unicodedata.normalize("NFC", text)
61
+ (lo, hi), base, marks = OTHER[script]
62
+ words = re.findall(f"[\\u{lo:04x}-\\u{hi:04x}\\u200c\\u200d\\uf700-\\uf71a]+", text)
63
+ words = [w for w in words if any(lo <= ord(c) <= hi for c in w)]
64
+ badw = [w for w in words if not other_word_ok(w, script)]
65
+ if collect is not None:
66
+ collect.extend(badw)
67
+ return len(words), len(badw)
68
+
69
+
70
+ def word_ok(w, cl):
71
+ cons, dv, length, viramas, nukta, signs = cl
72
+ cps = [ord(c) for c in w if c not in "‌‍"]
73
+ mal = 0x0D4D in viramas
74
+ for i, c in enumerate(cps):
75
+ prev = cps[i - 1] if i else None
76
+ if c in dv and prev not in cons and not (nukta is not None and prev == nukta):
77
+ return False
78
+ if c in length and prev not in dv and prev not in cons:
79
+ return False
80
+ if c in viramas and prev not in cons and not (nukta is not None and prev == nukta):
81
+ # Malayalam: chillu + virama (nta form) and samvruthokaram (u-sign + virama) are standard spellings
82
+ if not (mal and prev is not None and (0x0D7A <= prev <= 0x0D7F or prev == 0x0D41)):
83
+ return False
84
+ if c in signs and i == 0:
85
+ return False
86
+ return True
87
+
88
+ def scan_text(text, script, collect=None):
89
+ if script in OTHER:
90
+ return scan_other(text, script, collect)
91
+ text = unicodedata.normalize("NFC", text)
92
+ base = BASE[script]
93
+ cl = classes(base)
94
+ words = re.findall(f"[\\u{base:04x}-\\u{base + 0x7F:04x}\\u200c\\u200d]+", text)
95
+ words = [w for w in words if any(base <= ord(c) <= base + 0x7F for c in w)]
96
+ badw = [w for w in words if not word_ok(w, cl)]
97
+ if collect is not None:
98
+ collect.extend(badw)
99
+ return len(words), len(badw)
100
+
101
+ def report(name, docs, script):
102
+ W = B = 0; per = []
103
+ for t in docs:
104
+ w, b = scan_text(t, script)
105
+ W += w; B += b
106
+ if w >= 50:
107
+ per.append(b / w)
108
+ over = sum(p > 0.05 for p in per)
109
+ print(f"{name:28s} docs {len(docs):4d} | words {W:8d} | invalid {B:7d} = {B / max(W, 1):6.2%} | "
110
+ f"docs(>=50 words) with >5% invalid: {over}/{len(per)}"
111
+ + (f" | median doc {statistics.median(per):.2%}" if per else ""))
112
+ return per
113
+
114
+ if __name__ == "__main__":
115
+ for path in sys.argv[1:]:
116
+ script = re.search(r"_(" + "|".join(list(BASE) + list(OTHER)) + ")", path).group(1)
117
+ data = json.load(open(path, encoding="utf-8"))
118
+ docs = [d["text"] if isinstance(d, dict) else d for d in data]
119
+ report(path.split("/")[-1].split("\\")[-1], docs, script)
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: indic-pdf-check
3
+ Version: 0.2.0
4
+ Summary: Can a screen reader, search engine or AI read this PDF? Detects scanned and broken text layers in Indian and South/Southeast Asian script PDFs.
5
+ Author-email: Novain Shibu <georgeshibu380@gmail.com>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/novain-shibu/indic-pdf-check
8
+ Project-URL: Research report, https://github.com/novain-shibu/finepdfs-audit
9
+ Keywords: pdf,accessibility,screen reader,indic,unicode,malayalam,hindi,tamil,khmer,myanmar
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Topic :: Text Processing
13
+ Classifier: Intended Audience :: Developers
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: pymupdf>=1.23
18
+ Dynamic: license-file
19
+
20
+ # indic-pdf-check
21
+
22
+ **Can a screen reader, a search engine or an AI read the text of this PDF?**
23
+
24
+ Many PDFs in Indian and other South/Southeast Asian scripts look perfect on screen but carry a broken text layer: copy-paste,
25
+ search, screen readers and AI pipelines get garbled words. Microsoft Word's "Save as PDF" is a common cause (see the
26
+ [research report](https://github.com/novain-shibu/finepdfs-audit)). Others are scans with no text at all. This tool reads a
27
+ PDF's own text layer and tells you which case you have, in a second, on your own computer.
28
+
29
+ **Next steps after `BROKEN`:** recover the text with [Unshape](https://github.com/novain-shibu/unshape); verify that extracted text matches what people see with [SeenRead](https://github.com/novain-shibu/seenread).
30
+
31
+ ```bash
32
+ pip install indic-pdf-check
33
+ indic-pdf-check circular.pdf notice.pdf
34
+ ```
35
+
36
+ ```
37
+ circular.pdf: BROKEN script=Malayalam letters=1994 broken=29.4% tagged=True creator='Microsoft® Word for Microsoft '
38
+ notice.pdf: NO_TEXT script=None letters=0 broken=0.0% tagged=False creator='Canon '
39
+ -- 2 PDFs: BROKEN 1, NO_TEXT 1
40
+ ```
41
+
42
+ | verdict | meaning | what to do |
43
+ |---|---|---|
44
+ | `NO_TEXT` | almost no text at all: usually a scan or an image | run OCR (e.g. OCRmyPDF with Tesseract language packs) before publishing |
45
+ | `INSUFFICIENT_TEXT` | some text in a supported script, but under 200 letters: too little to judge | check by hand (e.g. a short notice) |
46
+ | `UNSUPPORTED_SCRIPT` | plenty of text, but none in a supported script (e.g. English only) | this tool cannot judge it |
47
+ | `BROKEN` | the main script, or any other supported script with 200+ letters, has more than 5% impossible spellings (e.g. a vowel sign or virama with no consonant before it) | re-export with another tool and check again; or recover the text with [Unshape](https://github.com/novain-shibu/unshape) (needs the document's original font) |
48
+ | `OK` | no problem detected by these checks | - (this is not a full accessibility check: reading order, headings, tables and alternative text are not checked) |
49
+
50
+ Pages whose own text has a high share of impossible spellings are listed as `suspicious_pages` (with `--json`), so damage
51
+ confined to some pages or to a second script is visible.
52
+
53
+ Also reported: the script, the share of broken words, whether the PDF is tagged for accessibility, and the program that
54
+ made it. `--json` gives machine-readable output; the exit code is 1 if any file is `NO_TEXT` or `BROKEN` (useful in CI).
55
+
56
+ **Scripts:** Devanagari (Hindi, Marathi, Nepali...), Bengali/Assamese, Gurmukhi, Gujarati, Odia, Tamil, Telugu, Kannada,
57
+ Malayalam, Sinhala, Thai, Lao, Khmer, Myanmar, Thaana (Divehi).
58
+
59
+ **Python:**
60
+ ```python
61
+ from indic_pdf_check import check, check_text
62
+ check("notice.pdf")["verdict"] # 'BROKEN' | 'OK' | 'NO_TEXT' | 'INSUFFICIENT_TEXT' | 'UNSUPPORTED_SCRIPT'
63
+ ```
64
+
65
+ ## How well it works (tested before release)
66
+ - Word for Microsoft 365 PDFs with known-broken text in 14 scripts: 12 flagged `BROKEN`; Kannada was passed as `OK`
67
+ (only 4% impossible spellings although many words are wrong - see limits).
68
+ - Clean source text in the same 14 scripts: 0 false alarms.
69
+ - Microsoft Edge PDFs of the same text are flagged in 3 of 4 scripts: they really do contain doubled vowel signs, which a
70
+ screen reader also reads.
71
+
72
+ ## Limits
73
+ - It finds *impossible* spellings. Garbled text can still be spelled legally (e.g. a wrong consonant), so `OK` means "no
74
+ sign of breakage", not "verified correct".
75
+ - Scripts not listed (Arabic, Hebrew, Latin, Chinese...) come out as `UNSUPPORTED_SCRIPT` (version 0.1.0 said `NO_TEXT`).
76
+ - Version 0.2.0 kept every verdict of the release tests above unchanged; it only splits the old `NO_TEXT` into three
77
+ clearer cases and adds per-script and per-page checks.
78
+ - It reads only the text layer; it does not look at how the page renders.
79
+
80
+ Apache-2.0 · Novain Shibu · [github.com/novain-shibu](https://github.com/novain-shibu)
81
+
82
+ It uses PyMuPDF (installed separately), which is licensed under AGPL-3.0 or a commercial licence from Artifex; using the two
83
+ together is subject to PyMuPDF's licence.
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/indic_pdf_check/__init__.py
5
+ src/indic_pdf_check/cli.py
6
+ src/indic_pdf_check/rules.py
7
+ src/indic_pdf_check.egg-info/PKG-INFO
8
+ src/indic_pdf_check.egg-info/SOURCES.txt
9
+ src/indic_pdf_check.egg-info/dependency_links.txt
10
+ src/indic_pdf_check.egg-info/entry_points.txt
11
+ src/indic_pdf_check.egg-info/requires.txt
12
+ src/indic_pdf_check.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ indic-pdf-check = indic_pdf_check.cli:main
@@ -0,0 +1 @@
1
+ pymupdf>=1.23
@@ -0,0 +1 @@
1
+ indic_pdf_check