0
votes

I'm in the process of moving from iText 5 to 7. We process huge PDF files, so parsing the entire PDF into memory is not at all desirable. In 5, there is a special constructor on PdfReader that forces 'partial mode'. Does iText 7 always parse the entire PDF or does it always effectively use 'partial mode'?

Looking at the iText 7 source, it appears that PdfReader no longer caches document content. Instead, PdfDocument takes care of the caching. This means that it should be possible to create a new PdfDocument for each page, which would have the same effect of the iText 5 'partial mode' in PdfReader.

If someone could confirm my thinking on that, I would appreciate it.

1

1 Answers

0
votes

Partial (or I would rather call it lazy) reading mode is supported in iText7 and it is active by default. This means objects will be read/loaded as needed. Of course, some necessary things will be read in any case (like cross-reference table, catalog etc, as well as nested direct objects).

Also, PdfObject has release() method in iText7, which frees that object from memory and that object will be read again if needed. But if you are using a lot of high-level API then release() might not be that useful and indeed creating several PdfDocument instances might be more useful and simple.

Important note: As the files are huge, they are probably located on disk, so it is very important to use PdfReader(String) or PdfReader(File) constructors. Those take advantage of random read possibility. Otherwise, if you simply pass an InputStream, the stream will be first read fully into memory and then document will be constructed. This of course still saves some memory for the data structures but keeps the source document in memory which I believe is undesired.