Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - PDFBox - Text Extraction

Tags:

java

pdfbox

I have been using pdfbox for extracting text information from PDFs. I have succesfully parsed all properties of text such as fontname , fontface , size ,position etc.

PROBLEM: I am using pdfbox1.2.1(latest version). The getCharacter() in TextPosition class returns the full string except the last character. The last character is parsed as a separate string.

Ex: "How are you" is parsed as "How are yo" and "u" (2 separate strings).

I dont want it to happen that way..

Has anybody come accross this? .. Am i doing something wrong??.. Waiting for reply..

Thanks and Regards, Magggi

like image 719
Magggi Avatar asked Oct 14 '22 02:10

Magggi


2 Answers

This issue is solved.

The following code in processEncodedText( byte[] string ) in PDFStreamEngine.java

if( spacingText == 0 && (i + codeLength) < (string.length - 1) )
{
    continue;
}

should be changed to

if( spacingText == 0 && (i + codeLength) < (string.length) )
{
    continue;
}

Regards, Maggi

like image 88
Magggi Avatar answered Oct 16 '22 16:10

Magggi


Yes. This issue is solved by pdfbox.
Try latest version of pdfbox. The latest version can be downloaded from http://pdfbox.apache.org/download.html

like image 38
Neeraj Avatar answered Oct 16 '22 16:10

Neeraj