Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when I try to use extract_words() ,can't get some text #956

Open
fangjiyuan opened this issue Aug 4, 2023 · 6 comments
Open

when I try to use extract_words() ,can't get some text #956

fangjiyuan opened this issue Aug 4, 2023 · 6 comments
Labels

Comments

@fangjiyuan
Copy link

Describe the bug

*when I try to use extract_words() ,can't get some text ,for example then phonenumber *

Have you tried repairing the PDF?

it not work.

PDF file

https __order.crm.hcp.telecom.sd_rest_order_crm_BSS3_prd_receipt_2023_0718_730017088912.pdf

Environment

  • pdfplumber version: [0.10.2]
  • Python version: [3.7.3]
  • OS: [Linux]

Additional context

Add any other context/notes about the problem here.

@fangjiyuan fangjiyuan added the bug label Aug 4, 2023
@cmdlineluser
Copy link

Hi @fangjiyuan - can you perhaps show what should be extracted exactly?

I see one long number in the text:

>>> [ word for word in words if '193' in word['text'] ]
[{'text': '19306498777',
  'x0': 339.75,
  'x1': 389.25,
  'top': 143.61997000000008,
  'doctop': 143.61997000000008,
  'bottom': 152.61997000000008,
  'upright': True,
  'direction': 1}]

But I don't understand the language to know if that is the phone number or not.

@fangjiyuan
Copy link
Author

fangjiyuan commented Aug 4, 2023

i am sorry about that ,i try to save the one of the pdf,may be it change the pdf's format.can u have a look this pdf example .what i want to get is '19306498777'.

https __order.crm.hcp.telecom.sd_rest_order_crm_BSS3_prd_receipt_2023_0718_730017088912.pdf
@cmdlineluser

@cmdlineluser
Copy link

Hm, ok well I don't see a number in this new example:

But the red outlined area seems to be present in .extract_text()?

Screen Shot 2023-08-04 at 17 07 59
>>> print(page.extract_text())
防范打击通讯信息诈骗告知书
为进一步加大防范治理通讯信息诈骗工作力度加强开卡用卡管控特告知如下1.贩卖电话卡是违法行为任何人不得将本人的电话卡转卖转借转租给他人如将号码用于通信诈骗等违法活动依照中华人民共和国刑事诉讼法相关规定公安机关将以帮助信息网络犯罪活动罪严厉处理并纳入失信黑名单同时需承担相
应法律责任2.用户存在以下通信异常疑似诈骗的暂停通信服务:
(1开卡后漫游至电信网络诈骗高危地且通信行为异常的;
(2经他人投诉有诈骗骚扰行为一经核实的;
(3频繁换机插卡或频繁补换卡;
(4公安机关提供的涉案或高风险人员开办的号卡

@fangjiyuan
Copy link
Author

Hm, ok well I don't see a number in this new example:

But the red outlined area seems to be present in .extract_text()?

Screen Shot 2023-08-04 at 17 07 59 ```python >>> print(page.extract_text()) 防范打击通讯信息诈骗告知书 为进一步加大防范、治理通讯信息诈骗工作力度,加强开卡、用卡管控,特告知如下: 1.贩卖电话卡是违法行为,任何人不得将本人的电话卡转卖、转借、转租给他人,如将号码用于通信诈骗等违法活动,依照 《中华人民共和国刑事诉讼法》相关规定,公安机关将以帮助信息网络犯罪活动罪严厉处理,并纳入失信黑名单,同时需承担相 应法律责任。 2.用户存在以下通信异常疑似诈骗的,暂停通信服务: (1)开卡后漫游至电信网络诈骗高危地且通信行为异常的; (2)经他人投诉有诈骗、骚扰行为,一经核实的; (3)频繁换机插卡或频繁补换卡; (4)公安机关提供的涉案或高风险人员开办的号卡。 ```

I can get this text too. But the page 2 of pdf contains phone number can't be find in the red outlined area .
截图_选择区域_20230805091237

@cmdlineluser
Copy link

cmdlineluser commented Aug 5, 2023

Ah okay. So the problem is on page 2 of the updated PDF.

Screen Shot 2023-08-05 at 12 03 47

Yes, I get the same behaviour.

It appears none of the numbers inside the [] are detected.

>>> page2 = pdf.pages[1]
>>> print(page.extract_text())
中国电信号码优享业务协议
甲方用户): (以下简称甲方 中国电信股份有限公司 分公司以下简称乙方鉴于甲乙双方已经签订中国电信用户入网协议》,甲方基于对乙方移动通信服务的了解和需求自愿选择使用乙方的号
码优享业务为维护双方权益根据相关法律法规的规定在平等自愿公平诚实信用的基础上甲乙双方就号码优享业
务及相关事宜达成以下协议共同遵照执行甲方自愿 选择 套餐办理号码优享业务并按照该套餐以及号码优享业务的规则享有相应的权利承担相应的义务就甲方办理的号码优享业务甲方有权使用乙方提供的优享号码[ ], 并承诺接受以下业务规则1. 预存话费甲方于本协议生效之日 预存[ ] 至优享号码的通信费账户该费用仅用于抵扣本协议约定的优享号

That helps with debugging things - thank you.

@jsvine
Copy link
Owner

jsvine commented Aug 8, 2023

FWIW, it seems that the same text is not copy/paste-able from a standard PDF viewer into a plain text editor. I haven't examined the potential cause closely, but this suggests the issue might not be solvable via pdfplumber.

It's possible (but just a guess) that this might be caused by glyph remappings, c.f., #851 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants