Convert raw text to utf-8

Skip to first unread message

Damian Martinelli

May 18, 2017, 7:07:34 AM5/18/17
to PDF::Reader
I'm getting the raw_content from a pdf and I want to get some part of it converted to utf-8 (like a see it when I use the text method from the page object).

I saw the code, what is done on the text method on the Page class.

I tried with code from the Parser class, related to MAPPING, but I'm not getting the desired text.

For example, from the raw_content I get "Luj\\341n"

str = "Luj\\341n"

str.gsub!(/\\([nrtbf()\\\n]|\d{1,3})?|\r\n?|\n\r/m) do |match|
  MAPPING[match] || ""

And I get "Luj\xE1n"

\xE1 should be an 'á'

\x00E1 is an 'á' on utf-16 encoding.

What am I missing to get str = "Luján"?

Can anyone help me?


James Healy

Jun 24, 2017, 11:01:10 AM6/24/17
Unfortunately using the raw_content method is unlikely to help with
the vast majority of PDFs.

Are you trying to extract text from specific sections of a page,
rather than the entire page?

pdf-reader doesn't support that out of the box. If you want to explore
writing custom code to do it, the `PDF::Reader::PageTextReceiver`
class is 80% of the way there. The missing piece is providing a way to
specify the bounding box you're interested in and ignoring any
characters outside it.

> --
> You received this message because you are subscribed to the Google Groups
> "PDF::Reader" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
> To post to this group, send email to
> Visit this group at
> For more options, visit
Reply all
Reply to author
0 new messages