use*_*057 10 pdf information-retrieval
有没有办法以编程方式从PDF文件中提取突出显示的文本和注释?欢迎任何语言.我找到了几个包含Python,Java和PHP的库,但是没有一个能够完成这项任务.
我不知道是否可能.我也知道有些程序会创建额外的文件来保存这类信息(如果我没有错,Kindle会生成另一个文件.)但目前这些文件超出了范围.
Mar*_*oma 16
要提取突出显示的部分,您可以使用PyMuPDF。以下是使用此 pdf 文件的示例:
直接下载
# Based on https://stackoverflow.com/a/62859169/562769
from typing import List, Tuple
import fitz # install with 'pip install pymupdf'
def _parse_highlight(annot: fitz.Annot, wordlist: List[Tuple[float, float, float, float, str, int, int, int]]) -> str:
points = annot.vertices
quad_count = int(len(points) / 4)
sentences = []
for i in range(quad_count):
# where the highlighted part is
r = fitz.Quad(points[i * 4 : i * 4 + 4]).rect
words = [w for w in wordlist if fitz.Rect(w[:4]).intersects(r)]
sentences.append(" ".join(w[4] for w in words))
sentence = " ".join(sentences)
return sentence
def handle_page(page):
wordlist = page.get_text("words") # list of words on page
wordlist.sort(key=lambda w: (w[3], w[0])) # ascending y, then x
highlights = []
annot = page.first_annot
while annot:
if annot.type[0] == 8:
highlights.append(_parse_highlight(annot, wordlist))
annot = annot.next
return highlights
def main(filepath: str) -> List:
doc = fitz.open(filepath)
highlights = []
for page in doc:
highlights += handle_page(page)
return highlights
if __name__ == "__main__":
print(main("PDF-export-example-with-notes.pdf"))
Run Code Online (Sandbox Code Playgroud)
小智 8
好的,看了之后我找到了一个解决方案,用于将高亮显示的文本从pdf导出到文本文件.不是很难:
首先,使用您想要使用的工具突出显示您的文本(在我的情况下,我在使用Goodreader应用程序在iPad上阅读时突出显示).
将您的pdf转移到计算机并使用Skim打开它(PDF文件阅读器,免费且易于在网上找到)
在文件上,选择CONVERT NOTES并将文档的所有注释转换为SKIM NOTES.
这就是全部:只需转到EXPORT选择EXPORT SKIM NOTES即可.它会导出一个突出显示的文本列表.打开后,此列表可以再次导出为txt格式文件.
没有多少工作要做,结果太棒了.
| 归档时间: |
|
| 查看次数: |
10763 次 |
| 最近记录: |