Ruby on Rails
Rfpdf Plugin (Version #4)

Adds support for .rfpdf templates which generate PDF files using Ruby FPDF.

I am a long time user of PDFlib. When I started working with Ruby on Rails, like Ruby on Rails I searched for a free PDF capable solution. I tried RTex with mixed results – sometimes it worked sometimes it didn’t. Then I found Ruby on FPDF. I have been very pleased.

I did like the template view capability of RTex, which accommodated embedding the ruby code in files with .rtex extensions.

I also had a client that needed Chinese, Japanese and Korean support. These languages were supported in the PHP version of FPDF but only Chinese had been ported and that port didn’t work properly so I spent the weekend porting these three languages to Ruby from PHP.

The Rfpdf Plugin incorporates: Ruby FPDF, e-ruby template view support (.rfpdf files) and additional Asian support for Chinese, Japanese and Korean languages.

Download it at http://rubyforge.org/projects/rfpdf/ or

Install It

Just like many Rails plugins:

    ruby script/plugin install <a href="http://rfpdf.googlecode.com/svn/rfpdf">http://rfpdf.googlecode.com/svn/rfpdf</a>

or, direct from the repository into vendor/plugins:

    cd vendor/plugins
    svn co <a href="http://rfpdf.googlecode.com/svn/rfpdf">http://rfpdf.googlecode.com/svn/rfpdf</a>

Example .rb method Usage

In the controller, something like:


  def mypdf
		pdf = FPDF.new()

		#
		# Chinese
		#
		pdf.extend(PDF_Chinese)
		pdf.AddPage
		pdf.AddBig5Font
		pdf.SetFont('Big5','',18)
		pdf.Write(5, '²{®É®ð·Å 18 C Àã«× 83 %')
		icBig5 = Iconv.new('Big5', 'UTF-8')
		pdf.Write(15, icBig5.iconv("宋体 should be working"))
		send_data pdf.Output, :filename => "something.pdf", :type => "application/pdf"
  end

Example .rfdf Usage

In the controller, something like:


  def mypdf
  end

In the layout (make sure this is the only item in the layout):


<%= @content_for_layout %>


In the view (mypdf.rfpdf):


<%
	pdf = FPDF.new()
	#
	# Chinese
	#
 	pdf.extend(PDF_Chinese)
 	pdf.AddPage
 	pdf.AddBig5Font
 	pdf.SetFont('Big5','',18)
 	pdf.Write(5, '²{®É®ð·Å 18 C Àã«× 83 %')
 	icBig5 = Iconv.new('Big5', 'UTF-8')
 	pdf.Write(15, icBig5.iconv("宋体 should be working"))

	#
	# Japanese
	#
 	pdf.extend(PDF_Japanese)
 	pdf.AddSJISFont();
 	pdf.AddPage();
 	pdf.SetFont('SJIS','',18);
 	pdf.Write(5,'9ÉñåéÇÃåˆäJÉeÉXÉgÇåoǃPHP 3.0ÇÕ1998îN6åéÇ…åˆéÆÇ…ÉäÉäÅ[ÉXÇ≥Ç�?NjǵÇΩÅB');
 	icSJIS = Iconv.new('SJIS', 'UTF-8')
 	pdf.Write(15, icSJIS.iconv("�?�れ�?�テキスト�?��?�る should be working"))

	#
	# Korean
	#
 	pdf.extend(PDF_Korean)
 	pdf.AddUHCFont();
 	pdf.AddPage();
 	pdf.SetFont('UHC','',18);
 	pdf.Write(5,'PHP 3.0Àº 1998³â 6¿ù¿¡ °ø½ÄÀûÀ¸·Î ¸±¸®�?îµÇ¾ú´Ù. °ø°³ÀûÀÎ Å×½ºÆ® ÀÌÈľà 9°³¿ù¸¸À̾ú´Ù.');
 	icUHC = Iconv.new('UHC', 'UTF-8')
 	pdf.Write(15, icUHC.iconv("�?�것�?� �?본 �?�다"))

	#
	# English
	#
 	pdf.AddPage();
	pdf.SetFont('Arial', '', 10)
	pdf.Write(5, "should be working")
%>
<%=	pdf.Output() %>

Contributions

Olivier Plathey the author of FPDF.

Brian Ollenberger, who ported FDPF to Ruby.

Bruce Williams, the author of RTex.

Feedback

For any remark, question or problem, you can leave a message on the forum.

Latest News

It looks like this project is now updated to support Unicode and UTF-8, via TCPDF. See here

Adds support for .rfpdf templates which generate PDF files using Ruby FPDF.

I am a long time user of PDFlib. When I started working with Ruby on Rails, like Ruby on Rails I searched for a free PDF capable solution. I tried RTex with mixed results – sometimes it worked sometimes it didn’t. Then I found Ruby on FPDF. I have been very pleased.

I did like the template view capability of RTex, which accommodated embedding the ruby code in files with .rtex extensions.

I also had a client that needed Chinese, Japanese and Korean support. These languages were supported in the PHP version of FPDF but only Chinese had been ported and that port didn’t work properly so I spent the weekend porting these three languages to Ruby from PHP.

The Rfpdf Plugin incorporates: Ruby FPDF, e-ruby template view support (.rfpdf files) and additional Asian support for Chinese, Japanese and Korean languages.

Download it at http://rubyforge.org/projects/rfpdf/ or

Install It

Just like many Rails plugins:

    ruby script/plugin install <a href="http://rfpdf.googlecode.com/svn/rfpdf">http://rfpdf.googlecode.com/svn/rfpdf</a>

or, direct from the repository into vendor/plugins:

    cd vendor/plugins
    svn co <a href="http://rfpdf.googlecode.com/svn/rfpdf">http://rfpdf.googlecode.com/svn/rfpdf</a>

Example .rb method Usage

In the controller, something like:


  def mypdf
		pdf = FPDF.new()

		#
		# Chinese
		#
		pdf.extend(PDF_Chinese)
		pdf.AddPage
		pdf.AddBig5Font
		pdf.SetFont('Big5','',18)
		pdf.Write(5, '²{®É®ð·Å 18 C Àã«× 83 %')
		icBig5 = Iconv.new('Big5', 'UTF-8')
		pdf.Write(15, icBig5.iconv("宋体 should be working"))
		send_data pdf.Output, :filename => "something.pdf", :type => "application/pdf"
  end

Example .rfdf Usage

In the controller, something like:


  def mypdf
  end

In the layout (make sure this is the only item in the layout):


<%= @content_for_layout %>


In the view (mypdf.rfpdf):


<%
	pdf = FPDF.new()
	#
	# Chinese
	#
 	pdf.extend(PDF_Chinese)
 	pdf.AddPage
 	pdf.AddBig5Font
 	pdf.SetFont('Big5','',18)
 	pdf.Write(5, '²{®É®ð·Å 18 C Àã«× 83 %')
 	icBig5 = Iconv.new('Big5', 'UTF-8')
 	pdf.Write(15, icBig5.iconv("宋体 should be working"))

	#
	# Japanese
	#
 	pdf.extend(PDF_Japanese)
 	pdf.AddSJISFont();
 	pdf.AddPage();
 	pdf.SetFont('SJIS','',18);
 	pdf.Write(5,'9ÉñåéÇÃåˆäJÉeÉXÉgÇåoǃPHP 3.0ÇÕ1998îN6åéÇ…åˆéÆÇ…ÉäÉäÅ[ÉXÇ≥Ç�?NjǵÇΩÅB');
 	icSJIS = Iconv.new('SJIS', 'UTF-8')
 	pdf.Write(15, icSJIS.iconv("�?�れ�?�テキスト�?��?�る should be working"))

	#
	# Korean
	#
 	pdf.extend(PDF_Korean)
 	pdf.AddUHCFont();
 	pdf.AddPage();
 	pdf.SetFont('UHC','',18);
 	pdf.Write(5,'PHP 3.0Àº 1998³â 6¿ù¿¡ °ø½ÄÀûÀ¸·Î ¸±¸®�?îµÇ¾ú´Ù. °ø°³ÀûÀÎ Å×½ºÆ® ÀÌÈľà 9°³¿ù¸¸À̾ú´Ù.');
 	icUHC = Iconv.new('UHC', 'UTF-8')
 	pdf.Write(15, icUHC.iconv("�?�것�?� �?본 �?�다"))

	#
	# English
	#
 	pdf.AddPage();
	pdf.SetFont('Arial', '', 10)
	pdf.Write(5, "should be working")
%>
<%=	pdf.Output() %>

Contributions

Olivier Plathey the author of FPDF.

Brian Ollenberger, who ported FDPF to Ruby.

Bruce Williams, the author of RTex.

Feedback

For any remark, question or problem, you can leave a message on the forum.

Latest News

It looks like this project is now updated to support Unicode and UTF-8, via TCPDF. See here