我正在使用Adobe Acrobat Pro从XML格式的PDF中提取信息。Acrobat在这方面做得特别好。我想从大约一千个文档中提取信息,并使用这些信息做一些事情,所以手动使用Acrobat会很烦人。有没有插件可以从任何公共语言(理想情况下是Python )调用Acrobat函数(即另存为XML)?
发布于 2012-11-05 07:00:30
也许你可以看看pypdf?它允许python引用Adobe pdf,也允许PDFminer提取pdf xml。我知道perl可以做到这一点,因为我以前也用过它,下面是对模块CAM::PDF的引用
示例:
from pyPdf import PdfFileWriter, PdfFileReader
output = PdfFileWriter()
input1 = PdfFileReader(file("document1.pdf", "rb"))
# print the title of document1.pdf
print "title = %s" % (input1.getDocumentInfo().title)
# add page 1 from input1 to output document, unchanged
output.addPage(input1.getPage(0))
# add page 2 from input1, but rotated clockwise 90 degrees
output.addPage(input1.getPage(1).rotateClockwise(90))
# add page 3 from input1, rotated the other way:
output.addPage(input1.getPage(2).rotateCounterClockwise(90))
# alt: output.addPage(input1.getPage(2).rotateClockwise(270))
# add page 4 from input1, but first add a watermark from another pdf:
page4 = input1.getPage(3)
watermark = PdfFileReader(file("watermark.pdf", "rb"))
page4.mergePage(watermark.getPage(0))
# add page 5 from input1, but crop it to half size:
page5 = input1.getPage(4)
page5.mediaBox.upperRight = (
page5.mediaBox.getUpperRight_x() / 2,
page5.mediaBox.getUpperRight_y() / 2
)
output.addPage(page5)
# print how many pages input1 has:
print "document1.pdf has %s pages." % input1.getNumPages()
# finally, write "output" to document-output.pdf
outputStream = file("document-output.pdf", "wb")
output.write(outputStream)
outputStream.close()另请看这个问题:python and pyPdf - how to extract text from the pages so that there are spaces between lines。描述PDF中的XML解析等。
发布于 2012-11-05 08:20:21
如果您使用的是Windows,则可以使用DDE命令与Acrobat对话。pyWin32模块支持DDE调用,或者您也可以试试this独立绑定。
但您必须弄清楚发送到Acrobat的请求。(here有一些随机的文档,但没有提到XML)。似乎命令在不同版本之间会有所不同,(或者至少有些东西会中断),所以请密切关注版本。祝你好运。
https://stackoverflow.com/questions/13222489
复制相似问题