PyPDF2 Parsing is returning different info than Tika Parser

Viewed 265

I am trying to parse the information off of a PDF file. When i run it through Tika, I get readable text, but I can't figure out how to go page by page to sort the information the way I need to. When I run it through PyPDF2 I am getting correctly formatted information until the main part of the PDF, and that is just a bunch of symbols and stuff.

Here is what Tika is returning with parser.from_file() and then ['content']:

All manufacturer’s names, numbers, symbols and descriptions are used for reference purposes only, and it is not implied that any part listed herein is the 
product of these manufacturers or approved by any of these manufacturers. 
All Prices are subject to change without notice, please confirm all prices before writing an estimate.
C= CAPA Certifited Part Available.        †= Part number may vary. 
N= NSF Certified Part Available

fo
r A

C
U

R
A

 PART  SHOP LIST REPLACES 
 NUMBER DESCRIPTION PRICE PRICE PART NUMBER

1

(about 60 blank lines here I deleted)

 ACIL01A1 Fender rh (13-18)   60210-TX6-A90ZZ
 ACIL01A2 Fender lh (13-18)   60260-TX6-A90ZZ
 ACIL03A1 Fender Liner rh (13-15)   74101-TX6-A01
 ACIL03A2 Fender Liner lh (13-15)   74151-TX6-A01
 ACIL05AA Hood Panel (13-18)   60100-TX6-A92ZZ
C ACIL10AA Grille (13-15)   71121-TX6-A11
C ACIL10AC Grille (16-18) without adaptive cruise control, black   71121-TX6-A51
C ACIL12AA Grille Surround Moulding (13-15)   71122-TX6-A11
C ACIL12AB Grille Surround Moulding (16-18)   71122-TX6-A51

And here is what PyPDF 2 is returning for the same section of the PDF using getPage(0) and then extractText():

All manufacturerÕs names, numbers, symbols and descriptions are used for reference purposes only, and it is not implied that any part listed herein is the 
product of these manufacturers or approved by any of these manufacturers.
 All Prices are subject to change without notice, please con
!rm all prices before writing an estimate.
C= CAPA Certi
!ted Part Available.

€= Part number may vary.
 N= NSF Certi
!ed Part Available
for
 ACURA
 PART
  SHOP LIST REPLACES  NUMBER DESCRIPTION PRICE PRICE PART NUMBER
1                             !"#$%&'"'!()*+),!,-!.'/0'12!!!3&4'&05630"7&88!"#$%&'"4!()*+),!9-!.'/0'12!!!3&43&05630"7&88!"#$%&/"'!()*+),!%:*),!,-!.'/0';2!!!<='&'05630"&'!"#$%&/"4!()*+),!%:*),!9-!.'/0';2!!!<=';'05630"&'!"#$%&;""!>??+!@A*)9!.'/0'12!!!3&'&&05630"7488#!"#$%'&""!B,:99)!.'/0';2!!!<''4'05630"''
#!"#$%'&"#!B,:99)!.'30'12!C:D-?ED!A+AFD:G)!H,E:I)!H?*D,?9J!K9AHL!!!<''4'05630";'
#!"#$%'4""!B,:99)!ME,,?E*+!N?E9+:*O!.'/0';2!!!<''4405630"''
#!"#$%'4"P!B,:99)!ME,,?E*+!N?E9+:*O!.'30'12!!!<''4405630";'
#!"#$%'4"#!B,:99)!N?E9+:*O!.OA,*:I-Q)*D2J!EFF),!.'30'12!!!<''4<05630";&8R
#!"#$%4/""!PEQF),!#?G),J!S,?*D!.'/0';2!FA:*D!D?!QADH-
!!!&=<''05630"7&88

I would like to use pypdf2 because there is much better information and videos explaining how to use it out there, but I can't figure out how to get it to actually decode the text like it does in tika. Anyone know a way I can decode the extracted data from pypdf2?

1 Answers

PyPDF2 text extraction capabilities improved a lot since April 2022. Try the latest version and very likely your issue is gone.

Also don't forget to look for deprecation warnings (e.g. use PdfReader instead of PdfFileReader)

Related