Skip to content Skip to sidebar Skip to footer

Can We Create An Image By Html String In Ruby On Rails.

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 t

Solution 1:

Are you referring to achieving:

<%= "<imgsrc='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'/>"

Solution 2:

I guess you want something like following

<% str = "<imgsrc='/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.

Solution 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.

Post a Comment for "Can We Create An Image By Html String In Ruby On Rails."