前言 獲取pdf目錄 :主要場景是為了拿到目錄信息做編輯,從pdf軟件里面一個個復(fù)制那肯定費時費力。設(shè)置pdf目錄 :主要場景,掃描文件或拍多張照片等制作的pdf文件是沒有目錄。還有就是網(wǎng)上很多掃描版的pdf加上目錄很方便。工具 在網(wǎng)上搜索一波,找到了【pdf-toc】這個命令行工具,可以實現(xiàn)獲取pdf目錄,以及設(shè)置pdf目錄。 感覺很方便,只是需要python >= 3.6的環(huán)境,然后執(zhí)行pip install pdf-toc進行安裝。該命令行的幫助文檔如下:
pdf-toc -husage: pdf-toc [-h] [--version] [--show-toc {json,toc}] [-t TOC] [-d DEST] [-T {json,toc}] [-f] [-m] source pdf ToC modifier. positional arguments: source source pdf file directory optional arguments: -h, --help show this help message and exit --version show program's version number and exit --show-toc {json,toc} print the toc info of the source file and exit -t TOC, --toc TOC toc info used to embed in the result file. leave it empty to read toc from stdin -d DEST, --dest DEST destination directory for result file -T {json,toc}, --type {json,toc} specify format of ToC file. leave it empty to let the tool determine the format, (from file suffix) -f, --force overwrite dist file if it exist -m, --modify modified the original file instead of create a new one
獲取pdf目錄 獲取toc格式目錄 執(zhí)行命令pdf-toc --show-toc toc MongoDB_dst.pdf可以得到簡單的文本目錄格式。 下面只截取部分目錄信息,可以看到結(jié)構(gòu)為【縮進 + 目錄名 + 空格 + 頁碼】,前面的縮進一般為4個空格,為4的倍數(shù)表示第幾級目錄。 該方式適用于得到要修改的目錄,因為后面設(shè)置目錄可以用下面這種格式的文件。
目錄 14第一部分 MongoDB介紹 24 第1章 MongoDB簡介 26 1.1 易于使用 26 1.2 易于擴展 27 1.3 豐富的功能 27 1.4 卓越的性能 28 1.5 小結(jié) 28 第2章 MongoDB基礎(chǔ)知識 30 2.1 文檔 30 2.2 集合 31 2.2.1 動態(tài)模式 31 2.2.2 命名 32 2.3 數(shù)據(jù)庫 33 2.4 啟動MongoDB 34 2.5 MongoDB shell簡介 35
獲取json格式目錄 執(zhí)行命令pdf-toc --show-toc json MongoDB_dst.pdf可以得到簡單的文本目錄格式。 下面只截取部分目錄信息,可以看到結(jié)構(gòu)為【目錄等級 + 目錄名 + 頁碼 + 種類信息】。 該方式得到的數(shù)據(jù)最適合用來寫代碼解析拿去為所欲為。
[ [1, "目錄 ", 14, {"kind": 1, "xref": 0, "page": 13, "to": {"__type__": "Point", "x": 72.0, "y": 0.0}, "zoom": 0.0}], [1, "第一部分 MongoDB介紹 ", 24, {"kind": 1, "xref": 0, "page": 23, "to": {"__type__": "Point", "x": 72.0, "y": 0.0}, "zoom": 0.0}], [2, "第1章 MongoDB簡介 ", 26, {"kind": 1, "xref": 0, "page": 25, "to": {"__type__": "Point", "x": 72.0, "y": 0.0}, "zoom": 0.0}], [3, "1.1 易于使用 ", 26, {"kind": 1, "xref": 0, "page": 25, "to": {"__type__": "Point", "x": 72.0, "y": 0.0}, "zoom": 0.0}], [3, "1.2 易于擴展 ", 27, {"kind": 1, "xref": 0, "page": 26, "to": {"__type__": "Point", "x": 72.0, "y": 0.0}, "zoom": 0.0}], [3, "1.3 豐富的功能 ", 27, {"kind": 1, "xref": 0, "page": 26, "to": {"__type__": "Point", "x": 72.0, "y": 0.0}, "zoom": 0.0}], [3, "1.4 卓越的性能 ", 28, {"kind": 1, "xref": 0, "page": 27, "to": {"__type__": "Point", "x": 72.0, "y": 0.0}, "zoom": 0.0}], [3, "1.5 小結(jié) ", 28, {"kind": 1, "xref": 0, "page": 27, "to": {"__type__": "Point", "x": 72.0, "y": 0.0}, "zoom": 0.0}], [2, "第2章 MongoDB基礎(chǔ)知識 ", 30, {"kind": 1, "xref": 0, "page": 29, "to": {"__type__": "Point", "x": 72.0, "y": 0.0}, "zoom": 0.0}], [3, "2.1 文檔 ", 30, {"kind": 1, "xref": 0, "page": 29, "to": {"__type__": "Point", "x": 72.0, "y": 0.0}, "zoom": 0.0}], [3, "2.2 集合 ", 31, {"kind": 1, "xref": 0, "page": 30, "to": {"__type__": "Point", "x": 72.0, "y": 0.0}, "zoom": 0.0}], [4, "2.2.1 動態(tài)模式 ", 31, {"kind": 1, "xref": 0, "page": 30, "to": {"__type__": "Point", "x": 72.0, "y": 0.0}, "zoom": 0.0}], [4, "2.2.2 命名 ", 32, {"kind": 1, "xref": 0, "page": 31, "to": {"__type__": "Point", "x": 72.0, "y": 0.0}, "zoom": 0.0}]}
設(shè)置pdf目錄 設(shè)置pdf目錄很簡單,需要制作獲取toc格式目錄中得到的那種格式文件。特別注意縮進為4個空格,且文件要為utf-8編碼。 然后執(zhí)行pdf-toc -t MongoDB.txt -d MongoDB_dst.pdf MongoDB_src.pdf就可以得到一個帶目錄的文件MongoDB_dst.pdf,是不是很方便。
結(jié)語 ????本來需求很簡單就是要獲取pdf目錄,百度了好一些Python庫都沒咋看到獲取pdf目錄的現(xiàn)成代碼,我也懶得看那些庫的方法文檔,肯定是有方法的。但是懶驅(qū)動我找到了這個工具,我制作《MongoDB權(quán)威指南(第2版.pdf》的pdf目錄文件還是花了我好多時間,眼睛都快看瞎了,不過為了方便我自己學(xué)習(xí),我還是弄好了。在這里我也把轉(zhuǎn)換前的目錄文件和《MongoDB權(quán)威指南(第2版.pdf》的【下載鏈接:https://545c.com/file/28844697-468213579,解壓密碼:https://www.cnblogs.com/janbar/】放出來,大家自己練習(xí)吧。
總結(jié)
以上是生活随笔 為你收集整理的获取3的倍数_获取和设置pdf目录 的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔 推薦給好友。