2

I am using wkhtmltoPDF to generate pdf from html string and It works fine for me as expected, but now I have to generate output as Image and I'm unable to find sample code or any library.

I have referred https://github.com/jhonnymertz/java-wkhtmltopdf-wrapper to generate pdf.

import com.github.jhonnymertz.wkhtmltopdf.wrapper.Pdf;

public class WKhtmlToPdf
 { 
    Pdf pdf = new Pdf();
    pdf.addPageFromString("html code");
    pdf.addToc();

 try{
     pdf.saveAs("Output.pdf");
   }
    catch (IOException e)
     {
     }
    catch (InterruptedException e)
     {     
     }
 }

I wanted an output an Image. Can any one tell me and I don't want to use Runtime.getRuntime().exe() method to generate output.

Thanks in advance.

Deva
  • 1,851
  • 21
  • 22

1 Answers1

0

wkhtmltopdf is a library which is part of the wkhtmltox project, which includes wkhtmltoimage too. You can inspire yourself from the wrapper you linked above to develop a wkhtmltoimage wrapper.

Also, I generally use ImageMagick to generate images programmatically. IM4Java is an example wrapper to it for Java.

OlivierH
  • 3,875
  • 1
  • 19
  • 32
  • Thanks @OlivierH, I tried and then only posted question. – Deva Jan 17 '19 at 10:04
  • They have given example of pdf only not for Image output. – Deva Jan 17 '19 at 10:11
  • @Deva What are you talking about ? IM4Java or java-wkhtmltopdf-wrapper ? – OlivierH Jan 17 '19 at 14:07
  • I am talking about java-wkhtmltopdf-wrapper. They have not given docs proper way about how to convert html to image. they only gave html to pdf. – Deva Jan 18 '19 at 05:55
  • You are right, this wrapper cannot generate images at this moment. What I meant is that you can clone this project and change it to output images instead of pdf : wkhtmltopdf and wkhtmltoimage are very similar in their use. – OlivierH Jan 18 '19 at 09:05
  • Thanks @OlivierH. Thanks for your support. – Deva Jan 18 '19 at 09:36