Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rendering html to png (server-side) [closed]

I have a workflow model. Internet Explorer doesn't support some features required for model editing functionality (and regular user doesn't need it).

I want a read-only preview of my model. Is it possible to server-side render my HTML to an image?

I would prefer offline solution to allow our system run in corporate LAN without access to internet.

like image 779
jonny Avatar asked Apr 16 '10 06:04

jonny


People also ask

Why is server-side rendering better?

Some server-side rendering advantages include: A server-side rendered application enables pages to load faster, improving the user experience. When rendering server-side, search engines can easily index and crawl content because the content can be rendered before the page is loaded, which is ideal for SEO.

Is server-side rendering worth it?

Between the two options, server-side rendering is better for SEO than client-side rendering. This is because server-side rendering can speed up page load times, which not only improves the user experience, but can help your site rank better in Google search results.

What is SSR server-side rendering?

Server-side rendering (SSR), is the ability of an application to contribute by displaying the web-page on the server instead of rendering it in the browser. Server-side sends a fully rendered page to the client; the client's JavaScript bundle takes over and allows the SPA framework to operate.


2 Answers

Here are 'local' solutions:

  • wkhtmltoimage from the wkhtmltopdf package

    does exactly its name says

  • PhantomJS

    more advanced capabilities, like evaluating any js code in the page's context before rendering it to an image or pdf.

like image 72
jonny Avatar answered Oct 07 '22 00:10

jonny


You can try using a java library called flyingsaucer (aka xhtmlrenderer). It has worked very well for me in the past.

Homepage: http://code.google.com/p/flying-saucer//

FAQ for generating an image: http://pigeonholdings.com/projects/flyingsaucer/R8/doc/guide/users-guide-R8.html#xil_29

like image 29
Tyler Avatar answered Oct 06 '22 23:10

Tyler