Question

I've encountered a problem with displaying images in pdf's and html's.

Basically what I want is to make my html view be downloadable in pdf. So I've created a partial _pdf_view.html.haml, which looks (for now) like so:

%p
  = wicked_pdf_image_tag "vehicles/Toyota_Echo1-1.jpg"

then I simply render this partial both in download.html.haml and in download.pdf.haml. The idea is that the html file previews what is going to be downloaded as a pdf.

The funny part is that this code will put the image nicely in my pdf, but not in my html. In PDF there needs to be specified full file path, however, in html that won't fly. If I change the path to "/vehicles/Toyota_Echo1-1.jpg" then it is the other way around...

Any way around it, besides creating separate files or separate chunks of code just for images?

P.S I'm using: rails 3.2.12, wkhtmltopdf 0.9.9, wicked_pdf 0.9.5

Was it helpful?

Solution

Change the image tag created based on the :format.

- if params[:format] == 'pdf'
  = wicked_pdf_image_tag 'vehicles/Toyota_Echo1-1.jpg'
- else
  = image_tag 'vehicles/Toyota_Echo1-1.jpg'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top