-
Notifications
You must be signed in to change notification settings - Fork 647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does Wicked PDF supports embeding images? #36
Comments
images work just fine. Wkthmltopdf needs to know the full path to the file to be able to render it internally. So, image_tag('foo.jpg') won't work because it outputs a relative path and wk needs to know where /images is. The library mixes in helpers for images, stylesheets, and javascripts. So, wicked_pdf_image_tag('foo.jpg'), will output <img src="file:///home/users/emzero/cool_app/public/images/foo.jpg"> An alternative way is to point to a remote server image, like so: image_tag("http://yourserver.com/images/foo.jpg") |
i'm having this problem on heroku cedar stack. works perfectly fine on local env. here are the gems i am using: File uploadgem 'paperclip', '~> 2.4' Creating PDFsgem 'wicked_pdf' Maybe you have suggestions or possible solution i can start with. Thanks |
@ademar11 Use :show_as_html => true in your pdf generation and check that the img src's are correct. |
@unixmonkey, i tried doing this: rendered_invoice = render_to_string(:template => "invoices/pdf/pdf_invoice.pdf.haml", :layout => "layouts/pdf", :show_as_html => true )
pdf = WickedPdf.new.pdf_from_string rendered_invoice
File.open(save_path, 'wb') do |file|
file << pdf
end When i open the file, the image attached is still not saved. Although, if I view it on browser and not saving it as a pdf the images appear. |
@unixmonkey nope not using wicked_pdf_image_tag, but it works on rendering the pdf on view. the problem is just when we save it into a file, as specified in the code above (#36 (comment)) Maybe this is a pdf_from_string method error? This did not work also: :show_as_html => true |
this is the same issue I am having with the latest version, using a cloud storage for my images. Has anyone figured out a work-around for this? |
@numsweb You can use the full url for the assets stored on the cloud: https://s3.amazonaws.com/my-bucket/foo.png Is that what you are asking? |
[image: Inline image 1] this is what I get in the pdf, I am debugging the image tag and you can see John Kropka On Tue, Mar 31, 2015 at 1:39 PM, David Jones notifications@github.com
|
here is the view's code: <%= image_tag(image) %>
John Kropka On Tue, Mar 31, 2015 at 1:39 PM, David Jones notifications@github.com
|
but when I render it to PDF in a controller everything works OK: render :pdf => "#{@alert.alert_type.name John Kropka On Tue, Mar 31, 2015 at 1:39 PM, David Jones notifications@github.com
|
@david : long term goal is to generate a flyer in PDF, and email it as an John Kropka On Tue, Mar 31, 2015 at 1:39 PM, David Jones notifications@github.com
|
so what I have in the model is:
{})
John Kropka On Tue, Mar 31, 2015 at 1:39 PM, David Jones notifications@github.com
|
I would suggest you capture the output of Image tags need to look like this:
Not like this:
Does that make sense? You may want to try using |
That image i sent HAS the whole path to the image, but it is on a cloud John Kropka On Tue, Mar 31, 2015 at 2:02 PM, David Jones notifications@github.com
|
I'm sorry, but I don't see an image, nor a URL to it, nor the HTML generated from your calling "render". Please provide that and I can be more helpful. |
Here is the PDF: "%PDF-1.4\n1 0 obj\n<<\n/Title (\xFE\xFF)\n/Producer
|
Here is the file that gets rendered, you will notice little boxes where the John Kropka On Tue, Mar 31, 2015 at 2:09 PM, David Jones notifications@github.com
|
Scroll down to page 4 to see the image URLs John Kropka On Tue, Mar 31, 2015 at 2:13 PM, John Kropka john@cabforward.com wrote:
|
@numsweb I'm guessing you think that I can see or inspect anything that you are attaching to your emails. I cannot. |
Hey unixmonkey, I tried image_tag(@receipt.image_link) none of them seem to work. Thanks |
@qpham415 What do the links stored in your database look like, and where are the files actually stored? If they are full URI's, they should work, if they are not, then you'll want to construct the string to them appropriately. For instance if
The leading slash tells rails to look under "public" instead of the asset pipeline. This should also work, and should be faster since it would load from disk instead of over HTTP:
|
Thanks for the quick reply. The links stored in the database are full URIs from external site It's weird, I am able to display the image on my show page with image_tag but when I go to generate the pdf, it's a blank box. |
This sounds like a recent HTTPS issue I've seen. You can try to update to the latest app/helpers/application_helper.rb require 'open-uri'
def embed_remote_image(url, content_type)
asset = open(url, "r:UTF-8") { |f| f.read }
base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
"data:#{content_type};base64,#{Rack::Utils.escape(base64)}"
end app/views/receipts/show.pdf.erb <%= image_tag embed_remote_image(@receipt.image_link, 'image/png' ) %> |
Your solution works perfectly, thanks for all your help! I will try updating wkhtmltopdf later also. |
in rails view using wicked pdf gem but not displaying how to call js
|
@Murali-Mohan-M Do you have jQuery or JsBarcode loaded? |
@unixmonkey |
Hello Guys, If any body want to add image with in the pdf then please follow https://github.com/ashishprajapati/add_image_inside_pdf
|
Hello, Thank you for your great work, it works pretty well with Rails application. Loading images into PDF works well too, except when the file name of those images contain Chinese marks. Actually it works well too in development environment, but not in production environment. Any suggestions how this issue should be handled? Thanks in advance. |
@lyonsun I wonder if that has something to do with not having Chinese character sets installed on your production server or something like that, or if it's just a coincidence, and there's something else going on with HTTPS or network routing. I don't have any great suggestions to troubleshoot this, except to maybe to proxy them to local files as described above in this issue here. |
@unixmonkey Thank you for your quick response.
Images are stored on local disks of the production server rather than the cloud, and the problem is that the filename of these images contains Chinese characters. |
@unixmonkey I just managed to solve the problem using the alternative way you suggested here to point to the image with full URL. Exact code for image display in view file:
Need to Again, thank you for your excellent work! |
instead of |
Hi,
Great work you've done with Wicked PDF.
I'm wondering if it supports adding images. I've tried dropping some tags but I'm getting blank boxes, so it seems it recognizes the image tags, but is not capable of embeding them into the PDF.
Is that being supported? If so, how exactly I can achieve?
Thank you.
The text was updated successfully, but these errors were encountered: