python中使用以下代码在pdf中添加注释:
def text_annotation_add(infile, outfile, inword, x1, x2, top, bottom, page_num):
path_infile = infile
path_outfile = outfile
pdfDocument = ap.Document(path_infile)
freeTextAnnotation = ap.annotations.FreeTextAnnotation(pdfDocument.pages[page_num],
ap.Rectangle(x1, top, x2, bottom, False),
ap.annotations.DefaultAppearance())
freeTextAnnotation.title = "User"
# freeTextAnnotation.subject = inword
freeTextAnnotation.contents = inword
# freeTextAnnotation.states = ap.annotations.AnnotationState.ACCEPTED
freeTextAnnotation.flags = ap.annotations.AnnotationFlags.PRINT
freeTextAnnotation.color = ap.Color.red
freeTextAnnotation.text_style.font_name = "黑体"
freeTextAnnotation.text_style.font_size = 20
pdfDocument.pages[page_num].annotations.append(freeTextAnnotation)
pdfDocument.save(path_outfile)
文字信息是有的,但显示不出来。稍微对文字做编辑,显示才能正确。这是什么原因呢?