You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Pierre Dubillot <al...@gmail.com> on 2015/07/20 11:30:28 UTC
Extraction problems with PDFTextStripperByArea
Hi,
I'm about to finalize my project (which will extract areas of text), but,
here's my problem :
I've got a document (
http://www.cinemas-utopia.org/admin/grilles/toulouse/2015-07-21.pdf).
Then, I split it into 7 pages (
http://www.docdroid.net/FedKhgp/2cac3a9c-b654-41c3-aea2-b473ccbeb06b.pdf.html
).
In a XML file, I define which areas i've to extract. (For example : the
current date of the page).
I create my objects ... Then I process extraction, but it only extracts the
last page :
"[MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2]" (A
list of the result after 7 pages extracted).
I've to explain my code a little bit. First, I did a local app using 1.8.9,
then I switched to a Web App and used 2.0.0, so, I changed my code a little
bit, and everything seems to stop working.
There are 3 main objects to process extraction : Line or Column and Cell. A
line/column can contain cells.
public Cell(String zoneName, double x, double y, int largeur, int hauteur)
> throws IOException {
> super();
> [this ...]
> uneCellule = new PDFTextStripperByArea();
> uneCellule.addRegion(nomZone, new Rectangle2D.Double(x, y, largeur,
> hauteur));
> }
>
And, for example, a column will create attached cells.
public Colonne(
> int index,
> String columnName,
> double x,
> double y,double hauteurCellule, double hauteurColonne, double
> largeurColonne, double decalage) throws IOException
> {
> [...]
> for(double i = y; i < (hauteurColonne + y); i+=(hauteurCellule+decalage)){
> cells.add(
> new Cell(
> nameOfCells.get(compteur),
> x,
> i,
> (int) largeurColonne,
> (int) hauteurCellule
> )
> );
> compteur++;
> }
> }
And my code to extract text (in my column object) :
>
> public ArrayList<String> scanCells(PDPage page) throws IOException{
> ArrayList<String> columnData= new ArrayList<String>();
> for(Cell cell: cells){
> cell.extractRegion(page);
> try {
> columnData.add(getTextOfCell(cell));
> } catch (ParseException e) {
> e.printStackTrace();
> }
> }
> return columnData;
> }
My documents are correctly loaded, each page is inside memory, I can't find
on my own how to solve this, it's a strange problem. If you have any idea
(how I could update my code)..
Thanks,
Re: Extraction problems with PDFTextStripperByArea
Posted by Tilman Hausherr <TH...@t-online.de>.
Am 24.07.2015 um 10:38 schrieb Pierre Dubillot:
> Hi,
> I've got greats news. That was exactly what you were telling. The
> LowerLeftY was not set at 0, so, the mediabox was broken..
> I spent around 1 week to solve this problem, your help is really
> appreciated !
Glad it works! Although I'm wondering why extract from the splitted file
instead of from the original file (which are identical except for the
different media box). Did you really need both, i.e. both the "split in
7 pages" thing and the text extraction? I hope that I / we didn't
somehow accidentally made you do uneeded work.
Tilman
>
> Best regards,
> Pierre
>
> 2015-07-23 21:38 GMT+02:00 Tilman Hausherr <TH...@t-online.de>:
>
>> I ran the ExtractText command utility. In the original PDF, CAVANNA
>> appears once on each day, so 7 times at all. In the "new" file, when
>> extracting all, it appears 49 times.
>>
>> This suggests that the text extraction logic doesn't bother about the
>> cropbox / mediabox / whatever. Hard to tell whether this is OK or not.
>>
>> It would be nice if you could upload the extract code.
>>
>> Can you try to change your extract code so that it uses the changing "y"
>> value (probably getLowerLeftY() ) of the media box (PDPage.getMediaBox())
>> in each page?
>>
>>
>> Tilman
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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: Extraction problems with PDFTextStripperByArea
Posted by Pierre Dubillot <al...@gmail.com>.
Hi,
I've got greats news. That was exactly what you were telling. The
LowerLeftY was not set at 0, so, the mediabox was broken..
I spent around 1 week to solve this problem, your help is really
appreciated !
Best regards,
Pierre
2015-07-23 21:38 GMT+02:00 Tilman Hausherr <TH...@t-online.de>:
> I ran the ExtractText command utility. In the original PDF, CAVANNA
> appears once on each day, so 7 times at all. In the "new" file, when
> extracting all, it appears 49 times.
>
> This suggests that the text extraction logic doesn't bother about the
> cropbox / mediabox / whatever. Hard to tell whether this is OK or not.
>
> It would be nice if you could upload the extract code.
>
> Can you try to change your extract code so that it uses the changing "y"
> value (probably getLowerLeftY() ) of the media box (PDPage.getMediaBox())
> in each page?
>
>
> Tilman
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
Re: Extraction problems with PDFTextStripperByArea
Posted by Tilman Hausherr <TH...@t-online.de>.
I ran the ExtractText command utility. In the original PDF, CAVANNA
appears once on each day, so 7 times at all. In the "new" file, when
extracting all, it appears 49 times.
This suggests that the text extraction logic doesn't bother about the
cropbox / mediabox / whatever. Hard to tell whether this is OK or not.
It would be nice if you could upload the extract code.
Can you try to change your extract code so that it uses the changing "y"
value (probably getLowerLeftY() ) of the media box
(PDPage.getMediaBox()) in each page?
Tilman
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Extraction problems with PDFTextStripperByArea
Posted by Tilman Hausherr <TH...@t-online.de>.
Am 23.07.2015 um 20:03 schrieb Pierre Dubillot:
> If you are talking about the text extractor, it's realy strange, because on
> each page, column and lines are with the same position..
> Or is it the mediabox x/y positions ?
Sorry, ignore what I've written. I need to think more.
Tilman
> Le 23 juil. 2015 6:11 PM, "Tilman Hausherr" <TH...@t-online.de> a
> écrit :
>
>> Am 23.07.2015 um 11:17 schrieb Pierre Dubillot:
>>
>>> http://pastebin.com/txLgqb7R
>>>
>>> Here's what I do to split my original page. But, I don't know what I
>>> should
>>> update for the mediabox...
>>>
>>>
>> I think that the problem isn't the media box, but the coordinates you use.
>> The mediabox is different because you use it as a "window" on a huge page.
>>
>> Tilman
>>
>> ---------------------------------------------------------------------
>> 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: Extraction problems with PDFTextStripperByArea
Posted by Pierre Dubillot <al...@gmail.com>.
If you are talking about the text extractor, it's realy strange, because on
each page, column and lines are with the same position..
Or is it the mediabox x/y positions ?
Le 23 juil. 2015 6:11 PM, "Tilman Hausherr" <TH...@t-online.de> a
écrit :
> Am 23.07.2015 um 11:17 schrieb Pierre Dubillot:
>
>> http://pastebin.com/txLgqb7R
>>
>> Here's what I do to split my original page. But, I don't know what I
>> should
>> update for the mediabox...
>>
>>
>
> I think that the problem isn't the media box, but the coordinates you use.
> The mediabox is different because you use it as a "window" on a huge page.
>
> Tilman
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
Re: Extraction problems with PDFTextStripperByArea
Posted by Tilman Hausherr <TH...@t-online.de>.
Am 23.07.2015 um 11:17 schrieb Pierre Dubillot:
> http://pastebin.com/txLgqb7R
>
> Here's what I do to split my original page. But, I don't know what I should
> update for the mediabox...
>
I think that the problem isn't the media box, but the coordinates you
use. The mediabox is different because you use it as a "window" on a
huge page.
Tilman
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Extraction problems with PDFTextStripperByArea
Posted by Pierre Dubillot <al...@gmail.com>.
http://pastebin.com/txLgqb7R
Here's what I do to split my original page. But, I don't know what I should
update for the mediabox...
Re: Extraction problems with PDFTextStripperByArea
Posted by Pierre Dubillot <al...@gmail.com>.
Hi, i'm still having the same issue, do you need more details ?
Best regards,
Pierre
2015-07-20 18:05 GMT+02:00 Pierre Dubillot <al...@gmail.com>:
> Yes, the method is called over another algorithm, which loops over each
> page, and also with a different page number.
>
> Console output :
>
>> Page : 0 -
>> [MARJUIN2]
>> Page : 1 -
>> [MARJUIN2]
>> Page : 2 -
>> [MARJUIN2]
>> Page : 3 -
>> [MARJUIN2]
>> Page : 4 -
>> [MARJUIN2]
>> Page : 5 -
>> [MARJUIN2]
>> Page : 6 -
>> [MARJUIN2]
>
>
> But, that should be :
>
>> [MERMAI27]
>> [...]
>> [MARJUIN2]
>
>
>
>
> 2015-07-20 17:58 GMT+02:00 Gilad Denneboom <gi...@gmail.com>:
>
>> So are you calling this method each time with a different page number?
>> What is the output to the console?
>>
>> On Mon, Jul 20, 2015 at 5:37 PM, Pierre Dubillot <al...@gmail.com>
>> wrote:
>>
>> > I did a short example with the same problem :
>> >
>> >
>> > PDFTextStripperByArea cellules;
>> > >
>> > public ArrayList<String> scanCells(PDDocument pdf, int pagenum) throws
>> > >> IOException{
>> > >
>> > > ArrayList<String> columnData = new ArrayList<String>();
>> > >
>> > > cellules.extractRegions(pdf.getPage(pagenum));
>> > >
>> > > cellules.setStartPage(pagenum);
>> > >
>> > > System.out.println("Page : " + cellules.getStartPage() + " - " +
>> > >> cellules.getEndPage());
>> > >
>> > > cellules.setSortByPosition(true);
>> > >
>> > > for(String region : cellules.getRegions()){
>> > >
>> > > // PDDocument pdoc = new PDDocument();
>> > >
>> > > // pdoc.addPage(page);
>> > >
>> > > // pdoc.save(new File("D:/Stage_DUT/pdfs/testing/" + region +
>> ".pdf"));
>> > >
>> > > // pdoc.close();
>> > >
>> > > // System.out.println(cellules.getTextForRegion(region));
>> > >
>> > > columnData.add(cellules.getTextForRegion(region));
>> > >
>> > > System.out.println(columnData);
>> > >
>> > > }
>> > >
>> > > return columnData;
>> > >
>> > > }
>> > >
>> > >
>> > Each region name is different (0page0, 0page1, 0page2, etc .. '0' is the
>> > column number for the current page.) , and the method is called inside
>> the
>> > column object (which is created 7 times for 7 pages, in order to adjust
>> > position of each column).
>> >
>> > 2015-07-20 11:30 GMT+02:00 Pierre Dubillot <al...@gmail.com>:
>> >
>> > > Hi,
>> > > I'm about to finalize my project (which will extract areas of text),
>> but,
>> > > here's my problem :
>> > >
>> > > I've got a document (
>> > > http://www.cinemas-utopia.org/admin/grilles/toulouse/2015-07-21.pdf).
>> > > Then, I split it into 7 pages (
>> > >
>> >
>> http://www.docdroid.net/FedKhgp/2cac3a9c-b654-41c3-aea2-b473ccbeb06b.pdf.html
>> > > ).
>> > > In a XML file, I define which areas i've to extract. (For example :
>> the
>> > > current date of the page).
>> > > I create my objects ... Then I process extraction, but it only
>> extracts
>> > > the last page :
>> > > "[MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2,
>> MARJUIN2]"
>> > > (A list of the result after 7 pages extracted).
>> > >
>> > > I've to explain my code a little bit. First, I did a local app using
>> > > 1.8.9, then I switched to a Web App and used 2.0.0, so, I changed my
>> > code a
>> > > little bit, and everything seems to stop working.
>> > >
>> > > There are 3 main objects to process extraction : Line or Column and
>> Cell.
>> > > A line/column can contain cells.
>> > >
>> > > public Cell(String zoneName, double x, double y, int largeur, int
>> > hauteur)
>> > >> throws IOException {
>> > >> super();
>> > >> [this ...]
>> > >> uneCellule = new PDFTextStripperByArea();
>> > >> uneCellule.addRegion(nomZone, new Rectangle2D.Double(x, y, largeur,
>> > >> hauteur));
>> > >> }
>> > >>
>> > >
>> > > And, for example, a column will create attached cells.
>> > >
>> > >
>> > >
>> > > public Colonne(
>> > >> int index,
>> > >> String columnName,
>> > >> double x,
>> > >> double y,double hauteurCellule, double hauteurColonne, double
>> > >> largeurColonne, double decalage) throws IOException
>> > >> {
>> > >> [...]
>> > >> for(double i = y; i < (hauteurColonne + y);
>> > i+=(hauteurCellule+decalage)){
>> > >> cells.add(
>> > >> new Cell(
>> > >> nameOfCells.get(compteur),
>> > >> x,
>> > >> i,
>> > >> (int) largeurColonne,
>> > >> (int) hauteurCellule
>> > >> )
>> > >> );
>> > >> compteur++;
>> > >> }
>> > >> }
>> > >
>> > >
>> > > And my code to extract text (in my column object) :
>> > >>
>> > >> public ArrayList<String> scanCells(PDPage page) throws IOException{
>> > >> ArrayList<String> columnData= new ArrayList<String>();
>> > >> for(Cell cell: cells){
>> > >> cell.extractRegion(page);
>> > >> try {
>> > >> columnData.add(getTextOfCell(cell));
>> > >> } catch (ParseException e) {
>> > >> e.printStackTrace();
>> > >> }
>> > >> }
>> > >> return columnData;
>> > >> }
>> > >
>> > >
>> > > My documents are correctly loaded, each page is inside memory, I can't
>> > > find on my own how to solve this, it's a strange problem. If you have
>> any
>> > > idea (how I could update my code)..
>> > >
>> > > Thanks,
>> > >
>> > >
>> >
>>
>
>
Re: Extraction problems with PDFTextStripperByArea
Posted by Pierre Dubillot <al...@gmail.com>.
Yes, the method is called over another algorithm, which loops over each
page, and also with a different page number.
Console output :
> Page : 0 -
> [MARJUIN2]
> Page : 1 -
> [MARJUIN2]
> Page : 2 -
> [MARJUIN2]
> Page : 3 -
> [MARJUIN2]
> Page : 4 -
> [MARJUIN2]
> Page : 5 -
> [MARJUIN2]
> Page : 6 -
> [MARJUIN2]
But, that should be :
> [MERMAI27]
> [...]
> [MARJUIN2]
2015-07-20 17:58 GMT+02:00 Gilad Denneboom <gi...@gmail.com>:
> So are you calling this method each time with a different page number?
> What is the output to the console?
>
> On Mon, Jul 20, 2015 at 5:37 PM, Pierre Dubillot <al...@gmail.com>
> wrote:
>
> > I did a short example with the same problem :
> >
> >
> > PDFTextStripperByArea cellules;
> > >
> > public ArrayList<String> scanCells(PDDocument pdf, int pagenum) throws
> > >> IOException{
> > >
> > > ArrayList<String> columnData = new ArrayList<String>();
> > >
> > > cellules.extractRegions(pdf.getPage(pagenum));
> > >
> > > cellules.setStartPage(pagenum);
> > >
> > > System.out.println("Page : " + cellules.getStartPage() + " - " +
> > >> cellules.getEndPage());
> > >
> > > cellules.setSortByPosition(true);
> > >
> > > for(String region : cellules.getRegions()){
> > >
> > > // PDDocument pdoc = new PDDocument();
> > >
> > > // pdoc.addPage(page);
> > >
> > > // pdoc.save(new File("D:/Stage_DUT/pdfs/testing/" + region + ".pdf"));
> > >
> > > // pdoc.close();
> > >
> > > // System.out.println(cellules.getTextForRegion(region));
> > >
> > > columnData.add(cellules.getTextForRegion(region));
> > >
> > > System.out.println(columnData);
> > >
> > > }
> > >
> > > return columnData;
> > >
> > > }
> > >
> > >
> > Each region name is different (0page0, 0page1, 0page2, etc .. '0' is the
> > column number for the current page.) , and the method is called inside
> the
> > column object (which is created 7 times for 7 pages, in order to adjust
> > position of each column).
> >
> > 2015-07-20 11:30 GMT+02:00 Pierre Dubillot <al...@gmail.com>:
> >
> > > Hi,
> > > I'm about to finalize my project (which will extract areas of text),
> but,
> > > here's my problem :
> > >
> > > I've got a document (
> > > http://www.cinemas-utopia.org/admin/grilles/toulouse/2015-07-21.pdf).
> > > Then, I split it into 7 pages (
> > >
> >
> http://www.docdroid.net/FedKhgp/2cac3a9c-b654-41c3-aea2-b473ccbeb06b.pdf.html
> > > ).
> > > In a XML file, I define which areas i've to extract. (For example : the
> > > current date of the page).
> > > I create my objects ... Then I process extraction, but it only extracts
> > > the last page :
> > > "[MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2,
> MARJUIN2]"
> > > (A list of the result after 7 pages extracted).
> > >
> > > I've to explain my code a little bit. First, I did a local app using
> > > 1.8.9, then I switched to a Web App and used 2.0.0, so, I changed my
> > code a
> > > little bit, and everything seems to stop working.
> > >
> > > There are 3 main objects to process extraction : Line or Column and
> Cell.
> > > A line/column can contain cells.
> > >
> > > public Cell(String zoneName, double x, double y, int largeur, int
> > hauteur)
> > >> throws IOException {
> > >> super();
> > >> [this ...]
> > >> uneCellule = new PDFTextStripperByArea();
> > >> uneCellule.addRegion(nomZone, new Rectangle2D.Double(x, y, largeur,
> > >> hauteur));
> > >> }
> > >>
> > >
> > > And, for example, a column will create attached cells.
> > >
> > >
> > >
> > > public Colonne(
> > >> int index,
> > >> String columnName,
> > >> double x,
> > >> double y,double hauteurCellule, double hauteurColonne, double
> > >> largeurColonne, double decalage) throws IOException
> > >> {
> > >> [...]
> > >> for(double i = y; i < (hauteurColonne + y);
> > i+=(hauteurCellule+decalage)){
> > >> cells.add(
> > >> new Cell(
> > >> nameOfCells.get(compteur),
> > >> x,
> > >> i,
> > >> (int) largeurColonne,
> > >> (int) hauteurCellule
> > >> )
> > >> );
> > >> compteur++;
> > >> }
> > >> }
> > >
> > >
> > > And my code to extract text (in my column object) :
> > >>
> > >> public ArrayList<String> scanCells(PDPage page) throws IOException{
> > >> ArrayList<String> columnData= new ArrayList<String>();
> > >> for(Cell cell: cells){
> > >> cell.extractRegion(page);
> > >> try {
> > >> columnData.add(getTextOfCell(cell));
> > >> } catch (ParseException e) {
> > >> e.printStackTrace();
> > >> }
> > >> }
> > >> return columnData;
> > >> }
> > >
> > >
> > > My documents are correctly loaded, each page is inside memory, I can't
> > > find on my own how to solve this, it's a strange problem. If you have
> any
> > > idea (how I could update my code)..
> > >
> > > Thanks,
> > >
> > >
> >
>
Re: Extraction problems with PDFTextStripperByArea
Posted by Gilad Denneboom <gi...@gmail.com>.
So are you calling this method each time with a different page number?
What is the output to the console?
On Mon, Jul 20, 2015 at 5:37 PM, Pierre Dubillot <al...@gmail.com>
wrote:
> I did a short example with the same problem :
>
>
> PDFTextStripperByArea cellules;
> >
> public ArrayList<String> scanCells(PDDocument pdf, int pagenum) throws
> >> IOException{
> >
> > ArrayList<String> columnData = new ArrayList<String>();
> >
> > cellules.extractRegions(pdf.getPage(pagenum));
> >
> > cellules.setStartPage(pagenum);
> >
> > System.out.println("Page : " + cellules.getStartPage() + " - " +
> >> cellules.getEndPage());
> >
> > cellules.setSortByPosition(true);
> >
> > for(String region : cellules.getRegions()){
> >
> > // PDDocument pdoc = new PDDocument();
> >
> > // pdoc.addPage(page);
> >
> > // pdoc.save(new File("D:/Stage_DUT/pdfs/testing/" + region + ".pdf"));
> >
> > // pdoc.close();
> >
> > // System.out.println(cellules.getTextForRegion(region));
> >
> > columnData.add(cellules.getTextForRegion(region));
> >
> > System.out.println(columnData);
> >
> > }
> >
> > return columnData;
> >
> > }
> >
> >
> Each region name is different (0page0, 0page1, 0page2, etc .. '0' is the
> column number for the current page.) , and the method is called inside the
> column object (which is created 7 times for 7 pages, in order to adjust
> position of each column).
>
> 2015-07-20 11:30 GMT+02:00 Pierre Dubillot <al...@gmail.com>:
>
> > Hi,
> > I'm about to finalize my project (which will extract areas of text), but,
> > here's my problem :
> >
> > I've got a document (
> > http://www.cinemas-utopia.org/admin/grilles/toulouse/2015-07-21.pdf).
> > Then, I split it into 7 pages (
> >
> http://www.docdroid.net/FedKhgp/2cac3a9c-b654-41c3-aea2-b473ccbeb06b.pdf.html
> > ).
> > In a XML file, I define which areas i've to extract. (For example : the
> > current date of the page).
> > I create my objects ... Then I process extraction, but it only extracts
> > the last page :
> > "[MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2]"
> > (A list of the result after 7 pages extracted).
> >
> > I've to explain my code a little bit. First, I did a local app using
> > 1.8.9, then I switched to a Web App and used 2.0.0, so, I changed my
> code a
> > little bit, and everything seems to stop working.
> >
> > There are 3 main objects to process extraction : Line or Column and Cell.
> > A line/column can contain cells.
> >
> > public Cell(String zoneName, double x, double y, int largeur, int
> hauteur)
> >> throws IOException {
> >> super();
> >> [this ...]
> >> uneCellule = new PDFTextStripperByArea();
> >> uneCellule.addRegion(nomZone, new Rectangle2D.Double(x, y, largeur,
> >> hauteur));
> >> }
> >>
> >
> > And, for example, a column will create attached cells.
> >
> >
> >
> > public Colonne(
> >> int index,
> >> String columnName,
> >> double x,
> >> double y,double hauteurCellule, double hauteurColonne, double
> >> largeurColonne, double decalage) throws IOException
> >> {
> >> [...]
> >> for(double i = y; i < (hauteurColonne + y);
> i+=(hauteurCellule+decalage)){
> >> cells.add(
> >> new Cell(
> >> nameOfCells.get(compteur),
> >> x,
> >> i,
> >> (int) largeurColonne,
> >> (int) hauteurCellule
> >> )
> >> );
> >> compteur++;
> >> }
> >> }
> >
> >
> > And my code to extract text (in my column object) :
> >>
> >> public ArrayList<String> scanCells(PDPage page) throws IOException{
> >> ArrayList<String> columnData= new ArrayList<String>();
> >> for(Cell cell: cells){
> >> cell.extractRegion(page);
> >> try {
> >> columnData.add(getTextOfCell(cell));
> >> } catch (ParseException e) {
> >> e.printStackTrace();
> >> }
> >> }
> >> return columnData;
> >> }
> >
> >
> > My documents are correctly loaded, each page is inside memory, I can't
> > find on my own how to solve this, it's a strange problem. If you have any
> > idea (how I could update my code)..
> >
> > Thanks,
> >
> >
>
Re: Extraction problems with PDFTextStripperByArea
Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,
This is all very confusing, and partly because of trouble with your mail
software. I think we had this before, that code parts simply vanished.
I looked at the file with PDFDebugger. Your mediabox is different in the
pages. Maybe that is a possible cause?
Tilman
Am 20.07.2015 um 17:37 schrieb Pierre Dubillot:
> I did a short example with the same problem :
>
>
> PDFTextStripperByArea cellules;
> public ArrayList<String> scanCells(PDDocument pdf, int pagenum) throws
>>> IOException{
>> ArrayList<String> columnData = new ArrayList<String>();
>>
>> cellules.extractRegions(pdf.getPage(pagenum));
>>
>> cellules.setStartPage(pagenum);
>>
>> System.out.println("Page : " + cellules.getStartPage() + " - " +
>>> cellules.getEndPage());
>> cellules.setSortByPosition(true);
>>
>> for(String region : cellules.getRegions()){
>>
>> // PDDocument pdoc = new PDDocument();
>>
>> // pdoc.addPage(page);
>>
>> // pdoc.save(new File("D:/Stage_DUT/pdfs/testing/" + region + ".pdf"));
>>
>> // pdoc.close();
>>
>> // System.out.println(cellules.getTextForRegion(region));
>>
>> columnData.add(cellules.getTextForRegion(region));
>>
>> System.out.println(columnData);
>>
>> }
>>
>> return columnData;
>>
>> }
>>
>>
> Each region name is different (0page0, 0page1, 0page2, etc .. '0' is the
> column number for the current page.) , and the method is called inside the
> column object (which is created 7 times for 7 pages, in order to adjust
> position of each column).
>
> 2015-07-20 11:30 GMT+02:00 Pierre Dubillot <al...@gmail.com>:
>
>> Hi,
>> I'm about to finalize my project (which will extract areas of text), but,
>> here's my problem :
>>
>> I've got a document (
>> http://www.cinemas-utopia.org/admin/grilles/toulouse/2015-07-21.pdf).
>> Then, I split it into 7 pages (
>> http://www.docdroid.net/FedKhgp/2cac3a9c-b654-41c3-aea2-b473ccbeb06b.pdf.html
>> ).
>> In a XML file, I define which areas i've to extract. (For example : the
>> current date of the page).
>> I create my objects ... Then I process extraction, but it only extracts
>> the last page :
>> "[MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2]"
>> (A list of the result after 7 pages extracted).
>>
>> I've to explain my code a little bit. First, I did a local app using
>> 1.8.9, then I switched to a Web App and used 2.0.0, so, I changed my code a
>> little bit, and everything seems to stop working.
>>
>> There are 3 main objects to process extraction : Line or Column and Cell.
>> A line/column can contain cells.
>>
>> public Cell(String zoneName, double x, double y, int largeur, int hauteur)
>>> throws IOException {
>>> super();
>>> [this ...]
>>> uneCellule = new PDFTextStripperByArea();
>>> uneCellule.addRegion(nomZone, new Rectangle2D.Double(x, y, largeur,
>>> hauteur));
>>> }
>>>
>> And, for example, a column will create attached cells.
>>
>>
>>
>> public Colonne(
>>> int index,
>>> String columnName,
>>> double x,
>>> double y,double hauteurCellule, double hauteurColonne, double
>>> largeurColonne, double decalage) throws IOException
>>> {
>>> [...]
>>> for(double i = y; i < (hauteurColonne + y); i+=(hauteurCellule+decalage)){
>>> cells.add(
>>> new Cell(
>>> nameOfCells.get(compteur),
>>> x,
>>> i,
>>> (int) largeurColonne,
>>> (int) hauteurCellule
>>> )
>>> );
>>> compteur++;
>>> }
>>> }
>>
>> And my code to extract text (in my column object) :
>>> public ArrayList<String> scanCells(PDPage page) throws IOException{
>>> ArrayList<String> columnData= new ArrayList<String>();
>>> for(Cell cell: cells){
>>> cell.extractRegion(page);
>>> try {
>>> columnData.add(getTextOfCell(cell));
>>> } catch (ParseException e) {
>>> e.printStackTrace();
>>> }
>>> }
>>> return columnData;
>>> }
>>
>> My documents are correctly loaded, each page is inside memory, I can't
>> find on my own how to solve this, it's a strange problem. If you have any
>> idea (how I could update my code)..
>>
>> Thanks,
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Extraction problems with PDFTextStripperByArea
Posted by Pierre Dubillot <al...@gmail.com>.
I did a short example with the same problem :
PDFTextStripperByArea cellules;
>
public ArrayList<String> scanCells(PDDocument pdf, int pagenum) throws
>> IOException{
>
> ArrayList<String> columnData = new ArrayList<String>();
>
> cellules.extractRegions(pdf.getPage(pagenum));
>
> cellules.setStartPage(pagenum);
>
> System.out.println("Page : " + cellules.getStartPage() + " - " +
>> cellules.getEndPage());
>
> cellules.setSortByPosition(true);
>
> for(String region : cellules.getRegions()){
>
> // PDDocument pdoc = new PDDocument();
>
> // pdoc.addPage(page);
>
> // pdoc.save(new File("D:/Stage_DUT/pdfs/testing/" + region + ".pdf"));
>
> // pdoc.close();
>
> // System.out.println(cellules.getTextForRegion(region));
>
> columnData.add(cellules.getTextForRegion(region));
>
> System.out.println(columnData);
>
> }
>
> return columnData;
>
> }
>
>
Each region name is different (0page0, 0page1, 0page2, etc .. '0' is the
column number for the current page.) , and the method is called inside the
column object (which is created 7 times for 7 pages, in order to adjust
position of each column).
2015-07-20 11:30 GMT+02:00 Pierre Dubillot <al...@gmail.com>:
> Hi,
> I'm about to finalize my project (which will extract areas of text), but,
> here's my problem :
>
> I've got a document (
> http://www.cinemas-utopia.org/admin/grilles/toulouse/2015-07-21.pdf).
> Then, I split it into 7 pages (
> http://www.docdroid.net/FedKhgp/2cac3a9c-b654-41c3-aea2-b473ccbeb06b.pdf.html
> ).
> In a XML file, I define which areas i've to extract. (For example : the
> current date of the page).
> I create my objects ... Then I process extraction, but it only extracts
> the last page :
> "[MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2, MARJUIN2]"
> (A list of the result after 7 pages extracted).
>
> I've to explain my code a little bit. First, I did a local app using
> 1.8.9, then I switched to a Web App and used 2.0.0, so, I changed my code a
> little bit, and everything seems to stop working.
>
> There are 3 main objects to process extraction : Line or Column and Cell.
> A line/column can contain cells.
>
> public Cell(String zoneName, double x, double y, int largeur, int hauteur)
>> throws IOException {
>> super();
>> [this ...]
>> uneCellule = new PDFTextStripperByArea();
>> uneCellule.addRegion(nomZone, new Rectangle2D.Double(x, y, largeur,
>> hauteur));
>> }
>>
>
> And, for example, a column will create attached cells.
>
>
>
> public Colonne(
>> int index,
>> String columnName,
>> double x,
>> double y,double hauteurCellule, double hauteurColonne, double
>> largeurColonne, double decalage) throws IOException
>> {
>> [...]
>> for(double i = y; i < (hauteurColonne + y); i+=(hauteurCellule+decalage)){
>> cells.add(
>> new Cell(
>> nameOfCells.get(compteur),
>> x,
>> i,
>> (int) largeurColonne,
>> (int) hauteurCellule
>> )
>> );
>> compteur++;
>> }
>> }
>
>
> And my code to extract text (in my column object) :
>>
>> public ArrayList<String> scanCells(PDPage page) throws IOException{
>> ArrayList<String> columnData= new ArrayList<String>();
>> for(Cell cell: cells){
>> cell.extractRegion(page);
>> try {
>> columnData.add(getTextOfCell(cell));
>> } catch (ParseException e) {
>> e.printStackTrace();
>> }
>> }
>> return columnData;
>> }
>
>
> My documents are correctly loaded, each page is inside memory, I can't
> find on my own how to solve this, it's a strange problem. If you have any
> idea (how I could update my code)..
>
> Thanks,
>
>