0

我遇到了这样的奇怪错误

Expected “xref” keyword or xref stream object (line=9351, col=44, token=‘ilter’)

我正在尝试使用'pdfrw'库通过python在pdf中填写密钥。我想做的是这个

for page in template_pdf.pages:
        annotations = page[ANNOT_KEY]
        if annotations:
            for annotation in annotations:
                if (
                    annotation[SUBTYPE_KEY] == WIDGET_SUBTYPE_KEY
                    and annotation[ANNOT_FIELD_KEY]
                ):
                    key = annotation[ANNOT_FIELD_KEY][1:-1]
                    if key in data_dict.keys():
                        if type(data_dict[key]) is bool:
                            if data_dict[key] is True:
                                annotation.update(
                                    pdfrw.PdfDict(AS=pdfrw.PdfName("Yes"))
                                )
                        else:
                            annotation.update(
                                pdfrw.PdfDict(V="{}".format(data_dict[key]))
                            )
                            annotation.update(pdfrw.PdfDict(AP=""))
            template_pdf.Root.AcroForm.update(
                pdfrw.PdfDict(NeedAppearances=pdfrw.PdfObject("true"))
            )
            name_of_document = "%s.%s" % (
                uuid.uuid4(),
                output_pdf_path.split(".")[-1],
            )
            output_pdf_path = os.path.join("media/uploads", name_of_document)
            pdfrw.PdfWriter().write(output_pdf_path, template_pdf)
            title = input_pdf_path[
                input_pdf_path.rfind("/") + 1 : len(input_pdf_path)
            ]

澄清一下,此代码在本地工作,但在生产中没有

有人能帮助我吗?

4

0 回答 0