My solution includes 3 steps:
- Create a
BufferedImage and Create it Graphics - Create a
JEditorPane and call print(Graphics) - Output
BufferedImage via ImageIO
code:
import java.awt.Graphics; import java.awt.GraphicsEnvironment; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.JEditorPane; public class Test { public static void main(String[] args) { String html = "<h1>Hello, world.</h1>Etc. Etc."; int width = 200, height = 100;
Result:

source share