Last active
June 20, 2026 13:09
-
-
Save duangsuse/a5bbb3f4d8e217902dc24d78852e0c23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| storage/downloads/a🔒 via 🐍 v3.13.13 | |
| ➜ python a.py | |
| 索引当前文件夹下的PDF文件... | |
| ./老神再在.pdf | |
| P10 ['0', '今夜我看见神的声音'] | |
| P13 ['1', '金钱的秘密'] | |
| P25 ['◆', '感恩是一种能量'] | |
| P26 ['◆', '改变自责和补偿的心态'] | |
| P28 ['◆', '金钱与骄傲'] | |
| P35 ['◆', '体验神'] | |
| P38 ['2', '自我的真相'] | |
| P38 ['◆', '创造的关键'] | |
| P44 ['◆', '我们都是天使'] | |
| P47 ['◆', '梦境的真实性'] | |
| P50 ['3', '宇宙的奥秘'] | |
| P50 ['◆', '《圣经》的秘密'] | |
| P57 ['◆', '死亡的真相'] | |
| P59 ['◆', '创造的秘密'] | |
| P68 ['4', '灵魂的觉醒'] | |
| P72 ['◆', '灵魂的纪律'] | |
| P74 ['◆', '我爱你'] | |
| P75 ['5', '社会的进化'] | |
| P75 ['◆', '领导的关键'] | |
| P77 ['◆', '一体意识'] | |
| P81 ['6', '真爱的定义'] | |
| P81 ['◆', '性的乐章'] | |
| P83 ['◆', '男人女人的战争'] | |
| P88 ['◆', '回家的路'] | |
| P92 ['7', '世间的法则'] | |
| P92 ['◆', '我们都默许黑暗'] | |
| P99 ['◆', '有弹性的因果律'] | |
| P102 ['◆', '轮回是必要的设计'] | |
| P110 ['8', '转变的关键'] | |
| P110 ['◆', '寻找神 VS.认识自己'] | |
| P116 ['9', '工作的意义'] | |
| P119 ['◆', '刚强你的内在,柔软你的态度'] | |
| P124 ['◆', '世间的游戏规则'] | |
| P126 ['◆', '凌驾利益的价值观'] | |
| P129 ['10', '切身的观察'] | |
| P129 ['◆', '真诚的人际关系'] | |
| P133 ['◆', '奇迹没有难易之别'] | |
| > 139 | |
| ./登出键.pdf | |
| ^C | |
| ./扬升书1.pdf | |
| Ignoring wrong pointing object 578 0 (offset 0) | |
| Ignoring wrong pointing object 1312 0 (offset 0) | |
| Annotation sizes differ: 12 vs. 0 | |
| > 3^C | |
| ./与神对话3.pdf | |
| P4 ['1 你教的,正是你必須學的'] | |
| P4 ['2 生命的一切都是S•E•X•'] | |
| P4 ['3 一切都只是視角的問題'] | |
| P4 ['4 生命開始於你們的舒適區域之外'] | |
| P4 ['5 宇宙間沒有意外'] | |
| P4 ['6 人生就象電腦遊戲'] | |
| P4 ['7 我們都是一體'] | |
| P4 ['8 有時候真理就寓含在矛盾中'] | |
| P4 ['9 靈魂之歌可以以許多方式演唱'] | |
| P4 ['10 我愛你'] | |
| P4 ['11 靈魂是身體的容器'] | |
| P4 ['12 每個人都各以各的方式是偉大的人'] | |
| P4 ['13 只有兩顆心才能宣布的事'] | |
| P4 ['14 生命從來沒有開始'] | |
| P4 ['15 你們正在創造神'] | |
| P4 ['16 所有的孩子終有一日全會回家'] | |
| P4 ['17 社會正要變成科技的產品'] | |
| P4 ['18 分享感就是獲利'] | |
| P4 ['19 把每一個人都看作是自己'] | |
| P4 ['20 保密變成了你們的社交密碼'] | |
| P5 ['21 到達那裏的路是―在‖那裏'] | |
| P7 ['1 你教的,正是你必須學的'] | |
| P46 ['2 生命的一切都是S•E•X'] | |
| P63 ['3 一切都只是視角的問題'] | |
| P75 ['4 生命開始於你們的舒適區域之外'] | |
| P95 ['5 宇宙間沒有意外'] | |
| P111 ['6 人生就象電腦遊戲'] | |
| P132 ['7 我們都是一體'] | |
| P147 ['8 有時候真理就寓含在矛盾中'] | |
| P166 ['9 靈魂之歌可以以許多方式演唱'] | |
| P174 ['10 我愛你'] | |
| P174 ['11 靈魂是身體的容器'] | |
| P191 ['12 每個人都以各自的方式是偉大的人'] | |
| P226 ['13 只有兩顆心才能宣布的事'] | |
| P260 ['14 生命從來沒有開始'] | |
| P273 ['15 你們正在創造神'] | |
| P275 ['16 所有的孩子終有一日全會回家'] | |
| P293 ['17 社會正要變成科技的產品'] | |
| P306 ['18 分享感就是獲利'] | |
| P329 ['19 把每一個人都看作是自己'] | |
| P346 ['20 保密成了你們的社交密碼'] | |
| P365 ['21 到達那裏的路是―在‖那裏'] | |
| > 400 | |
| ./与神对话(2).pdf | |
| Ignoring wrong pointing object 7 0 (offset 0) | |
| Ignoring wrong pointing object 12 0 (offset 0) | |
| Ignoring wrong pointing object 15 0 (offset 0) | |
| Ignoring wrong pointing object 23 0 (offset 0) | |
| P18 ['2 我就是那神燈裏的精靈'] | |
| P33 ['3 沒有―時間‖,而―你‖永遠存在'] | |
| P50 ['4 希特勒到天國去了'] | |
| P51 ['2 時間不是一個連續體。那是一種相對論的看法。時間是以―上下‖的范型而存在,許多―時刻‖'] | |
| P58 ['5 你比你想象的要大得多'] | |
| P67 ['6 宇宙,是神的呼吸'] | |
| P71 ['7 愛,愛,去愛那你們想要的東西吧'] | |
| P86 ['8 享受一切,一無所需'] | |
| P98 ['9 你們的教育使世界走向地獄'] | |
| P115 ['10 目前的政治只是滔天大謊'] | |
| P122 ['11 全球軍費每分鍾一百萬美元'] | |
| P131 ['12 愛給予一切,而一無所求'] | |
| P146 ['13 如果不能成為禮物,就不要進入那人的生活中'] | |
| P149 ['14 永遠不要提供削弱他人能力的幫助'] | |
| P150 ['15 我愛你,你知道嗎'] | |
| P150 ['16 社會大革命——收支透明化'] | |
| P160 ['17 世界唯一的希望——全球一國'] | |
| P166 ['18 你們是原始人'] | |
| P179 ['19 從外太空來的生物正在幫助你們'] | |
| P193 ['20 去吧,將你的生命作為真理的表述'] | |
| P203 ['26 Fell Street'] | |
| > 207 | |
| ./与神对话(1).pdf | |
| P9 ['1'] | |
| P52 ['2'] | |
| P60 ['3'] | |
| P72 ['4'] | |
| P77 ['5'] | |
| P85 ['6'] | |
| P89 ['7'] | |
| P97 ['8'] | |
| P116 ['9'] | |
| P125 ['10'] | |
| P125 ['11'] | |
| P132 ['12'] | |
| P145 ['13'] | |
| P157 ['14'] | |
| > 164 | |
| --- 所有文件处理完毕 --- | |
| storage/downloads/a🔒 via 🐍 v3.13.13 took 35s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pathlib import Path | |
| import pdfplumber as Pdf | |
| from pypdf import PdfWriter | |
| import re | |
| TOC = r"^(\d+[\.\d]*|◆)\s+(.{1,15})$" | |
| CtrlF={'*': TOC, '与神对话(1)':r"^(\d{1,2})$", '与神对话': r"^(\d{1,2}\s+.*)$" } | |
| # --- 配置结束 --- 文本高亮 https://v.magiconch.com/epub-transform | |
| # https://t.me/dsuse/22617 | |
| def CtrlB(wr, i, s): | |
| # 创建一个 FitH (Fit Horizontally) 目标,告诉阅读器锚定该页顶端 | |
| wr.add_outline_item( title=s, page_number=i ) | |
| def pdfToC(u: Path): | |
| """ | |
| 扫描整个PDF文件,根据正则表达式查找标题,并使用 pypdf 生成一个新的带书签的PDF。 | |
| """ | |
| # 1. 跳过已生成的文件 | |
| if u.name.startswith("toc_"): return | |
| print(f"\n./{u.name}") | |
| reader = Pdf.open(u) | |
| sel = next((CtrlF[k] for k in CtrlF if u.name.startswith(k)), CtrlF["*"]) | |
| sel = re.compile(sel, re.MULTILINE) | |
| rw = PdfWriter() | |
| rw.append(u.name, import_outline=False) | |
| rw1 = open(u.parent/"lastpage", "w+") | |
| # 2. 遍历每一页,查找匹配的标题,拒绝和页码一样的标题 | |
| rLast='' | |
| for i, page in enumerate(reader.pages): | |
| if not (text := page.extract_text()): continue | |
| print(f'\r> {i}', end='') | |
| pg=str(i+1) | |
| rw1.writelines([f"\n✦ {pg}\n\n", text]); rw1.flush() | |
| for match in sel.finditer(text): | |
| m = [g.strip() for g in match.groups()] | |
| ref = next(reversed(m), "Parens (.+) !!") | |
| if ref==pg or ref==rLast: continue | |
| CtrlB(rw, i, ref); rLast=ref | |
| print(f"\r P{pg} {m}") | |
| with open(u.parent / f"toc_{u.name}", "wb") as f_out: rw.write(f_out) | |
| print("索引当前文件夹下的PDF文件...") | |
| for u in Path.cwd().glob("*.pdf"): | |
| try: pdfToC(u) | |
| except KeyboardInterrupt: pass | |
| print("\n--- 所有文件处理完毕 ---") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment