# FPDF set FONT\_PATH

**URL:** <https://www.ruby-forum.com/t/fpdf-set-font-path/96881>\
**Category:** Rails\
**Created:** [July 3, 2006, 3:54am UTC](https://www.ruby-forum.com/t/fpdf-set-font-path/96881 "2006-07-03T03:54:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ellraziq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@ellraziq](https://www.ruby-forum.com/u/ellraziq)\
**Post date:** [July 3, 2006, 3:54am UTC](https://www.ruby-forum.com/t/fpdf-set-font-path/96881/1 "2006-07-03T03:54:54Z")

</div>

hi all,  
im using ruby FPDF to generate my pdf. the problem im facing now is i  
need to use some new font that is not included in basic fpdf font. then  
i have generated the font using the makefont.rb. but then i dont know  
how to define the font\_path in ruby. the font work great in PHP-FPDF. Is  
anybody there had solved the problem im facing now.

\*\* sorry for my english …

---

<div class="post-metadata">

**Author:** ![ellraziq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@ellraziq](https://www.ruby-forum.com/u/ellraziq)\
**Post date:** [July 3, 2006, 6:28pm UTC](https://www.ruby-forum.com/t/fpdf-set-font-path/96881/2 "2006-07-03T18:28:59Z")

</div>

On Jul 2, 2006, at 7:54 PM, raziq zaki wrote:

> –

In order to set the font path, you need to define the constant  
FPDF\_FONTPATH in your subclass of FPDF. You should do something  
like this:

class My\_PDF\_Document \< FPDF

FPDF\_FONTPATH = “/path/to/my/new/font”

# your code here…

end

When the pdf document is created, the code looks for the font  
in the directory “/path/to/my/new/font”.

## Kim

Kim S. - principal, Shrier and Deihl - [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Remote Unix Network Admin, Security, Internet Software Development  
Tinker Internet Services - Superior FreeBSD-based Web Hosting  
[http://www.tinker.com/](http://www.tinker.com/)

---

<div class="post-metadata">

**Author:** ![ellraziq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@ellraziq](https://www.ruby-forum.com/u/ellraziq)\
**Post date:** [July 3, 2006, 9:11pm UTC](https://www.ruby-forum.com/t/fpdf-set-font-path/96881/3 "2006-07-03T21:11:24Z")

</div>

raziq zaki wrote:

> hi all,  
> im using ruby FPDF to generate my pdf. the problem im facing now is i  
> need to use some new font that is not included in basic fpdf font. then  
> i have generated the font using the makefont.rb. but then i dont know  
> how to define the font\_path in ruby. the font work great in PHP-FPDF. Is  
> anybody there had solved the problem im facing now.
> 
> \*\* sorry for my english …

Raziq,  
there are some embeding font problems I recognized in FPDF library that  
I found workaround so tell if you still have problems.

Bojan

–  
Bojan M.  
Informatika Mihelac, Bojan M. s.p. | [www.informatikamihelac.com](http://www.informatikamihelac.com)  
 → tools, scripts, tricks from our code lab: [http://source.mihelac.org](http://source.mihelac.org)

---

<div class="post-metadata">

**Author:** ![ellraziq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@ellraziq](https://www.ruby-forum.com/u/ellraziq)\
**Post date:** [July 5, 2006, 7:29pm UTC](https://www.ruby-forum.com/t/fpdf-set-font-path/96881/4 "2006-07-05T19:29:52Z")

</div>

raziq wrote:

> thanks all,  
> i manage to create my pdf with the font. But when i open the pdf file  
> created, there an error saying cannot extract the embedded font. the  
> font display is not what im aspected.
> 
> im not defined the FPDF\_FONTPATH in my script, but hardcoded it in  
> fpdf.rb.
> 
> did this method give me the error.

Raziq,  
if you use FPDF on windows then change (line 1014 of rpdf.rb):

putstream(IO.read(file))

to:

File.open(file, “rb”) { |io| putstream(io.read) }

so the file would be read read in binary mode.

hope it helps,  
Bojan

–  
Bojan M.  
Informatika Mihelac, Bojan M. s.p. | [www.informatikamihelac.com](http://www.informatikamihelac.com)  
 → tools, scripts, tricks from our code lab: [http://source.mihelac.org](http://source.mihelac.org)

---

<div class="post-metadata">

**Author:** ![ellraziq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@ellraziq](https://www.ruby-forum.com/u/ellraziq)\
**Post date:** [March 31, 2009, 5:56am UTC](https://www.ruby-forum.com/t/fpdf-set-font-path/96881/5 "2009-03-31T05:56:06Z")

</div>

I’m still a noob with Rails so please forgive me but…

How do I use makefont to generate the font files. I currently have a  
japanese font ttf file that I want to use.

Thanks

---

<div class="post-metadata">

**Author:** ![ellraziq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@ellraziq](https://www.ruby-forum.com/u/ellraziq)\
**Post date:** [July 5, 2006, 4:07am UTC](https://www.ruby-forum.com/t/fpdf-set-font-path/96881/6 "2006-07-05T04:07:15Z")

</div>

thanks all,  
i manage to create my pdf with the font. But when i open the pdf file  
created, there an error saying cannot extract the embedded font. the  
font display is not what im aspected.

im not defined the FPDF\_FONTPATH in my script, but hardcoded it in  
fpdf.rb.

did this method give me the error.
