Question

i have a problem i am deveoping a application using rails 2.3.8 . my problem is with the pdf. when a generated the pdf it shows all images in Linux.(ubuntu)

but the same code when i tried in windows7 the pdf is not showing the images in the body.the header and footer images are loading. the header and footer in the layout. i am using wickedpdf for pdf generation. my code is

<%= wicked_pdf_image_tag "#{Rails.root}/public/images/master_student/profile/default_student.png" ,:width=>85,:height=>100 %>

the code working fine in the ubuntu but not working in the windows7.. please help

Was it helpful?

Solution

I just overcame a similar issue on Windows with images uploaded through Paperclip, because WickedPDF's wicked_pdf_image_tag helper requires the images to be in public/images.

I used the solution given here for that problem, but I still couldn't get the images to render in the PDF. Then I discovered that if I put the image into the public/images folder and referenced it that way, the wicked_pdf_image_tag helper rendered the image tag with forward slashes instead of backslashes after the 'file://'.

This is the helper method I ended up with, which replaces wicked_pdf_image_tag:

module ApplicationHelper
  def wicked_pdf_image_tag_for_public(img, options={})
    if img[0] == "/"
      # Remove the leading slash
      new_image = img.slice(1..-1)
      image_tag "file:///#{Rails.root.join('public', new_image).to_s.gsub("/", "\\")}"
    else
      image_tag "file://#{Rails.root.join('public', 'images', img).to_s.gsub("/", "\\")}}", options
    end
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top