You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Jeffrey Zhao <jz...@rivit.ca> on 2012/02/08 14:56:17 UTC

POI freezing?

I'm using POI to get text contents and having intermittent freezing. The java thread calling  this part hangs sometimes.
Have you experience similar problems?  I'm using following code.

            PDFParser parser;
            String parsedText = null;
            PDFTextStripper pdfStripper = null;
            PDDocument pdDoc = null;
            COSDocument cosDoc = null;
            try {
                  parser = new PDFParser(in);
                  parser.parse();
                  cosDoc = parser.getDocument();
                  pdfStripper = new PDFTextStripper();
                  pdDoc = new PDDocument(cosDoc);
                  if(!pdDoc.isEncrypted()){
                        pdfStripper.setStartPage(1);
                        pdfStripper.setEndPage(Integer.MAX_VALUE);
                        parsedText = pdfStripper.getText(pdDoc);
                  }else{
                        log.error("PDF Failed (" + fname+ ") Encrypted");
                  }
            } catch (Exception e) {
                  log.error("PDF Failed (" + fname + ") Error: " + e.getMessage());
            } finally {
                  try {
                        if (cosDoc != null){
                              cosDoc.close();
                        }
                        if (pdDoc != null){
                              pdDoc.close();
                        }
                  } catch (Exception e) {
                        log.error("PDF Close (" + fname + ") Error: " + e.getMessage());
                  }
            }

Re: POI freezing?

Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,

Am 08.02.2012 15:12, schrieb Ilija Pavlic:
> POITextExtractor is a custom class of yours and not included in
> pdfbox. There is probably something amiss in your code.
I guess it is the wrong mailing list for that question.

You may join the mailing list from the Apache POI project [1] where the 
POITextExtractor class belongs to.

BR
Andreas Lehmkühler

[1] http://poi.apache.org/

> BR,
> Ilija.
>
> On Wed, Feb 8, 2012 at 3:10 PM, Jeffrey Zhao<jz...@rivit.ca>  wrote:
>> Sorry, wrong code. It's following code for the POI.
>>
>>         String txt = "";
>>                 POITextExtractor txtExtractor = null;
>>
>>                 try{
>>                         txtExtractor = ExtractorFactory.createExtractor(in);
>>                         txt = txtExtractor.getText();
>>                         txt = txt.trim();
>>                         txtExtractor = null;
>>                         //poiFactory = null;
>>                 }catch(Exception e){
>>                         log.error(e.getMessage(),e);
>>                 }
>>
>>                 txt = txt.trim();
>>
>>                 return txt;
>>
>>
>> -----Original Message-----
>> From: Jeffrey Zhao [mailto:jzhao@rivit.ca]
>> Sent: February 8, 2012 8:56 AM
>> To: users@pdfbox.apache.org
>> Subject: POI freezing?
>>
>> I'm using POI to get text contents and having intermittent freezing. The java thread calling  this part hangs sometimes.
>> Have you experience similar problems?  I'm using following code.
>>
>>             PDFParser parser;
>>             String parsedText = null;
>>             PDFTextStripper pdfStripper = null;
>>             PDDocument pdDoc = null;
>>             COSDocument cosDoc = null;
>>             try {
>>                   parser = new PDFParser(in);
>>                   parser.parse();
>>                   cosDoc = parser.getDocument();
>>                   pdfStripper = new PDFTextStripper();
>>                   pdDoc = new PDDocument(cosDoc);
>>                   if(!pdDoc.isEncrypted()){
>>                         pdfStripper.setStartPage(1);
>>                         pdfStripper.setEndPage(Integer.MAX_VALUE);
>>                         parsedText = pdfStripper.getText(pdDoc);
>>                   }else{
>>                         log.error("PDF Failed (" + fname+ ") Encrypted");
>>                   }
>>             } catch (Exception e) {
>>                   log.error("PDF Failed (" + fname + ") Error: " + e.getMessage());
>>             } finally {
>>                   try {
>>                         if (cosDoc != null){
>>                               cosDoc.close();
>>                         }
>>                         if (pdDoc != null){
>>                               pdDoc.close();
>>                         }
>>                   } catch (Exception e) {
>>                         log.error("PDF Close (" + fname + ") Error: " + e.getMessage());
>>                   }
>>             }
>>


Re: POI freezing?

Posted by Ilija Pavlic <il...@gmail.com>.
POITextExtractor is a custom class of yours and not included in
pdfbox. There is probably something amiss in your code.

BR,
Ilija.

On Wed, Feb 8, 2012 at 3:10 PM, Jeffrey Zhao <jz...@rivit.ca> wrote:
> Sorry, wrong code. It's following code for the POI.
>
>        String txt = "";
>                POITextExtractor txtExtractor = null;
>
>                try{
>                        txtExtractor = ExtractorFactory.createExtractor(in);
>                        txt = txtExtractor.getText();
>                        txt = txt.trim();
>                        txtExtractor = null;
>                        //poiFactory = null;
>                }catch(Exception e){
>                        log.error(e.getMessage(),e);
>                }
>
>                txt = txt.trim();
>
>                return txt;
>
>
> -----Original Message-----
> From: Jeffrey Zhao [mailto:jzhao@rivit.ca]
> Sent: February 8, 2012 8:56 AM
> To: users@pdfbox.apache.org
> Subject: POI freezing?
>
> I'm using POI to get text contents and having intermittent freezing. The java thread calling  this part hangs sometimes.
> Have you experience similar problems?  I'm using following code.
>
>            PDFParser parser;
>            String parsedText = null;
>            PDFTextStripper pdfStripper = null;
>            PDDocument pdDoc = null;
>            COSDocument cosDoc = null;
>            try {
>                  parser = new PDFParser(in);
>                  parser.parse();
>                  cosDoc = parser.getDocument();
>                  pdfStripper = new PDFTextStripper();
>                  pdDoc = new PDDocument(cosDoc);
>                  if(!pdDoc.isEncrypted()){
>                        pdfStripper.setStartPage(1);
>                        pdfStripper.setEndPage(Integer.MAX_VALUE);
>                        parsedText = pdfStripper.getText(pdDoc);
>                  }else{
>                        log.error("PDF Failed (" + fname+ ") Encrypted");
>                  }
>            } catch (Exception e) {
>                  log.error("PDF Failed (" + fname + ") Error: " + e.getMessage());
>            } finally {
>                  try {
>                        if (cosDoc != null){
>                              cosDoc.close();
>                        }
>                        if (pdDoc != null){
>                              pdDoc.close();
>                        }
>                  } catch (Exception e) {
>                        log.error("PDF Close (" + fname + ") Error: " + e.getMessage());
>                  }
>            }
>

RE: POI freezing?

Posted by Jeffrey Zhao <jz...@rivit.ca>.
Sorry, wrong code. It's following code for the POI.

	String txt = "";
		POITextExtractor txtExtractor = null;
				
		try{
			txtExtractor = ExtractorFactory.createExtractor(in);
			txt = txtExtractor.getText();
			txt = txt.trim();
			txtExtractor = null;
			//poiFactory = null;
		}catch(Exception e){
			log.error(e.getMessage(),e);			
		}
		
		txt = txt.trim();
						
		return txt;


-----Original Message-----
From: Jeffrey Zhao [mailto:jzhao@rivit.ca] 
Sent: February 8, 2012 8:56 AM
To: users@pdfbox.apache.org
Subject: POI freezing?

I'm using POI to get text contents and having intermittent freezing. The java thread calling  this part hangs sometimes.
Have you experience similar problems?  I'm using following code.

            PDFParser parser;
            String parsedText = null;
            PDFTextStripper pdfStripper = null;
            PDDocument pdDoc = null;
            COSDocument cosDoc = null;
            try {
                  parser = new PDFParser(in);
                  parser.parse();
                  cosDoc = parser.getDocument();
                  pdfStripper = new PDFTextStripper();
                  pdDoc = new PDDocument(cosDoc);
                  if(!pdDoc.isEncrypted()){
                        pdfStripper.setStartPage(1);
                        pdfStripper.setEndPage(Integer.MAX_VALUE);
                        parsedText = pdfStripper.getText(pdDoc);
                  }else{
                        log.error("PDF Failed (" + fname+ ") Encrypted");
                  }
            } catch (Exception e) {
                  log.error("PDF Failed (" + fname + ") Error: " + e.getMessage());
            } finally {
                  try {
                        if (cosDoc != null){
                              cosDoc.close();
                        }
                        if (pdDoc != null){
                              pdDoc.close();
                        }
                  } catch (Exception e) {
                        log.error("PDF Close (" + fname + ") Error: " + e.getMessage());
                  }
            }