<?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>Meta Bates &#187; pdf</title>
	<atom:link href="http://www.metabates.com/tag/pdf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.metabates.com</link>
	<description>The technical ramblings of Mark Bates.</description>
	<lastBuildDate>Wed, 01 Feb 2012 16:25:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Why so quiet?</title>
		<link>http://www.metabates.com/2008/06/23/why-so-quiet/</link>
		<comments>http://www.metabates.com/2008/06/23/why-so-quiet/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 18:00:10 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[data mapper]]></category>
		<category><![CDATA[haml]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mack]]></category>
		<category><![CDATA[markaby]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[rjs]]></category>

		<guid isPermaLink="false">http://www.mackframework.com/?p=107</guid>
		<description><![CDATA[I&#8217;m sure everyone is wondering why things have been so quiet around the Mack front recently. Well, there are a couple of reasons. One, I&#8217;m on vacation in Ireland right now, so my coding time has dropped dramatically. Second, I&#8217;m still very much so patiently awaiting the 0.9.2 release of DataMapper, which the next version [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sure everyone is wondering why things have been so quiet around the Mack front recently. Well, there are a couple of reasons. One, I&#8217;m on vacation in Ireland right now, so my coding time has dropped dramatically. Second, I&#8217;m still very much so patiently awaiting the 0.9.2 release of DataMapper, which the next version of Mack needs. Third, there is a lot of Mack work afoot at the moment.</p>
<p>The company I work has seen fit to give me a few more resources to help me make Mack the most kick ass framework out there. I&#8217;ve not got 1.5 more bodies diligently working away on Mack, with another body to hopefully be hired in the next full weeks. That will mean, within a few weeks there will be 3.5 full time bodies working on Mack! Awesome!</p>
<p>There are some great things that are going to be in the next build, but mostly it&#8217;ll be a nice refactoring. We&#8217;re going to splitting a bunch of stuff out of the core of Mack and putting into a mack-more package, similar to the approach Merb and DataMapper have adopted. In mack-more there will be l10n internationalization, RJS support (Prototype AND jQuery), DataMapper 0.9.x support, HAML, Markaby, PDF::Writer support, amongst others. It&#8217;ll be nice. Trust me. <img src='http://www.metabates.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>We hope to have the next release out within the first or second week of July, of course, this really depends on when the DataMapper release can get out there. Once we get this release out, we can really focus on some extremely kick ass new features. Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2008/06/23/why-so-quiet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preview (0.5.5): Adding PDF::Writer Plugin Support Tutorial</title>
		<link>http://www.metabates.com/2008/05/20/055-adding-pdfwriter-plugin-support-tutorial/</link>
		<comments>http://www.metabates.com/2008/05/20/055-adding-pdfwriter-plugin-support-tutorial/#comments</comments>
		<pubDate>Tue, 20 May 2008 20:45:27 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[engine]]></category>
		<category><![CDATA[erubis]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[mack]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[render]]></category>
		<category><![CDATA[rendering]]></category>

		<guid isPermaLink="false">http://www.mackframework.com/?p=99</guid>
		<description><![CDATA[Ok, let&#8217;s take the new rendering system out for a spin, shall we? Let&#8217;s add the PDF::Writer library to our Obligatory Blog Demo application. If you haven&#8217;t followed this demo you should do that now. Let&#8217;s start by requiring the gem in our system. Open up your gems.rb file found in config/initializers and let&#8217;s add [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, let&#8217;s take the new rendering system out for a spin, shall we? Let&#8217;s add the PDF::Writer library to our Obligatory Blog Demo application. If you haven&#8217;t followed this demo you should do that <a href="http://www.mackframework.com/2008/04/18/046-the-obligatory-blog-demo-take-2/" target="_blank">now</a>.</p>
<p>Let&#8217;s start by requiring the gem in our system. Open up your gems.rb file found in config/initializers and let&#8217;s add the gem:</p>
<pre>require_gems do |gem|
  gem.add "pdf-writer", :version =&gt; "1.1.8", :libs =&gt; "pdf/writer"
end</pre>
<p>Great! We&#8217;ve told Mack we want to use the &#8216;pdf-writer&#8217; gem, version &#8217;1.1.8&#8242;, and we want to automatically require the file &#8216;pdf/writer&#8217;. Now, let&#8217;s install the gem:</p>
<pre>$ sudo rake gems:install</pre>
<p>See how easy this is? We&#8217;ve installed the gem, required the libraries, now we&#8217;re ready to write our plugin.</p>
<pre>$ rake generate:plugin name=render_pdf</pre>
<p>That should generate a few files/folders in our vendor/plugins directory. Let&#8217;s open up vendor/plugins/render_pdf/lib/render_pdf.rb and let&#8217;s start coding.</p>
<p>What we want to do is create a new Mack::Rendering::Engine::Base class so that when we call render(:action) it will have a new engine to render the view file as a PDF.</p>
<p>We&#8217;ll examine each section in a minute, but for now, let&#8217;s type this into our render_pdf.rb file:</p>
<pre>module Mack
  module Rendering
    module Engine
      class Pdf &lt; Mack::Rendering::Engine::Base

        def render(io, binding)
          @_pdf = ::PDF::Writer.new
          self.view_template.instance_variable_set("@_pdf", @_pdf)
          eval(io, binding)
          @_pdf.render
        end

        def extension
          :pdfw
        end

        module ViewHelpers
          def pdf
            @_pdf
          end
        end

      end
    end
  end
end
Mack::Rendering::ViewTemplate.send(:include, Mack::Rendering::Engine::Pdf::ViewHelpers)
Mack::Rendering::Engine::Registry.register(:action, :pdf)</pre>
<p>Ok, so on line #4 we extended Mack::Rendering::Engine::Base. This will give us access to a view methods, and will allow us to write to a very simple API. The only method you are <em>absolutely</em> required to implement is the render method. As we can see on line #6, we did just that.</p>
<p>First thing we do in the render method is instantiate a new PDF::Writer class and assign it to an instance variable. We then set that instance variable into the Mack::Rendering::ViewTemplate object we have. We do that because the way the PDF::Writer object works you need to constantly reference the instance of the writer to do your work. Example:</p>
<pre>@_pdf.text "Hello World", :font_size =&gt; 24, :justification =&gt; :center</pre>
<p>On line #9 we eval the io and the binding we&#8217;ve been given. The io will be contents of the view file we have disk, as a String, and the binding will be that of the Mack::Rendering::ViewTemplate object we&#8217;ve been given.</p>
<p>In the extension method we tell the system that are files are going to be found with the extension, pdfw. Another example of this would be the Erubis engine which declares its extension as erb.</p>
<p>The Mack::Rendering::Engine::Pdf::ViewHelpers module we&#8217;ve declared on line #17 is there to hide the @_pdf instance variable with a nicer pdf method. On line #27 we include this module into Mack::Rendering::ViewTemplate so it has access to it.</p>
<p>Finally, and most importantly, we need to register the new engine we&#8217;ve built with the system. We do that on line #28 with this bit of code:</p>
<pre>Mack::Rendering::Engine::Registry.register(:action, :pdf)</pre>
<p>That&#8217;s saying whenever someone calls render(:action), consider me as an engine to render that. The way the selection of which engine to use is done, is very simple. First come first serve. The engines are in an array, and the first one to have a file with its extension on disk wins. Plain and simple.</p>
<p>Now, let&#8217;s see all this in action. Let&#8217;s add PDF support for our &#8216;show&#8217; page.</p>
<p>Open up views/posts/show.html.erb and add the following line:</p>
<pre>&lt;%= link_to("pdf", posts_show_url(:id =&gt; @post, :format =&gt; :pdf)) %&gt;</pre>
<p>That will give us a link that looks like &#8216;/posts/:id.pdf&#8217;. This will, of course, go to our PostsController and the show action. This method does not need to be altered. That&#8217;s right, you heard me. It does not need to change. Mack will handle the appropriate content-type headers for you. Just another great feature in 0.5.5.</p>
<p>Create a file called views/posts/show.pdf.pdfw. I know this might look a little weird, what with &#8216;pdf.pdfw&#8217;, but here&#8217;s the reason why. That&#8217;s break the file name down into its three parts. &#8216;show&#8217; is the name of the action. &#8216;pdf&#8217; is the format of the request, think also html, xml, etc&#8230; &#8216;pdfw&#8217; is the engine we want to use. If we hated ourselves we could do this all in erb with a file called show.pdf.erb, but why would we want to do that?</p>
<p>Anyway, let&#8217;s dump this nice block of code into our show.pdf.pdfw file:</p>
<pre>pdf.select_font "Times-Roman"
pdf.fill_color(Color::RGB::Red)
pdf.text @post.title, :font_size =&gt; 24, :justification =&gt; :center
pdf.fill_color(Color::RGB::Black)
pdf.text "by #{@post.email}", :font_size =&gt; 12, :justification =&gt; :center
pdf.with_options(:font_size =&gt; 10, :justification =&gt; :left) do |p|
  p.text "\n\n"
  p.text @post.body
  p.text "\n\n"
  p.text "Created at: #{@post.created_at}"
  p.text "Updated at: #{@post.updated_at}"
end</pre>
<p>Since this is not a tutorial on this particular gem, I&#8217;m not going to go into what all that does. Instead, let&#8217;s just have a look at it in action.</p>
<p>Fire up your server:</p>
<pre>$ rake server</pre>
<p>And go to: http://localhost:3000. If you don&#8217;t already have a post created, create one. Now click on the show link. You should have a link on your page that says &#8216;pdf&#8217; click on that link. Voila! You should be seeing a wonderfully formatted PDF right now!</p>
<p>Congrats! You&#8217;ve built a plugin and a new rendering engine for Mack. Now, go crazy!</p>
<p>The source for all this can be found at:Â <a href="http://github.com/markbates/mack_blog_demo/tree/master" target="_blank">http://github.com/markbates/mack_blog_demo/tree/master</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2008/05/20/055-adding-pdfwriter-plugin-support-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Release 0.2.0</title>
		<link>http://www.metabates.com/2008/03/11/release-020/</link>
		<comments>http://www.metabates.com/2008/03/11/release-020/#comments</comments>
		<pubDate>Tue, 11 Mar 2008 20:47:30 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Releases]]></category>
		<category><![CDATA[Updates]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[mack]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[render]]></category>

		<guid isPermaLink="false">http://www.mackframework.com/2008/03/11/release-020/</guid>
		<description><![CDATA[A couple of really cool features in this release. In controllers and views you canÂ  now call: render(:url=&#62; "http://www.mycoolurl.com") Developers can now also develop their own custom rendering systems, without monkey patching the core: class Mack::Rendering::Pdf &#60; Mack::Rendering::Base def render # do work to render stuff as a PDF end end Now add this to [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of really cool features in this release. In controllers and views you canÂ  now call:</p>
<pre>render(:url=&gt; "http://www.mycoolurl.com")</pre>
<p>Developers can now also develop their own custom rendering systems, without monkey patching the core:</p>
<pre>class Mack::Rendering::Pdf &lt; Mack::Rendering::Base
  def render
    # do work to render stuff as a PDF
  end
end</pre>
<p>Now add this to the list of available render systems:</p>
<pre>app_config.mack.rendering_systems &lt;&lt; :pdf</pre>
<p>You should now be able to do this in your controller:</p>
<pre>class MyAwesomeController &lt; Mack::Controller::Base
  def pdf
    render(:pdf =&gt; "my_pdf_template")
  end
end</pre>
<p>Install:</p>
<pre>$ sudo gem install mack</pre>
<p>Changelog:</p>
<ul>
<li>ticket: <a href="http://trac.mackframework.com/ticket/3" target="_blank">3</a> Render url in Controllers/Views</li>
<li>ticket: <a href="http://trac.mackframework.com/ticket/5" target="_blank">5</a> Render Extension System.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2008/03/11/release-020/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.365 seconds -->

