Permalink
Browse files

PDF generation demo with iText

  • Loading branch information...
1 parent 96831bd commit a5df2eb2862d95a7e659b7606635aafb9da44048 @BanzaiMan committed Dec 4, 2010
Showing with 16 additions and 0 deletions.
  1. +15 −0 app/controllers/users_controller.rb
  2. +1 −0 config/initializers/mime_types.rb
  3. BIN lib/iText-5.0.5.jar
@@ -46,6 +46,21 @@ def show
svg_gen.stream(out, true)
render :inline => out.to_string
}
+
+ format.pdf {
+ require 'iText-5.0.5'
+ pdf = com.itextpdf.text.Document.new
+ para = com.itextpdf.text.Paragraph.new "Hello #{@user.name}"
+ file = "#{::Rails.root.to_s}/tmp/pdfs/pdf_demo.pdf" # not very secure
+ out = java.io.FileOutputStream.new file
+
+ com.itextpdf.text.pdf.PdfWriter.get_instance pdf, out
+ pdf.open
+ pdf.add para
+ pdf.close
+
+ render :file => file
+ }
end
end
@@ -5,3 +5,4 @@
# Mime::Type.register_alias "text/html", :iphone
Mime::Type.register 'image/svg+xml', :svg
+Mime::Type.register 'application/pdf', :pdf
View
Binary file not shown.

0 comments on commit a5df2eb

Please sign in to comment.