Can we create an Image by HTML string in Ruby On Rails.

不想你离开。 提交于 2019-12-25 00:27:53

问题


I would like to know , Is there any possibility by which we can create an image by the HTML sting that has the HTML tags along with the formatting Or the HTML content coming from the Web Editors like Ckeditor or TinyMce etc in Ruby on Rails.

Thanks Nishant


回答1:


Are you referring to achieving:

<%= "<img src='http://domain.tld/some_image.png' />".html_safe %>

You can also interpolate any strings by doing

<%= "#{url_string}".html_safe %>

where url_string = "<img src='http://domain.tld/some_image.png' width='200px'/>"




回答2:


I guess you want something like following

<% str = "<img src='/images/InboundButtons.png' style='border: medium none ; padding: 0px 0px 0px -2px;'>"%>
<%= str %>

Where str is an html string and you can show it as above.




回答3:


It seems that your ultimate destination is a PDF file. I would skip image creation, and go right to that, using one of several HTML to PDF libraries available, perhaps one of the ones listed right here on StackOverflow. If you do need an image for some reason, even then, I would consider generating a PDF of your HTML, and then converting that to an image, since it's the best path I know to get from HTML to an image.

However, you have done a poor job of describing your problem, so with more details there might be some obvious alternative as well.



来源:https://stackoverflow.com/questions/7412684/can-we-create-an-image-by-html-string-in-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!