Inline Image vs Temporary Files (Java XHTML->PDF generation) -
Inline Image vs Temporary Files (Java XHTML->PDF generation) -
i have project need generate pdf file. within pdf have insert body of text 4 or 5 big images (roughly 800px*1000px). in order create flexible have opted utilize freemarker in conjunction xhtmlrenderer (flying-saucer).
i faced couple of options:
create images , save them temporary files disk. process.xhtml template freemarker (saving disk) , pass processed .xhtml file url xhtmlrenderer generate pdf. these created files (bar pdf) created file.createtempfile. allow freemarker pick images off disk (as if images linked in xhtml) process .xhtml template , maintain in memory. pass images template base64 encoded info urls. remove need saving temporary files output freemarker passed straight xhtmlrenderer. base64 encoded image url illustration (a little folder icon):
<img src="data:image/gif;base64,r0lgodlheaaoalmaaoaztoehh0tls/7lzv/0jvb29t/f3//ub/ /ge8wslf/rhf/3kdbw1mxsbp//mf///yh5baaaaaaalaaaaaaqaa4aaare8l1ekyky67qz1hlnjm5uude0ecwljoexk cppv0accgcmtiheiueqjgaorcmxic6e0ccguww6afjsvmkkir7g77zkpjjpzqiyd7sjagvgoegv2xsbxqngypj/gawxeqa7" /> my main question improve technique? creating lots of temporary files bad (does carry lots of overhead)? potentially run out of memory creating such big base64 encoded strings?
i found myself asking same question recently. after benchmarking, turns out info uri approach best bet.
storing bunch of base64-encoded images can expensive. overhead creating temp files, streaming image info in, waiting xhtmlrenderer nail temp file 4 times before cleaning taxing.
in experiments, base64 images proved improve approach. beingness said, i'm not sure extent remain true larger images. in case, testing 32x32 icons, 80x80 logos, 400x240 bar graphs , 1 600x400 graphic. difference in overhead important except 600x400 graphic, got negligible.
(a side note joop eggen- in case, pdf generation is time critical. user clicks button pdf , expects download begin immediately.)
java xhtml pdf-generation freemarker flying-saucer
Comments
Post a Comment