Q: We are currently getting the following exception message with
PDFNet v4.0.3 (file version 22.214.171.124): -
Message: Error encoding a Flate stream
We are merging together roughly 3800 pdfs of around 70kb in size into
1 PDF, and adding a small amount of text to each page as the pages are
merged in. The exception does not always happen when merging in a
particular file, and merging a smaller amount of files works, so I
believe this is may be due to a memory leak.
The exception occurs when adding the text, specifically when calling
[instance of ElementWriter].End().
Please can you advise if this is a known problem, or what we need to
do to free memory properly, or if you can think of a work around to
Code we use to write the text: -
ElementBuilder inkwell = new ElementBuilder();
ElementWriter quill = new ElementWriter();
// Select page
PageIterator pageIteratorOutPage =
// set font
// set text
Element textBlock = inkwell.CreateTextRun(text);
// position text
textBlock.SetTextMatrix(1, 0, 0, 1, xPos, yPos);
// write text
A: Under .NET you should use 'using' keyword or call Dispose() on
ElementBuilder/ElementWriter (as well as PDFDraw or PDFDoc; any object
that implements IDispose interface), when they are no longer in use.
Forgetting to release resources on time could lead to memory
You may also want to make that indoc.InitSecurityHandler() is called
on all input PDFs. Forgetting to call InitSecurityHandler() on
encrypted PDFs will result in a similar error message.