Render HTML to an image

0 votes
I would like to know if there is any manner or way to render an html to an image like a PNG? I am aware that this is possible with canvas but however, I would want to render the standard html element such as Div. Could anyone help me with this?
Feb 8 in Java by Rahul
• 8,980 points
202 views

1 answer to this question.

0 votes

To answer your question, there are a lot of options available to render the standard html element such as using an API which includes ApiFlash, EcoPDF and the HTML to Image API. The advantage of this is to execute Javascript, close to perfect rendering, scale is handled by the APIs, precise timing and finally, the ability to offer a free plan. The disadvantage is that it is not free if decided to be used a lot. Another option is to use any one of the available libraries such as the dom-to-image and imgkit for python based on the wkhtmltoimage, python-webkit2png. The advantage of this option is that the conversion is very swift for most times. The disadvantages however are that the rendering is poor, does not execute javascript, is complicated to scale, could be tedious to install and finally does not support the recent web features such as Box Sizing and Media Queries. A third option or possibility is that using PhantomJs could help you with your doubt. For PhantomJs the following line of code captures the Google homepage, waits  for a bit, and then captures it to an image.

var page = require('webpage').create();

page.open('http://www.google.com', function() {

    setTimeout(function() {

        page.render('google.png');

        phantom.exit();

    }, 200);

});

The advantage of this is that it executes Javascript and works very quickly. The con is that it has poor rendering, does not support for the recent web features, is complicated to scale and is not easy to enable it to work if there are images to be loaded.

answered Feb 8 by Soham
• 8,730 points

Related Questions In Java

0 votes
2 answers

How can we add an image to a JPanel?

If you are using JPanels, then are ...READ MORE

answered Sep 20, 2018 in Java by Daisy
• 8,120 points
9,382 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,220 points
2,339 views
0 votes
2 answers

What is the syntax to initialize an array?

Rather than learning un-Official websites learn from ...READ MORE

answered Aug 2, 2018 in Java by samarth295
• 2,220 points
310 views
0 votes
2 answers

How to convert an array to arraylist?

In Java 9 you can use: List<String> list= List.of("Hello", "World", ...READ MORE

answered Aug 1, 2018 in Java by samarth295
• 2,220 points
281 views
0 votes
1 answer
0 votes
0 answers

Anyone can help me out to understand the semantic of (document.getElementBYId("demo").innerHTML="Hello") ?

Hello guys, Can Someone helps me to find ...READ MORE

Jan 17, 2020 in Web Development by anonymous
• 37,510 points
361 views
+1 vote
1 answer

What is the relationship between angularjs Scope with controller/view?

Let us consider the below block: <div ng-controller="emp"> ...READ MORE

answered Jan 20, 2020 in Web Development by Niroj
• 82,680 points

edited Jan 21, 2020 by Niroj 372 views
+1 vote
1 answer

What are pseudo class in css??

Hey, The state of an element is controlled  by ...READ MORE

answered Jan 20, 2020 in Web Development by Niroj
• 82,680 points

edited Jan 21, 2020 by Niroj 269 views
0 votes
2 answers

How do I convert a String to an int in Java?

Use the lines of code mentioned below:- String ...READ MORE

answered Feb 9 in Java by Soham
• 8,730 points
364 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP