You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Diogo Ribeiro <di...@hotmail.com> on 2016/01/16 12:52:00 UTC
Extract text from PDF, wrong sort order
Hi guys,
I'm using PDFBox 1.8.10 to extract some text from a PDF (see attachment).
The output lines are not correctly sorted.
Got:
1/435 S LOPES C�NDIDO FELIX LOPESABEL DIA 27-09-1964
FRANCISCA MARIA DIAS
Was expecting:
1/435 ABEL DIAS LOPES C�NDIDO FELIX LOPES 27-09-1964
FRANCISCA MARIA DIAS
My simple code:
PDDocument pdf = PDDocument.load(new File(FILE_PATH));
PDFTextStripper stripper = new PDFTextStripper();
stripper.setStartPage(1);
stripper.setEndPage(1);
stripper.setSortByPosition(true);
String plainText = stripper.getText(pdf);
System.out.println(plainText);
Thanks in advance.
Re: Extract text from PDF, wrong sort order
Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,
Am 16.01.2016 um 12:52 schrieb Diogo Ribeiro:
> Hi guys,
>
> I'm using PDFBox 1.8.10 to extract some text from a PDF (see attachment).
Your attachment didn't make it due to restcrictions to the mailing list. Please
provide a link to a public download area, e.g. a sharhoster like dropbox or similar.
BR
Andreas
> The output lines are not correctly sorted.
>
> Got:
>
> 1/435 S LOPES CÂNDIDO FELIX LOPESABEL DIA 27-09-1964
> FRANCISCA MARIA DIAS
>
> Was expecting:
>
> 1/435 ABEL DIAS LOPES CÂNDIDO FELIX LOPES 27-09-1964
> FRANCISCA MARIA DIAS
>
> My simple code:
>
> PDDocument pdf = PDDocument.load(new File(FILE_PATH));
>
> PDFTextStripper stripper = new PDFTextStripper();
>
> stripper.setStartPage(1);
> stripper.setEndPage(1);
> stripper.setSortByPosition(true);
>
> String plainText = stripper.getText(pdf);
>
> System.out.println(plainText);
>
>
> Thanks in advance.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Extract text from PDF, wrong sort order
Posted by Tilman Hausherr <TH...@t-online.de>.
Here's what I get with the 2.0 version:
1/435 CÂNDIDO FELIX LOPESABEL DIAS LOPES 27-09-1964
FRANCISCA MARIA DIAS
this is mostly correct. "CÂNDIDO FELIX LOPES" is on a higher line than
"ABEL DIAS LOPES". The only problem is the missing line break, this can
possibly be set with an option.
Assuming you want to extract all this to fill a database, you could also
try the non sorted output. The only problem is to get the correct count
per page.
Tilman
Am 16.01.2016 um 12:52 schrieb Diogo Ribeiro:
> Hi guys,
>
> I'm using PDFBox 1.8.10 to extract some text from a PDF (see attachment).
>
> The output lines are not correctly sorted.
>
> Got:
>
> 1/435 S LOPES CÂNDIDO FELIX LOPESABEL DIA 27-09-1964
> FRANCISCA MARIA DIAS
>
> Was expecting:
>
> 1/435 ABEL DIAS LOPES CÂNDIDO FELIX LOPES 27-09-1964
> FRANCISCA MARIA DIAS
>
> My simple code:
>
> PDDocument pdf = PDDocument.load(new File(FILE_PATH));
>
> PDFTextStripper stripper = new PDFTextStripper();
>
> stripper.setStartPage(1);
> stripper.setEndPage(1);
> stripper.setSortByPosition(true);
>
> String plainText = stripper.getText(pdf);
>
> System.out.println(plainText);
>
>
> Thanks in advance.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Extract text from PDF, wrong sort order
Posted by Gilad Denneboom <gi...@gmail.com>.
The internal structure of a PDF file does not always correspond to the
visual structure you see on the page, or what we would interpret as the
"correct" structure. PDFBox extracts the former, but you can write your own
text parser that will do it differently, such as sort the characters on the
page according to their x,y location. This is not a simple task, though.
On Sat, Jan 16, 2016 at 12:52 PM, Diogo Ribeiro <di...@hotmail.com>
wrote:
> Hi guys,
>
> I'm using PDFBox 1.8.10 to extract some text from a PDF (see attachment).
>
> The output lines are not correctly sorted.
>
> Got:
>
> 1/435 S LOPES CÂNDIDO FELIX LOPESABEL DIA 27-09-1964
> FRANCISCA MARIA DIAS
>
> Was expecting:
>
> 1/435 ABEL DIAS LOPES CÂNDIDO FELIX LOPES 27-09-1964
> FRANCISCA MARIA DIAS
>
> My simple code:
>
> PDDocument pdf = PDDocument.load(new File(FILE_PATH));
>
> PDFTextStripper stripper = new PDFTextStripper();
>
> stripper.setStartPage(1);
> stripper.setEndPage(1);
> stripper.setSortByPosition(true);
>
> String plainText = stripper.getText(pdf);
>
> System.out.println(plainText);
>
>
> Thanks in advance.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>