To generate PDF reports there's also *RGhost*. It's a gem (also available as a rails plugin) that wraps PostScript with pure Ruby syntax. The gem is very stable and tested with reports over 1k pages in various OS's. The downside is that you need ghostscript libs installed.
More info: "RGhost[Rubyforge]":http://rubyforge.org/projects/rghost/
I must agree with others, your screencasts are really top notch. Keep up the good work!
Regarding this one, I have one question, but it is not about writing pdf documents - I want to read and parse pdf. Is there some useful gem/plugin available for this kind of stuff? I've looked around but without any success. I would really appreciate any tip or recommendation on how to get into pdf parsing with ruby/rails.
i tried to work with PDF::Writer in the last weeks, and i have to say that RGhost looks really good, but do you know about some translation, because http://rghost.rubyforge.org/doc/ looks english but is in fact Portuguese...
Or does anybody has some short sample apps to build on???
2nd,
maybe you want to share your experience using other pdf-writing-tools(gems) in some words, which you mentioned to be not as easy as this one, but better.
(Additional Links in the resources of this episode would be enough)
3rd,
with the new rails (upcoming versions) you can put your mimetypes in a separate file in the folder 'configuration/initializers' which is called 'mime_types' and for example put the 'require'-stuff in a seperate file 'requirements.rb' to keep your envirements.rb file clean (no changes)
I've got a Rails app that I'll be adding PDF generation to soon. I've collected some links to various blog entries and tutorials. Maybe others will find them useful.
A cool extension to this would be to also generate a flash paper doc. I'm not sure of the exact implementation, but I know a lot of the social document sharing services are doing this. That way the doc can be viewed in the browser rather than needing a separate app.
Out of those PDF::Writer was by far my favorite so I've stuck with it and haven't had any complaints. I should look into some more newer options though (RGhost).
@Paul, for simple PDFs I think a template view would work really well, but most of the PDFs I've done get fairly complex. In those cases it helps having an actual object with methods and variables.
I tried out the PDF:Writer a while ago. One thing that bothered me is that it does not support Unicode. There is a hack to make it work with some European languages (documented in the rails wiki). However, Asian languages, Arabic, and so on are not supported. And since I read that Austin Ziegler isn't working on the PDF:Writer project any more there doesn't seem to be too much hope that this will change soon. Or does any one have new info on that?
Hi Ryan,
very nice railscast! This Railcast was very interesting.
A time extended episode about the formating seaction would be great to learn more about layout development (is this so far supported in the writer?).
In general an extend version of PDF:Writer with UTF-8 or international support planned yet?
Could this also be done easily in Ruby (asked from a beginner point of view)?
I would like to implement a PDF function into my application.
I have already installed the pdf-writer-1.1.6.
Firstly, there are several folders in this zip folder e.g. pdf, writer etc.
Where exactly should I paste this folders to?
Secondly, I added the following codes to the environment.rb:
require 'pdf/writer'
Mime:Type.register 'application/pdf',:pdf
Where should I place these codes and the should the word "application" be replaced with my project's name?
I am sure that there is something wrong with the codes in here as when i restarted WEBRICK in my command prompt, some of the errors that occurred are:
- already initialized constant OPTIONS
-no such file to load -- transaction/simple<MissingSourceFile>
Can someone please give me a solution? Because there is no way I can implement the codes if I cannot start my WEBrick successfully.
This is quite urgent as the deadline is drawing nearer. Please help!
Thank you very much!!!
@Valerie:
1. Install by gems (not from source) - it should be a command line tools but in netbeans/eclipse plugins you have GUI
2. 'application/pdf' is mime type
Is passing instance variables as arguments the only way to get instance variables into in the drawer method? I have a controller that collects/calculates a lot of information destined for output as rhtml or pdf.
Any tips or URLs I could follow would be appreciated.
I used rfpdf since pdf-writer did not go together with activescaffold (+activescaffoldlocalize +calendar_date_select). Be sure to pick the right plugin (http://code.google.com/p/rfpdf/source/checkout), since there are two.
Scott, Justin -> I get the same problem and fixed it.
If you look in action_controller/mime_type
you'll see that the file has a require at the bottom of it - I assume to 'self -include... er... itself. I'm guessing (haven't done a bug search) at some point someone renamed the file from types to type (dropping the s) and didn't update the 'require' bit. I fixed it in mine by adding
require 'action_controller/mime_type'
before the
Mime::Type.register 'application/pdf', :pdf
require 'pdf/writer'
in my environment.rb file.
I upgraded an app that I'm working on from rails 2.1.2 to 2.2.2 and now my rtex pdf generation does not work. It appears that the latex file is never run through the processor so no PDF is every created, you just get the latex file with a .pdf extension.
I just wanted to say that the pdf writer is very nice, the only complain I have is that when I tried to create a table with 2000 rows it took more than 15 minutes to render the report, which kind of sucks. Am I doing something wrong?
_p = PDF::Writer.new(:orientation => :landscape)
_p.select_font 'Times-Roman'
PDF::SimpleTable.new do |tab|
tab.title_font_size = 10
tab.heading_font_size = 8
tab.font_size = 8
tab.width = 700
tab.orientation = :center
tab.title = "#{@report.name} as of " + (Time.now()).strftime("%a %b %d, %Y")
tab.column_order = @results.first.attribute_names
#Rename Columns
@results.first.attribute_names.each do |mykey|
tab.columns[mykey] = PDF::SimpleTable::Column.new(mykey) { |col| col.heading = mykey.slice(6..-1) }
end
tab.data = @results
tab.render_on(_p)
end
send_data _p.render, :filename => "#{@report.name}.pdf", :type => "application/pdf"
Hi Ryan
Iam using rails 2.3.2.Whrn i run http://localhost:3000/att.pdf
It is giving following error:
No route matches "/att.pdf" with {:method=>:get}
In routes.rb i have
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
map.connect ':controller/:action.:format'
please help me why iam getting this error
The code is written in AttendenceReport index method.
when in run
http://localhost:3000/attendence_report/att.pdf
then it is giving error:
No action responded to att. Actions: index
and index working properly.help me
I have the same error of sravanthi, when I call 127.0.0.1:3000/makepdf/13.pdf I get this: Missing template makepdf/show.erb . In MakepdfController I have
def show
@asset = Asset.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @asset }
format.pdf { render :layout => false }
end
end
any hint?
WOWWWWWW, I spend all the morning looking for something like this!, don't get me wrong!, but I think I'm starting to loving YOU!!!!!(LOL!) THANKS A LOT!!!!!!!!!!!
Where should be payin_drawer.rb (previously product_drawer.rb)
be located in the project framework ?
LoadError in PayinsController#index
Unable to autoload constant PayinDrawer, expected C:/RubymineProjects/pms4mysql/app/pdfs/payin_drawer.rb to define it
I just had to say "W00000000T!"
Hi Ryan!
To generate PDF reports there's also *RGhost*. It's a gem (also available as a rails plugin) that wraps PostScript with pure Ruby syntax. The gem is very stable and tested with reports over 1k pages in various OS's. The downside is that you need ghostscript libs installed.
More info: "RGhost[Rubyforge]":http://rubyforge.org/projects/rghost/
Hello Ryan,
I must agree with others, your screencasts are really top notch. Keep up the good work!
Regarding this one, I have one question, but it is not about writing pdf documents - I want to read and parse pdf. Is there some useful gem/plugin available for this kind of stuff? I've looked around but without any success. I would really appreciate any tip or recommendation on how to get into pdf parsing with ruby/rails.
Thanks and best regards!
Hello Marcello,
i tried to work with PDF::Writer in the last weeks, and i have to say that RGhost looks really good, but do you know about some translation, because http://rghost.rubyforge.org/doc/ looks english but is in fact Portuguese...
Or does anybody has some short sample apps to build on???
Thanks
René
Hi Ryan,
1st,
thx for this one, just great as always.
2nd,
maybe you want to share your experience using other pdf-writing-tools(gems) in some words, which you mentioned to be not as easy as this one, but better.
(Additional Links in the resources of this episode would be enough)
3rd,
with the new rails (upcoming versions) you can put your mimetypes in a separate file in the folder 'configuration/initializers' which is called 'mime_types' and for example put the 'require'-stuff in a seperate file 'requirements.rb' to keep your envirements.rb file clean (no changes)
4th,
keep going ^^
There is nothing excellent about the PDF::Writer stuff... right now.
The Ruports[1] guys have just taken this over, and hopefully they make it the awesome package is could be.
1: http://www.rubyreports.org
Thanks for the (as always) well-done screencast!
I've got a Rails app that I'll be adding PDF generation to soon. I've collected some links to various blog entries and tutorials. Maybe others will find them useful.
http://del.icio.us/tjstankus/pdf
Any thoughts on the rails PDF plugin?
http://railspdfplugin.rubyforge.org
Seems a lot cleaner to me to use an .rpdf view than putting a "Drawer" class in lib.
A cool extension to this would be to also generate a flash paper doc. I'm not sure of the exact implementation, but I know a lot of the social document sharing services are doing this. That way the doc can be viewed in the browser rather than needing a separate app.
Hi Brian,
Flash paper is mostly generated via printing method not authored per se.
we have build a rails app urwords.com which uses it that way.
you can contact us in case you need any help
Anybody got an idea how to generate a google map in PDF?
@Marcello, I haven't tried RGhost yet. I'll have to look into it. Thanks for the suggestion!
@QuBit, a while ago I tried most of the options mentioned on this wiki page:
http://wiki.rubyonrails.org/rails/pages/HowtoGeneratePDFs
Out of those PDF::Writer was by far my favorite so I've stuck with it and haven't had any complaints. I should look into some more newer options though (RGhost).
@Paul, for simple PDFs I think a template view would work really well, but most of the PDFs I've done get fairly complex. In those cases it helps having an actual object with methods and variables.
cool~thx.
and can anybody share somethings about “how to genarate reports chart in rails".
I tried out the PDF:Writer a while ago. One thing that bothered me is that it does not support Unicode. There is a hack to make it work with some European languages (documented in the rails wiki). However, Asian languages, Arabic, and so on are not supported. And since I read that Austin Ziegler isn't working on the PDF:Writer project any more there doesn't seem to be too much hope that this will change soon. Or does any one have new info on that?
@jurglic,
FYI i just came across this... http://software.pmade.com/pdfreader
Looks like it was started in October but couldnt really find anything else on the net for reading PDFs.
你的英语讲的很好,内容也不错,我们很喜欢!
但是,有点小遗憾,就是有些东西讲的太少了.
我看过layout那部分,partial那部分没有涉及到!
Hi iceskysl, for charts I think you could use this:
http://elctech.com/2007/9/7/swfchart-generator
I didn't try it but like the results. It uses http://www.maani.us/xml_charts/index.php?menu=Gallery
which can be controlled also via PHP.
Nik
@rene and Ryan:
The translation is underway. At least the pdf manual shall be ready by the ende of the week. The code soon follows. =)
@Marcello:
this would be really great. Thanks a lot for your efforts!!!
@Nik:
your are so kind~
that's cool~
thx~
Hi Ryan,
Thanks, your screencasts, just great as always!
I wonder why you use the ProductDrawer class in lib. Why don't you use a method in the Product Model?
Thank you so much for your great screencasts! Very inspiring and informative and quite entertaining as well:-)
I ran into problems with the encoding of German Umlaute characters, such as "äöüÄÖUß" with PDF::Writer.
I have my source code encoded in UTF-8 and PDF::Writer cannot yet display UTF-8 characters.
A great solution is to overwrite PDF::Writer's text method and have it convert the text from UTF-8 to ISO-8859-15, like so:
CONVERTER = Iconv.new( 'ISO-8859-15//IGNORE//TRANSLIT', 'utf-8')
module PDF
class Writer
alias_method :old_text, :text
def text(textto, options = {})
old_text(CONVERTER.iconv(textto), options)
end
end
end
All credits go to Peter Krantz and Anibal. See http://www.peterkrantz.com/2007/utf8-in-pdf-writer/
Hi Ryan,
very nice railscast! This Railcast was very interesting.
A time extended episode about the formating seaction would be great to learn more about layout development (is this so far supported in the writer?).
In general an extend version of PDF:Writer with UTF-8 or international support planned yet?
Could this also be done easily in Ruby (asked from a beginner point of view)?
Excellent...EXCELLENT....*rasps fingers*
Hi,
I would like to implement a PDF function into my application.
I have already installed the pdf-writer-1.1.6.
Firstly, there are several folders in this zip folder e.g. pdf, writer etc.
Where exactly should I paste this folders to?
Secondly, I added the following codes to the environment.rb:
require 'pdf/writer'
Mime:Type.register 'application/pdf',:pdf
Where should I place these codes and the should the word "application" be replaced with my project's name?
I am sure that there is something wrong with the codes in here as when i restarted WEBRICK in my command prompt, some of the errors that occurred are:
- already initialized constant OPTIONS
-no such file to load -- transaction/simple<MissingSourceFile>
Can someone please give me a solution? Because there is no way I can implement the codes if I cannot start my WEBrick successfully.
This is quite urgent as the deadline is drawing nearer. Please help!
Thank you very much!!!
@Valerie:
1. Install by gems (not from source) - it should be a command line tools but in netbeans/eclipse plugins you have GUI
2. 'application/pdf' is mime type
Thanks! Error occurred...
undefined method `formatted_programmes_path'
Seriously, I don't see where i should define this.
hi, i am using pdf:writer with attachment_fu and when i am trying to load an image into the pdf like so.
avatar = @villa.avatar.public_filename()
pdf = PDF::Writer.new(:paper => "A4")
pdf.select_font "Helvetica"
pdf.image avatar, :resize => 0.75
but all i get is an error.
"No such file or directory - /avatars/0000/0007/1.jpg"
so whats wrong here?
thx for the great screencast :)
Thanks for the screencast.
Is passing instance variables as arguments the only way to get instance variables into in the drawer method? I have a controller that collects/calculates a lot of information destined for output as rhtml or pdf.
Any tips or URLs I could follow would be appreciated.
Thanks again.
Great screencast.
But I get this error:
Routing Error
no route found to match "/reporting/index.pdf" with {:method=>:get}
Can you help me?
regards
svend
@svend:
I am working on a rails 1.2.6 app that does not use RESTful routing. To get this to work for me, I added the following to routes.rb:
map.connect ':controller/:action.:format'
Check out the above link for Extremely Simple PDF Generation in Rails using HTMLDOC
Hi,
I wonder how i get an error " undefined method `pdf'". I think I follow all you stpes.
thanks
wing
I used rfpdf since pdf-writer did not go together with activescaffold (+activescaffoldlocalize +calendar_date_select). Be sure to pick the right plugin (http://code.google.com/p/rfpdf/source/checkout), since there are two.
Now RGhost 0.8 with English Documentation. For PDF, PS, TIF, etc
The Ghost's speed!!
see http://rghost.rubyforge.org
Hi, this looks great. Trying it out, but encountered an error:
uninitialized constant Mime::PDF
...
require "pdf/writer"
Mime::Type.register 'application/pdf', :pdf
...
...
format.pdf do
pdf = PDF::Writer.new
pdf.text "test"
send_data pdf.render, :filename => 'threads.pdf', :type => 'application/pdf', :disposition=> 'inline'
...
end
Thanks for any help!
Justin,
I am having the same problem suddenly. It seems related to using ruby enterprise instead of normal ruby. It's the only thing I've recently changed.
Anyone else notice it being related to Ruby Enterprise?
Awesome railcast!!
Do you have any idea's on generating spreadsheet documents?
Thanks so much!
rugger
Hi, great tutorial - keep them coming!
Scott, Justin -> I get the same problem and fixed it.
If you look in action_controller/mime_type
you'll see that the file has a require at the bottom of it - I assume to 'self -include... er... itself. I'm guessing (haven't done a bug search) at some point someone renamed the file from types to type (dropping the s) and didn't update the 'require' bit. I fixed it in mine by adding
require 'action_controller/mime_type'
before the
Mime::Type.register 'application/pdf', :pdf
require 'pdf/writer'
in my environment.rb file.
Hope that helps.
Actually, you can just put the line
Mime::Type.register 'application/pdf', :pdf
in mime_types.rb in config\initializers
You'll still need
require 'pdf/writer'
but you can put that in your drawer.rb file and you can leave environment.rb alone.
I upgraded an app that I'm working on from rails 2.1.2 to 2.2.2 and now my rtex pdf generation does not work. It appears that the latex file is never run through the processor so no PDF is every created, you just get the latex file with a .pdf extension.
Moving back to rails 2.1.2 fixes the problem.
Is there a way to insert images into a simple table? I can't get that to work.
hey. I'm having problems with the path for images.
the pdf writer cant find it.
I've put the image everywhere but it doesn't seem to find it.
without restful routing. what should the path be anyway?
Ryan, what color scheme do you use in textmate? I like the colors you have when editing are they preset ones or did you customize?
I just wanted to say that the pdf writer is very nice, the only complain I have is that when I tried to create a table with 2000 rows it took more than 15 minutes to render the report, which kind of sucks. Am I doing something wrong?
_p = PDF::Writer.new(:orientation => :landscape)
_p.select_font 'Times-Roman'
PDF::SimpleTable.new do |tab|
tab.title_font_size = 10
tab.heading_font_size = 8
tab.font_size = 8
tab.width = 700
tab.orientation = :center
tab.title = "#{@report.name} as of " + (Time.now()).strftime("%a %b %d, %Y")
tab.column_order = @results.first.attribute_names
#Rename Columns
@results.first.attribute_names.each do |mykey|
tab.columns[mykey] = PDF::SimpleTable::Column.new(mykey) { |col| col.heading = mykey.slice(6..-1) }
end
tab.data = @results
tab.render_on(_p)
end
send_data _p.render, :filename => "#{@report.name}.pdf", :type => "application/pdf"
Thanks for your suggestions
Hi Ryan
Iam using rails 2.3.2.Whrn i run http://localhost:3000/att.pdf
It is giving following error:
No route matches "/att.pdf" with {:method=>:get}
In routes.rb i have
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
map.connect ':controller/:action.:format'
please help me why iam getting this error
The code is written in AttendenceReport index method.
when in run
http://localhost:3000/attendence_report/att.pdf
then it is giving error:
No action responded to att. Actions: index
and index working properly.help me
I have the same error of sravanthi, when I call 127.0.0.1:3000/makepdf/13.pdf I get this: Missing template makepdf/show.erb . In MakepdfController I have
def show
@asset = Asset.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @asset }
format.pdf { render :layout => false }
end
end
any hint?
Anyone else tried the Wicked pdf plugin yet? Looks perfect and simply uses your view html/css http://github.com/mileszs/wicked_pdf
WOWWWWWW, I spend all the morning looking for something like this!, don't get me wrong!, but I think I'm starting to loving YOU!!!!!(LOL!) THANKS A LOT!!!!!!!!!!!
Anybody got an idea how to generate a histogram in PDF?
Where should be payin_drawer.rb (previously product_drawer.rb)
be located in the project framework ?
LoadError in PayinsController#index
Unable to autoload constant PayinDrawer, expected C:/RubymineProjects/pms4mysql/app/pdfs/payin_drawer.rb to define it
Extracted source (around line #10):
8
9
10
11
12
13
end
Rails.root: C:/RubymineProjects/pms4mysql