提取PDF注释/注释

我们有一个非常复杂的打印工作流程,其中控件是使用Adobe Reader或Adobe Acrobat为生成的PDF文档的草稿版本添加注释和注释。 作为工作流程的一部分,应解析带有注释和注释的导入PDF文档,并将注释导入CMS系统(与PDF一起)。

问:有没有可靠的工具(首选Python或Java)以清晰可靠的方式提取PDF文件?

这段代码应该可以胜任。 从PDF文件中解析注释的问题的答案之一对于让我编写下面的代码非常有帮助。 它使用poppler库来解析注释。 这是annotations.pdf的链接。

import poppler, os.path path = 'file://%s' % os.path.realpath('annotations.pdf') doc = poppler.document_new_from_file(path, None) pages = [doc.get_page(i) for i in range(doc.get_n_pages())] for page_no, page in enumerate(pages): items = [i.annot.get_contents() for i in page.get_annot_mapping()] items = [i for i in items if i] print "page: %s comments: %s " % (page_no + 1, items) 

产量

 page: 1 comments: ['This is an annotation'] page: 2 comments: [' Please note ', ' Please note ', 'This is a comment in the text'] 

安装

在Ubuntu上安装如下。

 apt-get install python-poppler