0

I am trying to transform html text into a png or jpg image. When I call my web service, I have an image that returned to me, the text is a bit blurry. It is not really sharp.

The method:

@Transactional
@GetMapping("/media/image/{fun}")
public void getImageAsByteArray(HttpServletResponse response) throws IOException
{

    Fiche fiche = ficheRepository.getOne(23L);

    response.setContentType(MediaType.IMAGE_PNG_VALUE);
    String html = "<p>Ma <strong>description dcdvd</strong></p><p>&nbsp;</p><p><i><strong>dddddd</strong></i></p>";
    Document doc = Jsoup.parse(html);
    
    int width = 200, height = 100;

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    Graphics graphics = image.createGraphics();
    JEditorPane jep = new JEditorPane("text/html", fiche.getTexte());
    jep.setSize(width, height);

    jep.print(graphics);


    ImageIO.write(image, "png", response.getOutputStream());

}

The result: result.png

0 Answers0