0

我正在尝试使用 PDFplumber 从 pdf 文件中提取文本

import pdfplumber
pdf = pdfplumber.open(r"https://www.lupin.com/pdf/financials/subsidiaries/multicare-pharmaceuticals-philippines-inc-philippines-2018.pdf")
for ps in pdf.pages:        
print(ps.extract_text(y_tolerance=20))

但是,我得到的输出如下。它没有拾取确切的文本并返回符号-

 (A WhLolUlyI POnwdMIenNapFerid ecnP nhSad Hun3ebc1Insi,aiLt d 2laAiI a0SnuPr1tdyda8P  itot eIafo mnLNrusde’pE  n2iRnSt0es H1, p o7oIl drNitn Cgs.,  B.V.) 
                    1135 Chino Roces Avenue    , Makati City, Philippines  None None None (SLATU AWPTIhENoMll yPE NOHwTISLn eIOdPF PS FuIINbNsEiAdSiNa, rCIyIN AoCfL L. PuOpiSnI HToIOldNings, B.V.) PDCTDIPRNACnrrreaueuSooeavfsferSnppudeTTehr Enae-enroofercryr tTdttnoeaotaaumaSymdntrllrb    i edrCNeAa tlneer asnuosoe tnxdrnsstslr ath e-eaee tcecAtsnequurssdtsu rre r rsiiAetptpeesyscamnts ertdseeit veiAtnesapstsbo–slesneitetssst–net No21129678t2201es                   PP                  434                 125863           21674007458  0,,,,,,,,,, 2367029366 1 26653629047825231406078 ,,,,,,,,,,, 43521581332  01450564793 M07073790873arc                  h            3                  1         P         P           323                 313732           51359221260  ,,,,,,,,,,1 1685100499 72767656537925485539399,,,,,,,,,,,446553288940724576365308101010455 SDSDTDLCENerIhqueeuoaeAaffuern dTeiNrrBc i-eroetetoiIcrot yt tneaLcau erdantsIlre    pdTrCtLltoaei aIuito atEnaxFretiblr Sthndle iiea L alnApnirbitt caaN piiiLlerbaiDatitlsaii yy elSbEiatstiabQylitlteeUimesIseTnYts  11211214                          PP            444(        134362    7907555  ,,,,,,, 146490647732044012981676,,,,,,,,968737381184639575050575)              PP      332     (    341039    5473266  ,,,,,,, 6692396 2801199  1417594  ,,,,,,, 2033441-32631380406151) 
4

1 回答 1

0

由于y_tolerance. 提取文本时,pdfplumber添加换行符,其中doctop一个字符与下一个字符之间的差异doctop大于y_tolerance。要解决此问题,您可以删除参数,如

for ps in pdf.pages:        
    print(ps.extract_text())

由于右下角的条形码和 PDF 中的项目符号,出现了奇怪的符号。如果您尝试复制任何页面上的条形码,您会得到奇怪的 emoji unicode 字符。如果你不想要它们,你可以简单地替换它们。

于 2021-05-13T13:29:06.570 回答