-
Website
http://blog.adsdevshop.com/ -
Original page
http://blog.adsdevshop.com/2007/11/20/easy-pdf-generation-with-ruby-rails-and-htmldoc/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
Ryan Price
2 comments · 1 points
-
webfugitive
1 comment · 1 points
-
Mark W. Schumann
2 comments · 1 points
-
ReinH
1 comment · 6 points
-
paulklipp
6 comments · 1 points
-
-
Popular Threads
-
Does Offshoring Really Save Money?
1 week ago · 8 comments
-
Introduction to Scrum for Managers Webinar
3 days ago · 2 comments
-
If You Don’t Focus on Business Value, Don’t Adopt Agile
3 weeks ago · 12 comments
-
Add a Call to Action to Your WordPress Posts with WP Post Footer
3 weeks ago · 6 comments
-
Pay (A Little) Attention to Competitors
3 weeks ago · 4 comments
-
Does Offshoring Really Save Money?
Tried a number of other approaches before this and definitely the best and really easy to implement
Robert.
I had the same problem with images, but have not looked into it yet as it was not of primary concern.
Chris
I am not entirely sure. I believe the website states the nightly builds have at least some support for CSS.
Chris
I've got some code using PDF::Writer, and managing the templates is a pain. If I could design the templates using normal HTML views, and then render them as PDF with some reasonable control over the style, I'd be a happy man.
I will try and post an example PDF tomorrow morning. However, I can tell you it looks pretty close to what a normal HTML page would look like.
@Robert Shell: I tested images and you give it the full path. For example /Users/chris/Projects/railsapp/public/images/logo.gif
Chris
HTML / CSS to PDF using Ruby on Rails
http://sublog.subimage.com/articles/2007/05/29/...
It comes from restful routes. Example:
map.resources :posts
gives you:
posts_path as well as formatted_posts_path(:format)
Try rake routes within in your project directory to see all your routes.
Chris
send_data has an option for filename.
send_data render_to_pdf({ :action => 'index.rpdf', :layout => 'pdf_report' }), :filename => "foobar.pdf"
Chris
" Mime::Type.register 'application/pdf', :pdf
require 'htmldoc'"
In config/enviroment.rb file in the last webrick server not restart. How am I solve this issue.
Is anybody help me
Thanks
Nidhika
If I run HTMLDOC from the command line with supposedly the same arguments (basically just --webpage) then it works a treat, even if I point it at the URL for my dynamically generated rails page. However if I call it using the Rails GEM then it renders everything except the images.
It's driving me bonkers and pretty urgent. I've tried all sorts of things including the pdf_image_tag helper above with numerous modifications (eg. adding file:/// at the start).
Cheers,
Matt
I found that I had to use absolute path to the image. Thus, for example:
/Users/chris/src/my_rails_app/public/images/some_image.png
I hope that helps.
Thanks for that. The trouble is (and I should have mentioned) that it's on Windoze. If I set it to 'c:\rails\project\public\images\some_image.jpg', load the page directly and save it to disk and then load the page in explorer it looks fine (that is, it loads the image/s from disk). But the Ruby htmldoc plugin still doesn't get them.
I've also tried prepending file:/// and a few other things.
//matt
undefined method `size' for false:FalseClass
I walk thru it with the debugger and it seems that data is nil so it can't do a size. I assume that is because the model for my control is not an option to post to the render_as_pdf but not sure.
********************
def send_data(data, options = {}) #:doc:
logger.info "Sending data #{options[:filename]}" unless logger.nil?
send_file_headers! options.merge(:length => data.size)
@performed_render = false
********************
is there a way to pass the record I have when I call this?
right now we do send_data render_to_pdf but is there a way to say @object so I can pass the object created by the finder? send_data @object.render_to_pdf does not work either as I get a missing method render_to_string that way
Here is a patch that solves my problem:
http://textmode.at/2008/5/14/ruby-htmldoc-gem-f...
Not sure if it's the same problem as the user above has.
I contacted the author htmldoc people.
greetings
Thanks for the patch!
I was getting the exact same error when using the pdf_image_tag helper. Applied the patch and viola! Image renders perfect.
thx...
BUT... I am storing Articles in my Database. I use FCKEditor for the User-interface - the text is stored HTML formatted and the path for Images is stored in the HTML Code in form of "/public/uploads/Images" and so on. I have explored that HTMLDOC needs the full path(as some People above). For Example http://0.0.0.0:3000/public/uploads/Images ...
Has anyone an idea how to fix this? I have seen the pdf_image_tag but i am not sure how it works...
I've got an app that does the same. I wrote a very simple helper that expands the image paths.
def write_full_image_path(text)
newtext = text.gsub('img src="', 'img src="' + File.expand_path(RAILS_ROOT) + '/public/')
newtext
end
Then, in my .rpdf files, I call for write_full_image_path(model.formatted_text)
With Debian is fine to install htmldoc with apt-get install.
The patch for images is necessary in both Debian and Ubuntu.
Thank you *very much* to all the people who shared their knowledge here :)
doc = Document.new
doc.mime = 'application/pdf'
pdf = PDF::HTMLDoc.new
pdf.set_option :bodycolor, :white
pdf.set_option :links, links
pdf.set_option :webpage, true
pdf.set_option :path, "#{RAILS_ROOT}/public/"
pdf << url
pdf.footer ".1."
if pdf.generate
puts "Successfully generated a PDF file"
doc.body = pdf.generate
else
puts "ERROR!--------------------------------------------"
for error in pdf.errors
puts error
end
end
doc
end
The important line is the pdf.set_option :path, #{RAILS_ROOT}/public/"
It tells htmldoc to look in your public folder for images.
If you manually create the img tag this will work and the images will be the same on the web as in the pdf. Using image_tag however will not work, because rails adds on the uid to each image.
If you were adventurous, you could parse out the uid from the tags with gsub. Now if I could just figure out how to keep the errors without having to generate twice.
getting error as for rails application.
"'htmldoc' is not recognized as an internal or external command,\noperable program or batch file.\n"
Thank you
But show stopper for me: HTMLDOC does not support CJK (Chinese, Japanese, Korean) languages.
I'm currently having a problem. I'm trying to apply a body image to my pdf's using the method:
pdf.set_option :bodyimage, "report_bg.jpg"
It's not that the image doesn't display right, it just doesn't display at all...
Any ideas? Tks in advance
data = render_to_string(options)
with the following line:
data = Iconv.conv('ISO-8859-15//IGNORE//TRANSLIT', 'utf-8', render_to_string(options))
This is needed because htmldoc (at least v1.8) doesn't support UTF
Torpedo Gratis
I'm trying to include special htmldoc comments, such as <!-- NEW PAGE -->, <!-- FOOTER LEFT "foo" --> and so on, but failed so far. Does anyone have a hint?
www.staffingpower.com