如何测试 popplerqt5 中的注释类型?

how can I test the type of annotation in popplerqt5?

popplerqt5 是 python 的 pdf 渲染库。

注解是来自该库的摘要 class。它有很多子class,比如LinkAnnotation。我如何从注释对象中知道 Subclass?

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.

你必须使用 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()