Skip to content

Instantly share code, notes, and snippets.

@TheNicholasNick
Created May 22, 2009 03:49
Show Gist options
  • Save TheNicholasNick/115916 to your computer and use it in GitHub Desktop.
Save TheNicholasNick/115916 to your computer and use it in GitHub Desktop.
# is there a "proper" way to do this?
# I want to return a pdf via prince if it is a pdf requested
# Otherwise return html reponse
class RefCove < Application
def show(id, cove_id)
provides :pdf, :html
@cove = Cove.get(cove_id)
raise NotFound if @cove.nil?
return display @cove unless params[:format].eql?("pdf")
html_string = render("", {:format => :html, :template => "pdf/int", :layout => "pdf"})
html_string.gsub!("src=\'", "src=\'#{Merb.root}/public")
prince = Prince.new()
prince.add_style_sheets("#{Merb.root}/public/stylesheets/pdf.css")
prince.add_style_sheets("#{Merb.root}/public/stylesheets/prince.css")
headers.update(
"Content-Type" => "application/pdf",
"Content-Transfer-Encoding" => "binary"
)
prince.pdf_from_string(html_string)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment