# Rails messing up FPDF / encodings?

**URL:** <https://www.ruby-forum.com/t/rails-messing-up-fpdf-encodings/88005>\
**Category:** Rails\
**Created:** [March 7, 2007, 2:35pm UTC](https://www.ruby-forum.com/t/rails-messing-up-fpdf-encodings/88005 "2007-03-07T14:35:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Isak\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@Isak\_H](https://www.ruby-forum.com/u/Isak_H)\
**Post date:** [March 7, 2007, 2:35pm UTC](https://www.ruby-forum.com/t/rails-messing-up-fpdf-encodings/88005/1 "2007-03-07T14:35:32Z")

</div>

This code seems to break under rails and the console (1.2.2 branch),  
while working as expected under irb:

* * *

require “fpdf/fpdf”

s = ("" \<\< 73 \<\< 241 \<\< 116 \<\< 234 \<\< 114 \<\< 110 \<\< 228 \<\< 116 \<\< 105  
\<\< 111 \<\< 110 \<\< 97 \<\< 108 \<\< 105 \<\< 122 \<\< 230 \<\< 116 \<\< 105 \<\< 248  
\<\< 110)

pdf = FPDF.new  
pdf.AddPage  
pdf.SetFont(“Arial”, “B”, 16)  
pdf.Cell(40, 10, s)  
pdf.Output(“test.pdf”)

* * *

The string should be valid cp1252, which afaik is also the default  
encoding for fpdf.

Running this code from irb creates a pdf containing the whole string,  
while trying to write the same string from within Rails or running  
this code in script/console chops off the last two characters…?

Any suggestions appreciated.

Isak

---

<div class="post-metadata">

**Author:** ![Isak\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@Isak\_H](https://www.ruby-forum.com/u/Isak_H)\
**Post date:** [March 8, 2007, 11:32am UTC](https://www.ruby-forum.com/t/rails-messing-up-fpdf-encodings/88005/2 "2007-03-08T11:32:28Z")

</div>

On 3/7/07, Isak H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> pdf.AddPage
> 
> Any suggestions appreciated.
> 
> Isak

Did some debugging on this issue, and found that my strings are  
getting mutilated by sprintf, which fpdf is using for string  
substitution, i.e. this is a kcode/ruby issue, and has nothing to do  
with rails.

Taking the discussion to comp.lang.ruby instead, thanks.

Isak
