Home > Uncategorized > PDF::Writer and Ruby on Rails

PDF::Writer and Ruby on Rails

January 15th, 2009 peter Leave a comment Go to comments

Was struggling with an unbelievably annoying error, where PDF::Writer (or pdf-writer as it’s also called) simply refused to show special accented characters incl the Euro sign, but presented garbage instead. Turns out that as of pdf-writer 1.1.8, the following is the case:

a) No, it doesn’t accept utf-16, despite what it claims
b) Feeding it utf-8, will look fine for what can be mapped to 7bit ASCII
c) Feeding it Win-1252 seems to do the trick, although some people claim it’s also hit and miss.

In your class doing the PDF generation, add a method like this:

def to_pw(text = '')
  return Iconv.conv('win-1252', 'utf-8', text)
end

And then call that to output all the text.

YMMV, but it worked for me.

Categories: Uncategorized Tags: , ,
  1. Sab
    April 9th, 2009 at 22:24 | #1

    Grande!!!!
    (Great :P )

  1. No trackbacks yet.