# UTF-8 String to PDF using PDF::Writer

**URL:** <https://www.ruby-forum.com/t/utf-8-string-to-pdf-using-pdf-writer/69868>\
**Category:** Rails\
**Created:** [September 25, 2006, 6:09am UTC](https://www.ruby-forum.com/t/utf-8-string-to-pdf-using-pdf-writer/69868 "2006-09-25T06:09:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@andrew](https://www.ruby-forum.com/u/andrew)\
**Post date:** [September 25, 2006, 6:09am UTC](https://www.ruby-forum.com/t/utf-8-string-to-pdf-using-pdf-writer/69868/1 "2006-09-25T06:09:19Z")

</div>

Hi

I just can’t seem to figure this out.

I know that PDF doesn’t support UTF-8 so I’m trying to use Iconv to  
convert the string from UTF-8 to MacRoman (or anything that will  
work). This doesn’t seem to be working though. Is there a better/  
correct way to do this? The string is stored as UTF-8 in MySQL and  
displays properly on the web (\<?xml version="1.0" encoding="utf-8"?\>).

The main problem seems to be smart quotes do not come across I get  
strange symbols, everything else seems to work.

My latest attempt.

def create\_pdf  
# creates a PDF version of an authors listing. Pass a listing  
object as the methods parameter. AJ  
#  
pdfOfListing = PDF::Writer.new # defaults to a US Letter,  
portrait, PDF version 1.3 document. AJ  
pdfOfListing.compressed  
pdfOfListing.select\_font(‘Times-Roman’, {:encoding =\>  
‘MacRomanEncoding’})  
pdfOfListing.text(Iconv.conv(“UTF-8”, “MacRoman”,  
chapter.chapter\_body), :font\_size =\> 12, :justification =\> :left))  
send\_data(pdfOfListing.render, :filename =\>  
listing.title\_of\_work , :type =\> “application/pdf” )  
end

Thanks  
Andrew J.

---

<div class="post-metadata">

**Author:** ![andrew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@andrew](https://www.ruby-forum.com/u/andrew)\
**Post date:** [September 25, 2006, 6:55am UTC](https://www.ruby-forum.com/t/utf-8-string-to-pdf-using-pdf-writer/69868/2 "2006-09-25T06:55:23Z")

</div>

On 9/25/06, Andrew J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The main problem seems to be smart quotes do not come across I get  
> strange symbols, everything else seems to work.

Use substitution maps. Look in the source for the manual (it’s  
documented in the manual, but it’s not as clear as I’d like) and see  
where I do substitutions for the copyright character. It’s in the  
first 10k or so of source, and it’s pretty clear.

You can do any substitution you’d like at all.

## -austin

Austin Z. \* removed\_email\_address@domain.invalid \* [http://www.halostatue.ca/](http://www.halostatue.ca/)  
\* removed\_email\_address@domain.invalid \* [You are in a maze of twisty little passages, all alike. // halo • statue](http://www.halostatue.ca/feed/)  
\* removed\_email\_address@domain.invalid
