And it works! Here's the secret:

Do use the string m-patch
string_utf8_mpatch.rb:
#international character support
class String
    require 'iconv'
    def to_iso
        c = Iconv.new('ISO-8859-15','UTF-8')
        c.iconv(self)
    end
end
# require this in *all* files which handles the strings you are using
# require 'string_utf8_mpatch.rb'

Do use the pdf/writer m-patch
pdfwriter_utf8_mpatch.rb:
#
CONVERTER = Iconv.new( 'ISO-8859-15//IGNORE//TRANSLIT', 'utf-8')
module PDF
    class Writer
        alias :text_old :text
        def text( texto, options = {} )
            text_old( CONVERTER.iconv(texto), options )
        end

        alias_method :old_add_text, :add_text
        def add_text(x, y, text, *options)
          old_add_text(x, y, CONVERTER.iconv(text), *options)
        end
    end
end
# require 'pdfwriter_utf8_mpatch.rb'

Don't use the mechanize monkey patch. It doesn't work and it messes up
picture downloads

AJ ONeal


On Mon, May 25, 2009 at 11:52 AM, AJ ONeal <[email protected]> wrote:

> I think I need to upscale a UTF-8 character to UTF-16 or use some
> regex-UTF-foo in order to view correctly in a pdf generated by ruby's
> PDF::Writer.
>
> This is what I see in the ward directory:
> Encarnación Braña (Output from webpage, also displays well in my terminal)
> Encarnación Braña (Output in PDF)
> Encarnaci\303\263n Bra\303\261a (Ruby's String.inspect)
>
> If I understand correctly:
> ANSI is the normal a-Z, and uses 1 byte per character.
> UTF-8 is for normal international characters and uses 2 bytes per
> character.
> UTF-16 can handle all the 25,000 character-alphabets and uses 4 bytes per
> character.
>
> I see 2 bytes being used, hence this is encoded in UTF-8? Or could this
> just as well be some ISO something?
>
> I've tried a few of the various monkey patches suggested online (including
> Incov changes to the String, PDF::Writer, and Mechanize modules, but it
> doesn't work). Have any of you encountered this problem before?
>
> AJ ONeal
>
--------------------
BYU Unix Users Group 
http://uug.byu.edu/ 

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG. 
___________________________________________________________________
List Info (unsubscribe here): http://uug.byu.edu/mailman/listinfo/uug-list

Reply via email to