Reputation: 169
following iText example https://kb.itextpdf.com/itext/large-tables i'm able to build a pdf with a very large table while the temporary file size grows on flushing and heap space remains constant.
I need to create a PDF/A file but flushing doesn't happen, pdf is built in memory reaching heap max size and causing overflow.
With PDF/A log shows the following warning
com.itextpdf.pdfa.PdfADocument : Page flushing was not performed. Pages flushing in PDF/A mode works only with explicit calls to PdfPage#flush(boolean) with flushResourcesContentStreams argument set to true
I experience the correct behaviour with PdfDocument, while with PdfADocument flushing doesn't work
PdfADocument pdf = new PdfADocument(new PdfWriter(tempfile), PdfAConformanceLevel.PDF_A_1B,
new PdfOutputIntent("Custom", "", null, "sRGB IEC61966-2.1",
resourceLoader.getResource("classpath:sRGB2014.icc").getInputStream()));
pdf.getCatalog().setLang(new PdfString("it-it"));
// if pdf is instantiated with the following line flushing happens, with PdfADocument flushing doesn't work!
// PdfDocument pdf = new PdfDocument(new PdfWriter(tempfile));
Document document = new Document(pdf,PageSize.A4,true);
Any help appreciated, thank in advance
Upvotes: 2
Views: 147
Reputation: 236
After investigating in great detail, you can safely ignore that warning message because even though we retain the page contentStreams and other data in memory to perform our compliance checks we still give back a lot of the memory to the garbage collector, mainly java objects we don't need anymore. So it's well worth to use the large table feature.
Of course it will not be as efficient as when using a normal PdfDocument but it still has large speed/memory gains. In my local test a table in an PDFA document with a large table and 30000 cells took 3 s runtime and peaked at 296 MB. But for the same table without using the large table it ran for 1.15 min and peaked at 498 MB so as you can see the gains are pretty good.
Upvotes: 2