'Render XHTML on one page to PDF
I have XHTML containing shop receipt. I am trying to generate PDF out of it. Generation is not problem at all. But I would like to have "break-less" page (whole content fits to one page).
I have Koltin Spring project and using flying-saucer.
org.xhtmlrenderer:flying-saucer-pdf-itext5:9.1.22
Code is simple as this:
fun generatePDF(templateString: String): ByteArrayOutputStream {
val renderer = ITextRenderer()
renderer.sharedContext.also {
it.isPrint = true
it.isInteractive = false
it.textRenderer.setSmoothingThreshold(0F)
}
renderer.setDocumentFromString(templateString, baseUrl)
renderer.layout()
val baos = ByteArrayOutputStream()
renderer.createPDF(baos)
renderer.finishPDF()
return baos
}
Is it somehow possible to do it?
Note: I've found some information about page size in the documentation, but I am not sure how to use it if I don't know the exact size (items in receipt are calculated).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
