Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

PDF generation demo with iText

  • Loading branch information...
commit a5df2eb2862d95a7e659b7606635aafb9da44048 1 parent 96831bd
@BanzaiMan authored
View
15 app/controllers/users_controller.rb
@@ -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
View
1  config/initializers/mime_types.rb
@@ -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
BIN  lib/iText-5.0.5.jar
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.