diff --git a/flying-saucer-examples/src/main/java/QuotingExample.java b/flying-saucer-core/src/test/java/org/xhtmlrenderer/swing/QuotingExampleTest.java similarity index 58% rename from flying-saucer-examples/src/main/java/QuotingExample.java rename to flying-saucer-core/src/test/java/org/xhtmlrenderer/swing/QuotingExampleTest.java index a66a96415..48e82f270 100644 --- a/flying-saucer-examples/src/main/java/QuotingExample.java +++ b/flying-saucer-core/src/test/java/org/xhtmlrenderer/swing/QuotingExampleTest.java @@ -1,55 +1,47 @@ -import org.xhtmlrenderer.simple.XHTMLPanel; -import org.xhtmlrenderer.util.XMLUtil; - -import javax.swing.*; - -import static javax.swing.SwingUtilities.invokeLater; - - -public class QuotingExample extends JFrame { - //currently we cannot display different quotes based on depth - private static final String DOCUMENT = - """ - - - - - -
-

This is just a test of the emergency quoting system.

-

This is only a test.

-

Thank you for your cooperation during this test.

-
- - - """; - - protected void frameInit() { - super.frameInit(); - - setTitle("CSS Quoting Example"); - setDefaultCloseOperation(EXIT_ON_CLOSE); - - XHTMLPanel xr = new XHTMLPanel(); - try { - xr.setDocument(XMLUtil.documentFromString(DOCUMENT)); - } catch (Exception e) { - throw new ExceptionInInitializerError(e); - } - - add(xr); - - setSize(500, 300); - } - - public static void main(String[] args) { - invokeLater(() -> new QuotingExample().setVisible(true)); - } -} +package org.xhtmlrenderer.swing; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.File; + +import static org.xhtmlrenderer.swing.Java2DRenderer.htmlAsImage; + +public class QuotingExampleTest { + private static final Logger log = LoggerFactory.getLogger(QuotingExampleTest.class); + + //currently we cannot display different quotes based on depth + private static final String DOCUMENT = + """ + + + + + +
+

This is just a test of the emergency quoting system.

+

This is only a test.

+

Thank you for your cooperation during this test.

+
+ + + """; + + @Test + public void exampleWithQuotes() throws Exception { + BufferedImage image = htmlAsImage(DOCUMENT, 600); + File result = new File("target/%s.png".formatted(getClass().getSimpleName())); + ImageIO.write(image, "png", result); + log.info("Generated image from html: {}", result.getAbsolutePath()); + } +}