使用 camelot 从 pdf 中提取文本时如何剥离 (CID:)

How to strip (CID:) when using camelot to extract text from pdfs

我正在使用 Camelot 从 pdf 中提取文本。 pdf 还包含汉字,Camelot 为其打印相同的 Cid。例如 (cid:3634)

我想去掉那些 CID,因为汉字对我来说不重要。

我试过这个:

>>> tables = camelot.read_pdf('D:/iolo/1.  Hangcha/1.  FORKLIFTS ELECTRIC/2.  NK15E - 3 WHEEL - NEW-(2014)/copy.pdf',pages='12',strip_text='(cid:[0-9])')

但只删除 CID 帧,不删除其中的数字。

See example Output Image Here 请帮忙

目前,Camelot 参数 strip_text 不支持正则表达式(参见 official repository)。

相反,您可以使用 Pandas replace 方法:

for table in tables:
    table.df.replace(to_replace='\(cid\:[0-9]+\)', value='', inplace=True, regex=True)