<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Martin on Rails</title>
	<atom:link href="http://www.martinonrails.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.martinonrails.com</link>
	<description>Let's eat chunky bacon together!</description>
	<lastBuildDate>Thu, 26 Feb 2009 00:57:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Justification problem with PDF generators</title>
		<link>http://www.martinonrails.com/2008/04/03/justification-problem-with-pdf-generators/</link>
		<comments>http://www.martinonrails.com/2008/04/03/justification-problem-with-pdf-generators/#comments</comments>
		<pubDate>Fri, 04 Apr 2008 00:19:51 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Ruby Libraries]]></category>
		<category><![CDATA[Justification]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.martinonrails.com/?p=3</guid>
		<description><![CDATA[Unfortunatly there seems to be a bug with justification in the PDF::Writer library, which I described in detail in a bug report on the PDF::Writer site. On the mailing list this was confirmed as a known bug. Because I needed a solution I decided to have a look at the Ruby port of the well [...]]]></description>
			<content:encoded><![CDATA[<p>Unfortunatly there seems to be a bug with justification in the <a href="http://stonecode.svnrepository.com/ruby_pdf/trac.cgi/wiki">PDF::Writer</a> library, which I described in detail in a <a title="bug report" href="http://stonecode.svnrepository.com/ruby_pdf/trac.cgi/ticket/18">bug report</a> on the PDF::Writer site. On the mailing list this was confirmed as a known bug.</p>
<p>Because I needed a solution I decided to have a look at the Ruby port of the well known <a href="http://www.fpdf.org">PHP library FPDF</a>, which is called <a title="Ruby FPDF" href="http://zeropluszero.com/software/fpdf/">Ruby FPDF</a> by Olivier Plathey.</p>
<p>Justification works fine there, but there is no solution built in the base FPDF library to have justification with formatted text (some words in a flowing text which are bold, italic, have other font sizes, etc.). But there is a nice <a href="http://www.fpdf.de/downloads/addons/65/">&#8220;flowing block&#8221; module</a> by Damon Kohler for the PHP version of FPDF, which solves exactly this problem.</p>
<p>So I decided to to a Ruby port by my own, which is what I did and what I hope that you find useful as well. Here is an example how to use it:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'flowing_block'</span>
&nbsp;
pdf = PDF.<span style="color:#9900CC;">new</span>
&nbsp;
pdf.<span style="color:#9900CC;">AddPage</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">newFlowingBlock</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006666;">40</span>, <span style="color:#006666;">6</span>, <span style="color:#006666;">0</span>, <span style="color:#996600;">'L'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">SetFont</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Helvetica'</span>, <span style="color:#996600;">'B'</span>, <span style="color:#006666;">8</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">WriteFlowingBlock</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Bonjour Martin!'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">finishFlowingBlock</span>
&nbsp;
pdf.<span style="color:#9900CC;">newFlowingBlock</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006666;">40</span>, <span style="color:#006666;">6</span>, <span style="color:#006666;">0</span>, <span style="color:#996600;">'J'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">SetFont</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Helvetica'</span>, <span style="color:#996600;">'B'</span>, <span style="color:#006666;">16</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">WriteFlowingBlock</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Hello '</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">SetFont</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Helvetica'</span>, <span style="color:#996600;">'I'</span>, <span style="color:#006666;">8</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">WriteFlowingBlock</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'World! '</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">SetFont</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Times'</span>,<span style="color:#996600;">''</span>,<span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">WriteFlowingBlock</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'This is a test of the flowing block script.'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">SetTextColor</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">255</span>, <span style="color:#006666;">0</span>, <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>;  <span style="color:#008000; font-style:italic;"># red color.. ;-)</span>
pdf.<span style="color:#9900CC;">SetFont</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Helvetica'</span>, <span style="color:#996600;">'B'</span>, <span style="color:#006666;">12</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">WriteFlowingBlock</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Rot! '</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">SetTextColor</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0</span>, <span style="color:#006666;">255</span>, <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>;  <span style="color:#008000; font-style:italic;"># green color.. ;-)</span>
pdf.<span style="color:#9900CC;">SetFont</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Helvetica'</span>,<span style="color:#996600;">''</span>,<span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">WriteFlowingBlock</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">' of this should be justified correclty. It is sooooo amazing!! It is sooooo amazing!! It is sooooo amazing!! '</span><span style="color:#006600; font-weight:bold;">&#41;</span>
pdf.<span style="color:#9900CC;">finishFlowingBlock</span>
&nbsp;
pdf.<span style="color:#9900CC;">Output</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'test.pdf'</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>I have put the Ruby FPDF library and the flowing block extension in ZIP-File which can be downloaded <a href="http://www.martinonrails.com/code/flowing_block.zip">here</a>.</p>
<p>Please have in mind that I am a Ruby beginner and that it&#8217;s very likely that there are lots of bugs in it. It&#8217;s also a matter of fact that the port is pretty ugly, mainly because I did not know a Ruby equivalent for the PHP pointer like =&amp; operator. (If somebody knows how one can do that in Ruby, please post a comment!).</p>
<p>So if you find a bug or a solution how to improve the code please do so &#8211; I will gladly post the update here!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.martinonrails.com/2008/04/03/justification-problem-with-pdf-generators/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Riding on Rails&#8230;</title>
		<link>http://www.martinonrails.com/2008/04/03/riding-on-rails/</link>
		<comments>http://www.martinonrails.com/2008/04/03/riding-on-rails/#comments</comments>
		<pubDate>Fri, 04 Apr 2008 00:18:25 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Blog related]]></category>

		<guid isPermaLink="false">http://www.martinonrails.com/?p=4</guid>
		<description><![CDATA[I am new to Ruby and Ruby on Rails in particular and found out that it&#8217;s often easier the find answers to the complicated questions that to the easy ones. So I decided to start a blog about my ups and downs I am experiencing riding on Rails.. May the force of the chunky bacon [...]]]></description>
			<content:encoded><![CDATA[<p>I am new to Ruby and Ruby on Rails in particular and found out that it&#8217;s often easier the find answers to the complicated questions that to the easy ones. So I decided to start a blog about my ups and downs I am experiencing riding on Rails..</p>
<p>May the force of the <a href="http://www.chunkybacon.com">chunky bacon</a> be with this blog!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.martinonrails.com/2008/04/03/riding-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

