iText pdf library
Website search

When is the content flushed to a PDF File by iTextSharp?

I assumed that Document.Add() flushed content to the PDF file (the file stream) immediately, but it looks like that's not the case

Posted on StackOverflow on Feb 18, 2014 by sameer

PDF is a Page Description Language. Every page is an autonomous set of objects. The content is stored in one or more streams. There is no such thing as a paragraph or a table etc in a PDF. It's just a sequence of lines, shapes and glyphs drawn on a page.

When you add content to a document using the Add() method, this content is converted into PDF syntax that is appended to the content stream of a page. As soon as the page is full, this content stream and the corresponding page dictionary are written to the output stream and flushed.

Not sooner!

Several objects, such as fonts, the cross-reference table, Form XObjects,... are kept into memory, because they can change during the document creation process.

In some cases you can release these objects early. For instance: there a "release template" method to write Form XObject to the output stream immediately. Image XObjects are always written immediately.


Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now