# Example on rpdf2text?

**URL:** <https://www.ruby-forum.com/t/example-on-rpdf2text/106079>\
**Category:** Ruby\
**Created:** [June 6, 2007, 7:08am UTC](https://www.ruby-forum.com/t/example-on-rpdf2text/106079 "2007-06-06T07:08:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@coelho](https://www.ruby-forum.com/u/coelho)\
**Post date:** [June 6, 2007, 7:08am UTC](https://www.ruby-forum.com/t/example-on-rpdf2text/106079/1 "2007-06-06T07:08:12Z")

</div>

Hello,

I am trying to use the rpdf2text library, does anyone have any example  
on how to use properly? [http://raa.ruby-lang.org/project/rpdf2txt/](http://raa.ruby-lang.org/project/rpdf2txt/)  
thank you

---

<div class="post-metadata">

**Author:** ![coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@coelho](https://www.ruby-forum.com/u/coelho)\
**Post date:** [June 6, 2007, 9:36am UTC](https://www.ruby-forum.com/t/example-on-rpdf2text/106079/2 "2007-06-06T09:36:18Z")

</div>

On 6/6/07, coelho coelho [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am trying to use the rpdf2text library, does anyone have any example  
> on how to use properly? [http://raa.ruby-lang.org/project/rpdf2txt/](http://raa.ruby-lang.org/project/rpdf2txt/)

this is taken from bin/rpdf2txt (comments added for your benefit;)

# create a parser-instance, with the pdf-content as its first argument. # The second argument is the encoding you want the resulting String to # have. Note: if you need utf8, I recommend the character-encoding # library by Nikolai W.

parser = Rpdf2txt::Parser.new(File.read(ARGV[0]), ‘utf8’)

outstream = STDOUT  
if(ARGV.size == 2)  
outstream = File.open(ARGV[1], ‘w’)  
end

# create a callback handler (If you roll your own, be sure to include

# Rpdf2txt::DefaultHandler). outstream needs to respond to :\<\<

handler = Rpdf2txt::ColumnHandler.new(outstream, padding)  
parser.extract\_text(handler)

There have recently been a couple of major improvements in how rpdf2txt  
positions characters. However, there’s no official release for that yet.  
Since you’re just starting out, I would recommend using a daily build  
from [http://download.ywesee.com/rpdf2txt/rpdf2txt-daily.tar.bz2](http://download.ywesee.com/rpdf2txt/rpdf2txt-daily.tar.bz2),  
or download rpdf2txt via git/cogito:

cg-clone [http://scm.ywesee.com/rpdf2txt](http://scm.ywesee.com/rpdf2txt)

Changelog: [http://scm.ywesee.com/?p=rpdf2txt;a=summary](http://scm.ywesee.com/?p=rpdf2txt;a=summary)

hth,  
let me know if it works for you

Hannes
