只需更改包代码中任何不相关的内容即可解决错误

问题描述 投票:0回答:1

我对 python 包“fillpdf”有一个奇怪的问题。 启动spyder并运行代码后:

fields=fillpdfs.get_form_fields(source_pdf)

field1=1
field2=2

fillpdfs.write_fillable_pdf(source_pdf, filled_pdf, fields)

我收到一个特定 PDF 的错误:

AttributeError: 'PdfArray' object has no attribute 'to_bytes'

导致错误的代码行是“raw”的定义:

   def to_unicode(self):
        """ Decode a PDF string to a unicode string.  This is a
            convenience function for user code, in that (as of
            pdfrw 0.3) it is never actually used inside pdfrw.

            There are two Unicode storage methods used -- either
            UTF16_BE, or something called PDFDocEncoding, which
            is defined in the PDF spec.  The determination of
            which decoding method to use is done by examining the
            first two bytes for the byte order marker.
        """
        

        
        raw = self.to_bytes()


        if raw[:2] == self.bytes_bom:
            return raw[2:].decode('utf-16-be')
        else:
            return raw.decode('pdfdocencoding')

但是,如果我只是删除“原始”定义上方的空行或任何其他不相关的更改并保存更改,即使我没有更改代码中的任何操作,我的程序中的错误也不会再发生。 然后我可以运行程序,我的 pdf 会自动填充。

重新启动spyder后,同样的问题:错误,直到我取消包代码中完全不相关的东西,之后就没有问题了。

这怎么可能?

python spyder autofill
1个回答
0
投票

我对这个库也有同样的问题。感谢您提供的信息,我会尝试一下

© www.soinside.com 2019 - 2024. All rights reserved.