// Prepare HTML code and save it to a file String code = "Hello, World!!"; try (java.io.FileWriter fileWriter = new java.io.FileWriter("png.html")) { fileWriter.write(code); } // Initialize an HTML document from the file HTMLDocument document = new HTMLDocument("png.html"); // Initialize ImageSaveOptions ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Png); // Convert HTML to PNG Converter.convertHTML(document, options, "png-output.png");