Generating PDF as a A4 PAGE

193 views
Skip to first unread message

Josef Vávra

unread,
Nov 24, 2023, 7:41:39 AM11/24/23
to Flying Saucer Users
Hi,

I am not sure if I encountered a bug or I am just using this library in a wrong way.
This is the piece of css, that should take html code wrapped in <page></page> tags and turn them into A4 page.

page {
background: white;
width: 21cm;
height: 29.7cm;
display: block;
margin: 0 auto;
padding: 20px;
margin-bottom: 0.5cm;
box-shadow: 0 0 0.5cm rgba(0,0,0,0.5);
display: flex;
flex-direction: column;
}

When I open my html page in browser, it works just fine, but when I pass the same html into ITextRenderer, this particular part of css is completely ignored and whole document is scrambled. Is this part of code not enought and when I try to do this kind of formatting I need to use something else?

val fileOutputStream = FileOutputStream(pdfFilePath)
val renderer = ITextRenderer()
val lines = object {}.javaClass.getResourceAsStream("template.html")?.bufferedReader()?.readLines()
renderer.setDocumentFromString(lines?.joinToString("\n"))
renderer.layout()
renderer.createPDF(fileOutputStream, false)
renderer.finishPDF()

Thanks in advance for replies!

Andrei Solntsev

unread,
Jan 10, 2024, 12:09:08 PM1/10/24
to flying-sa...@googlegroups.com
Hi Josef!

Sorry, but I could not reproduce your problem.
I just generated a pdf from your code, and I see the styled page both in html in pdf.

I've changed to background color to "background: lightblue;", and now 
1. HTML has blue background:
2. PDF also has blue background

image.png

Andrei Solntsev


пт, 24 нояб. 2023 г. в 14:41, Josef Vávra <vavra...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Flying Saucer Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flying-saucer-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flying-saucer-users/c76393dc-eb88-473e-ba32-efe14133517bn%40googlegroups.com.
hello.pdf
Reply all
Reply to author
Forward
0 new messages