popplerqt5是python的pdf渲染库。
Annotation是此库中的抽象类。它具有许多子类,例如LinkAnnotation。如何从Annotation对象知道子类?
import popplerqt5 as poppler
import PyQt5
import PyQt5.QtXml
def main():
file = 'file.pdf'
doc = poppler.Poppler.Document.load(file)
annotations = doc.page(1).annotations()
for annotation in annotations:
print (annotation)
# if isinstance(annotation, poppler.LinkAnnotation):
# print ("Link")
if __name__ == "__main__":
main()
这不起作用,未定义LinkAnnotation。我正在使用Python 3。
答案 0 :(得分:0)
您必须使用poppler.Poppler.LinkAnnotation
:
import popplerqt5 as poppler
def main():
file = 'test.pdf'
doc = poppler.Poppler.Document.load(file)
annotations = doc.page(2).annotations()
for annotation in annotations:
if isinstance(annotation, poppler.Poppler.LinkAnnotation):
print ("Link")
if __name__ == "__main__":
main()