-1

I am having thousands of HTML files, I want to convert then to .bmp (Bitmap images) using Java.

Like I select all the HTML files specify the size and then code will convert all images into bmp.

Please suggest me the simple method, which class shall i use for the same.

Is there any API for Converting Html to bmp.

Code Hungry
  • 3,930
  • 22
  • 67
  • 95
  • 2
    Welcome to Stack Overflow. Please read [How to Ask](http://stackoverflow.com/questions/how-to-ask), [What have you tried?](http://mattgemmell.com/2008/12/08/what-have-you-tried/), and [How To Ask Questions The Smart Way](http://catb.org/esr/faqs/smart-questions.html). –  Mar 01 '12 at 12:43
  • So if I understood you: You want to convert the HTML files into BMP? Not the Pictures linked in the HTML files? – NotANormalNerd Mar 01 '12 at 12:57
  • @DennisSchma:Thanks for replying ,Yes you are Right i want to convert HTML page page to BMP image. – Code Hungry Mar 01 '12 at 12:59

3 Answers3

2

One simple and easy way to do it is to rely on this 2 tools :

WkHtml2png : it cas convert HTML pages to PNG and it has really great capabilities with advanced CSS and JavaScript. I'm currently using it to convert Html to PDF.

png2bmp : it converts PNG to BMP images.

As these tools are native programs, you will have to Wrap them using basic Java API :

  • java.lang.ProcessBuilder
  • java.lang.Process

This discussion might be very useful if using WkHtml2pdf.

Community
  • 1
  • 1
0

If the HTML is very simple, and each file is short, you could render it in a JEditorPane, then use java.awt.Robot to take a screenshot with the .createScreenCapture() method.

See this question for saving it as BMP: BufferedImage to BMP in Java

However, JEditorPane is quite limited in the HTML it accepts.

This won't work if the rendering area is larger than the screen. You might be able to create a larger JEditorPane in a window larger than the screen and capture the Graphics buffer, instead.

Why does this have to be done from Java,?

Community
  • 1
  • 1
DNA
  • 42,007
  • 12
  • 107
  • 146
0

Now that i understood you right you have another problem.

Although all webbrowser should display HTML equally, they don't do. You should think about that.

If you only have simple HTML Files like Javadocs or equal, there should be no problem with the proposal of Khaled Labidi, if you have no problem using native Librarys.

Maybe you can have a look at http://lobobrowser.org/cobra.jsp. Render your HTML and CSS and then try to convert it all to BMP.

I think there is no really easy way to do that.

NotANormalNerd
  • 415
  • 3
  • 14