From 5f3625b23a40a3e88f69cb9ef413f4c6cd5353a2 Mon Sep 17 00:00:00 2001 From: Andrei Solntsev Date: Sun, 13 Oct 2024 22:49:51 +0300 Subject: [PATCH] #411 add few samples of html with lists Unfortunately, these do not check how lists look like. But it least it's easy to check the result manually. --- .../java/org/xhtmlrenderer/pdf/ListsTest.java | 47 ++++ .../src/test/resources/list-sample.xhtml | 205 ++++++++++++++++++ .../src/test/resources/page-with-lists.html | 59 +++++ 3 files changed, 311 insertions(+) create mode 100644 flying-saucer-pdf/src/test/java/org/xhtmlrenderer/pdf/ListsTest.java create mode 100755 flying-saucer-pdf/src/test/resources/list-sample.xhtml create mode 100644 flying-saucer-pdf/src/test/resources/page-with-lists.html 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: CSS List Support + + + + + + + + + + + CSS + + +

List support includes: Full support for ordered and unordered lists, image bullets for lists, list style types, + numbered lists, and so on.

+
+ +

Unordered List Items with default style

+ + + +

Ordered List Items with default style

+
    +
  1. List text list text list text list text
  2. +
  3. more item more item more item more item
  4. +
+ +

List Items with image bullets

+
    +
  1. first item
  2. +
  3. second item
  4. +
+ +

Position Outside

+
    +
  1. first item
  2. +
  3. second item
  4. +
+ +

Position Inside

+
    +
  1. first item
  2. +
  3. second item
  4. +
+ +

Failover

+

The image shouldn't load and a square should be used instead

+
    +
  1. first item
  2. +
  3. second item
  4. +
+ +

Shorthand Test

+

It should have squares with outside position

+
    +
  1. first item
  2. +
  3. second item
  4. +
+ +

Inheritance test with squares

+
    +
  1. first item
  2. +
  3. second item
  4. +
+ +

Square Items

+
    +
  1. first item
  2. +
  3. second item
  4. +
+ +

Disc Items

+
    +
  1. first item
  2. +
  3. second item
  4. +
+ +

Circle Items

+
    +
  1. first item
  2. +
  3. second item
  4. +
+ +

Decimal Items

+
    +
  1. first item
  2. +
  3. second item
  4. +
  5. third item
  6. +
  7. fourth item
  8. +
  9. fifth item
  10. +
  11. sixth item
  12. +
+ +

Decimal Leading Zero Items

+

Just does decimal for now

+
    +
  1. first item
  2. +
  3. second item
  4. +
  5. third item
  6. +
  7. fourth item
  8. +
  9. fifth item
  10. +
  11. sixth item
  12. +
+ +

Lower Roman Items

+

Roman numerals not valid past 4000

+
    +
  1. first item
  2. +
  3. second item
  4. +
  5. third item
  6. +
  7. fourth item
  8. +
  9. fifth item
  10. +
  11. sixth item
  12. +
+ +

Upper Roman Items

+
    +
  1. first item
  2. +
  3. second item
  4. +
  5. third item
  6. +
  7. fourth item
  8. +
  9. fifth item
  10. +
  11. sixth item
  12. +
+ +

Lower Greek Items

+

not supported yet. does decimal instead

+
    +
  1. first item
  2. +
  3. second item
  4. +
  5. third item
  6. +
  7. fourth item
  8. +
  9. fifth item
  10. +
  11. sixth item
  12. +
+ +

Lower Latin Items

+

not tested past Z

+
    +
  1. first item
  2. +
  3. second item
  4. +
  5. third item
  6. +
  7. fourth item
  8. +
  9. fifth item
  10. +
  11. sixth item
  12. +
+ +

Upper Latin Items

+
    +
  1. first item
  2. +
  3. second item
  4. +
  5. third item
  6. +
  7. fourth item
  8. +
  9. fifth item
  10. +
  11. sixth item
  12. +
+ +

None Items

+
    +
  1. first item
  2. +
  3. second item
  4. +
+ + \ No newline at end of file diff --git a/flying-saucer-pdf/src/test/resources/page-with-lists.html b/flying-saucer-pdf/src/test/resources/page-with-lists.html new file mode 100644 index 000000000..fbd7895c6 --- /dev/null +++ b/flying-saucer-pdf/src/test/resources/page-with-lists.html @@ -0,0 +1,59 @@ + + + + Title Here + + + + + + +
    +
  1. First list Item Goes Here
  2. +
  3. How to efficiently add a list
  4. +
  5. Steps to take when you are making a list
  6. +
  7. Our specific recommendations to you for lists.
  8. +
+ + + + +