<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4215883606892138906</id><updated>2012-02-16T02:12:05.924-08:00</updated><category term='acts_as_flying_saucer'/><category term='haml'/><category term='erb'/><category term='wicked_pdf'/><category term='pdfkit'/><category term='pdf'/><title type='text'>Param On Rails</title><subtitle type='html'>Ruby On Rails and Web Development Articles</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://iparamtech.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4215883606892138906/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://iparamtech.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>param</name><uri>http://www.blogger.com/profile/18003712092687148540</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4215883606892138906.post-6009943162923857373</id><published>2011-09-29T01:19:00.000-07:00</published><updated>2011-09-29T02:38:46.827-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='wicked_pdf'/><category scheme='http://www.blogger.com/atom/ns#' term='haml'/><category scheme='http://www.blogger.com/atom/ns#' term='erb'/><category scheme='http://www.blogger.com/atom/ns#' term='pdf'/><category scheme='http://www.blogger.com/atom/ns#' term='pdfkit'/><category scheme='http://www.blogger.com/atom/ns#' term='acts_as_flying_saucer'/><title type='text'>Generate PDF using Erb or HAML and pdfkit</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;In my current work i want to generate pdf and pre store into my application and whenever user wants to download pdf user can download pdf easily. I can't generate pdf on the fly because of some limitation.&lt;br /&gt;&lt;br /&gt;Previously we are using prawn but as complexity increases and time decreases we started looking into another solution, we came across mainly &lt;a href="https://github.com/jdpace/PDFKit"&gt;pdfkit&lt;/a&gt;,&lt;a href="https://github.com/mileszs/wicked_pdf"&gt;wicked_pdf&lt;/a&gt;,&lt;a href="https://github.com/amardaxini/acts_as_flying_saucer"&gt;acts_as_flying_saucer&lt;/a&gt; library.&lt;br /&gt;&lt;br /&gt;We initially started with &lt;b&gt;pdfkit&lt;/b&gt; to test our need it full fill majority all requirement,but as i say i want to generate PDF and store into my rails app.So it is easy to generate from &lt;b&gt;HTML&lt;/b&gt; but we need to generate &lt;b&gt;PDF&lt;/b&gt; from &lt;b&gt;erb &lt;/b&gt;template (HAML can also work) in backend.&lt;br /&gt;&lt;br /&gt;Basically&amp;nbsp; it is 3 step process&lt;br /&gt;&lt;ol style="text-align: left;"&gt;&lt;li&gt;Read &lt;b&gt;ERB(Haml,...) &lt;/b&gt;file and store into &lt;b&gt;string.&lt;/b&gt;&lt;/li&gt;&lt;li&gt; &lt;b&gt;Parse file&lt;/b&gt; using &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/"&gt;erb&lt;/a&gt; with necessary parameter.&lt;/li&gt;&lt;li&gt; &lt;b&gt;Generate PDF &lt;/b&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;So i am sharing my small idea it works for me.&lt;br /&gt;&lt;pre class="ruby" name="code"&gt;require 'rubygems'&lt;br /&gt;require 'pdfkit'&lt;br /&gt;require 'erb'&lt;br /&gt;&lt;br /&gt;# Read ERB File&lt;br /&gt;&amp;nbsp; content = File.read('path/of/erb/template')&lt;br /&gt;# Create new ERB template by passing required variable&lt;br /&gt;&amp;nbsp;template = ERB.new(content)&lt;br /&gt;# Create new object to PDFKIt&lt;br /&gt;&amp;nbsp;kit = PDFKIT.new(template.result(binding))&lt;br /&gt;# Save into PDF &lt;br /&gt;&amp;nbsp;file = kit.to_file('/path/to/save/pdf')&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="border-collapse: separate; color: black; font-family: 'Times New Roman'; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 14px;"&gt;&lt;pre&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;We can set configuration for pdfkit and erb as per our requirement.&amp;nbsp;&amp;nbsp;&lt;br /&gt;I hope this is helpful,if any other way we can generate PDF kindly share it.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4215883606892138906-6009943162923857373?l=iparamtech.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iparamtech.blogspot.com/feeds/6009943162923857373/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://iparamtech.blogspot.com/2011/09/generate-pdf-using-erb-or-haml-and.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4215883606892138906/posts/default/6009943162923857373'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4215883606892138906/posts/default/6009943162923857373'/><link rel='alternate' type='text/html' href='http://iparamtech.blogspot.com/2011/09/generate-pdf-using-erb-or-haml-and.html' title='Generate PDF using Erb or HAML and pdfkit'/><author><name>param</name><uri>http://www.blogger.com/profile/18003712092687148540</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
