prawn - import image from URL
Asked Answered
W

3

14

I can't seem to figure out how to import an image from an url

To import the images from my localhost I use:

image"./assets/images/img.png"

When I replace the path with an URL it says

`image' : URL not found

Is there a solution for this, or should I create a def that downloads the image and to use the path it returns?

Worser answered 19/7, 2012 at 12:2 Comment(0)
R
44

you need to do the following -

require "open-uri"

Prawn::Document.generate(INSERT_YOUR_PDF_FILENAME_HERE) do 
   image open(INSERT_YOUR_URL_HERE)
end

Refer to http://rubydoc.info/gems/prawn/0.12.0/frames for more details.

Roundhead answered 20/7, 2012 at 4:56 Comment(4)
Thx, but I found that same solution later that day :-). I forgot to post it here. Thank you anyway! If I would not have found it on my own, this would have fixed the problem for me!Worser
Good that your problem has been resolved and I think it would be nice if you accept or uptick this answer!Roundhead
How can I use this if I have a file.pdf.rb because i think that code is for the controller ??Fredericton
Could someone tell me how to use this in github.com/spree-contrib/spree_print_invoice/blob/master/app/… on line 8? I cant seem to get it to work.Phagocytosis
R
2

I got this working for me:

image open("https://driver.mbpgroup.eu/images/mbp_logo.jpg"), position: :right, width: 250

I could NOT get this to work for me (Prawn documentation):

image "https://driver.mbpgroup.eu/images/mbp_logo.jpg", position: :right, width: 250
Reverberate answered 16/4, 2020 at 9:46 Comment(0)
B
0

I got this working for me, In my environment all the PDFs are generating from a separate internal gem. not sure if this helps but it got working for me

image URI.open("https://driver.mbpgroup.eu/images/mbp_logo.jpg"), position: :right, width: 250

Boracite answered 8/5 at 9:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.