0

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

3 Answers 3

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'/>"

Sign up to request clarification or add additional context in comments.

4 Comments

No , what basically i want is to create an image from the HTML string like suppose i have an HTML string "<p>hello world</p>" so i want this string to be printed on the image. so the HTML content can be printed over an image
Well that's easy, just echo your output (as above) into a DIV; set your image as the background image of the DIV container.
That will not solve my cause , this is the second step after this step i am going to put that image on a pdf
Your original question wasn't phrased well enough; I suggest you provide more details otherwise we are just groping in the dark. I take it that English isn't your first language? In any case, good luck.
0

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.

1 Comment

You'd need to do <%= str.html_safe %> or <%= raw str %> though?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.