How to use special characters in FPDF

How to use special characters in FPDF

Postby cccp » Wed May 27, 2009 8:14 am

FPDF is a nice little library for php that allows you to create PDFs on the fly. It’s great for all sorts of document, amongs them invoices. Until you try to use say a pound (£) or euro (€) sign. Basically the library itself does not support utf-8, so the moment you need to insert anything extra into your document a conversion needs to be done.

Here is the background:

I have a Web page with a Form that saves data to a MySQL database. I
need to retrieve the data from the database and create a PDF document
with FPDF.

The Web Page, the database, and the browser are all set to UTF-8, so I
have to convert the data from the database to ISO-8859-1 in order to
have FPDF show it correctly. I am using iconv() to convert the data.

It works like a charm for the data acquired with text boxes, but it does
not parse the data acquired from textareas correctly.

For example:

I have an text input (<input type="text" />) and a textarea
(<textarea></textarea>).
I type the string "sometextàèìòùésomeothertext" on both the input fields
and save it into the database through POST.

If I retrieve the data and show it on a web page, it shows correctly. I
then create the PDF with FPDF parsing the data with the following

User avatar
cccp
Newbie
Newbie
 
Posts: 35
Joined: Mon Apr 30, 2007 10:31 am

Re: How to use special characters in FPDF

Postby Darwin » Wed May 27, 2009 8:19 am

Use the iconv function to convert the special characters.

Code: Select all
$textarea = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $textarea)
;


then just print the string to the cell like normal.

User avatar
Darwin
Full Member
Full Member
 
Posts: 111
Joined: Mon Oct 09, 2006 11:16 am
Location: Bradenton, FL


Return to PHP

Who is online

Users browsing this forum: No registered users and 0 guests

cron