diff --git a/flying-saucer-pdf/src/test/java/org/xhtmlrenderer/pdf/ListsTest.java b/flying-saucer-pdf/src/test/java/org/xhtmlrenderer/pdf/ListsTest.java new file mode 100644 index 000000000..0f533da2f --- /dev/null +++ b/flying-saucer-pdf/src/test/java/org/xhtmlrenderer/pdf/ListsTest.java @@ -0,0 +1,47 @@ +package org.xhtmlrenderer.pdf; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; + +public class ListsTest { + private static final Logger log = LoggerFactory.getLogger(ListsTest.class); + + @ParameterizedTest + @ValueSource(strings = {"page-with-lists.html", "list-sample.xhtml"}) + void pageWithLists(String fileName) throws IOException, ParserConfigurationException, SAXException { + InputStream htmlStream = getClass().getClassLoader().getResourceAsStream(fileName); + String htmlContent = new String(htmlStream.readAllBytes()); + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.parse(new InputSource(new StringReader(htmlContent))); + + ITextRenderer renderer = new ITextRenderer(); + + ITextUserAgent userAgent = new ITextUserAgent(renderer.getOutputDevice(), Math.round(renderer.getOutputDevice().getDotsPerPoint())); + renderer.getSharedContext().setUserAgentCallback(userAgent); + + renderer.setDocument(document, null); + + File result = new File("target", fileName + ".pdf"); + try (FileOutputStream outputStream = new FileOutputStream(result)) { + renderer.layout(); + renderer.createPDF(outputStream); + } + log.info("PDF with lists: {}", result.getAbsolutePath()); + } +} diff --git a/flying-saucer-pdf/src/test/resources/list-sample.xhtml b/flying-saucer-pdf/src/test/resources/list-sample.xhtml new file mode 100755 index 000000000..92e782947 --- /dev/null +++ b/flying-saucer-pdf/src/test/resources/list-sample.xhtml @@ -0,0 +1,205 @@ + + + + +
+Flying Saucer XML/CSS2 Renderer
+ + CSS +List support includes: Full support for ordered and unordered lists, image bullets for lists, list style types, + numbered lists, and so on.
+The image shouldn't load and a square should be used instead
+It should have squares with outside position
+Just does decimal for now
+Roman numerals not valid past 4000
+not supported yet. does decimal instead
+not tested past Z
+