2

I want to render a PDF document using latest FLyingSaucer

build.gradle:

implementation 'org.xhtmlrenderer:flying-saucer-pdf-openpdf:9.1.22'

Input HTML document (almost a copy from W3 schools):

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
  display: flex;
  background-color: DodgerBlue;
}

.flex-container > div {
  background-color: #f1f1f1;
  margin: 10px;
  padding: 20px;
  font-size: 30px;
}
</style>
</head>
<body>

<h1>Create a Flex Container</h1>

<div class="flex-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>  
</div>

</body>
</html>

A sample code (as JUnit test):

class FlexTest {

  @Test
  void flexTest() throws FileNotFoundException, IOException {

    final String htmlContent =
        IOUtils.toString(new FileInputStream("input.html"), Charset.defaultCharset());

    ITextRenderer renderer = new ITextRenderer();
    renderer.setDocumentFromString(htmlContent);
    renderer.layout();
    renderer.createPDF(new FileOutputStream("output.pdf"));
  }
}

It works fine except the display: flex is not rendered correctly. It looks like it's rendered as a regular <div>:

enter image description here

Is the flex box supported by FlyingSaucer/openpdf? I didn't find any note that it isn't.

zolv
  • 1,720
  • 2
  • 19
  • 36
  • 1
    just because you mention openpdf, pdfhtml/itext have [flex support](https://kb.itextpdf.com/home/it7kb/examples/flexbox-suport-in-pdfhtml) – André Lemos Nov 10 '21 at 12:47

1 Answers1

3

Flying-saucer doesn't support Flex, and will likely never support it.

The CSS supported by flying-saucer is limited to CSS 2.1 and most of CSS paged media.

obourgain
  • 8,856
  • 6
  • 42
  • 57