You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Suhas Indra <su...@robosoftin.com> on 2002/12/27 07:34:11 UTC
PDF Text extraction
Hello List
I am using PDFBox to index some of the PDF documents. The parser works fine
and I can read the summary. But the contents are displayed as
java.io.InputStream.
When I try the following:
System.out.println(doc.getField("contents")) (where doc is the Document
object)
The result will be:
Text<co...@127dc0>
I want to print the extracted data.
Can anyone please let me know how to extract the contents?
Regards
Suhas
--------------------------------------------------------------
Robosoft Technologies - Partners in Product Development
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: PDF Text extraction
Posted by Ben Litchfield <be...@csh.rit.edu>.
You need to do something like
//first get the document field
Field contentsField = doc.getField( "contents" );
//Then get the reader from the field
BufferedReader contentsReader =
new BufferedReader( contentsField.readerValue() );
//finally dump the contents of the reader to System.out
String line = null;
while( (line = contentsReader.readLine() ) != null )
{
System.out.println( line );
}
I have not tested if this compiles but it should be pretty close.
Ben Litchfield
On Fri, 27 Dec 2002, Suhas Indra wrote:
> Hello List
>
> I am using PDFBox to index some of the PDF documents. The parser works fine
> and I can read the summary. But the contents are displayed as
> java.io.InputStream.
>
> When I try the following:
> System.out.println(doc.getField("contents")) (where doc is the Document
> object)
>
> The result will be:
>
> Text<co...@127dc0>
>
> I want to print the extracted data.
>
> Can anyone please let me know how to extract the contents?
>
> Regards
>
> Suhas
>
>
>
> --------------------------------------------------------------
> Robosoft Technologies - Partners in Product Development
>
>
>
>
>
>
>
>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
--
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: PDF Text extraction
Posted by Karl Øie <ka...@gan.no>.
to get the string value of a inputstream you can use it to fill a
ByteArrayInputStream and get the content from that;
ByteArrayInputStream bais = new ByteArrayInputStream(inputstream);
System.out.println( new String(bais.getBytes()) );
mvh karl øie
On Friday, Dec 27, 2002, at 07:34 Europe/Oslo, Suhas Indra wrote:
> Hello List
>
> I am using PDFBox to index some of the PDF documents. The parser works
> fine
> and I can read the summary. But the contents are displayed as
> java.io.InputStream.
>
> When I try the following:
> System.out.println(doc.getField("contents")) (where doc is the Document
> object)
>
> The result will be:
>
> Text<co...@127dc0>
>
> I want to print the extracted data.
>
> Can anyone please let me know how to extract the contents?
>
> Regards
>
> Suhas
>
>
>
> --------------------------------------------------------------
> Robosoft Technologies - Partners in Product Development
>
>
>
>
>
>
>
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: PDF Text extraction
Posted by Kelvin Tan <ke...@relevanz.com>.
Try this?
InputStream input = new FileInputStream(file);
COSDocument document = parseDocument(input);
PDFTextStripper stripper = new PDFTextStripper();
StringWriter output = new StringWriter()
stripper.writeText(document, output);
System.out.println(output.toString())
errmmm...the code may not be 100% correct, but you get the idea.
Regards,
Kelvin
--------
The book giving manifesto - http://how.to/sharethisbook
On Fri, 27 Dec 2002 12:04:11 +0530, Suhas Indra said:
>Hello List
>
>I am using PDFBox to index some of the PDF documents. The parser
>works fine and I can read the summary. But the contents are
>displayed as java.io.InputStream.
>
>When I try the following:
>System.out.println(doc.getField("contents")) (where doc is the
>Document object)
>
>The result will be:
>
>Text<co...@127dc0>
>
>I want to print the extracted data.
>
>Can anyone please let me know how to extract the contents?
>
>Regards
>
>Suhas
>
>
>
>--------------------------------------------------------------
>Robosoft Technologies - Partners in Product Development
>
>
>
>
>
>
>
>
>
>--
>To unsubscribe, e-mail: <mailto:lucene-user-
>unsubscribe@jakarta.apache.org> For additional commands, e-mail:
><mailto:lucene-user-
>help@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>