Q: It seems like elementbuilder and and the element are linked in
their dispose calls, is this true?
We try calling dispose on the builder then a few lines of code later
try to access the element and we run into exceptions.
The reason we are doing this is because we are trying to cache the
element and so in many cases we dont want to rebuild it.
But the way it seems is that we always need to create the builder so
we can dispose it after we are done with the element, whether it was
used to create the element or not.
Here is the code we were trying to use. Perhaps just a brief
explanation would be helpful. Thanks.
PDFDoc document = ...;
Matrix2D matrix = ...;
Element element;
// Element retrieved from cache
if (element == null)
{
Page renderedPage = document.GetPage(1);
ElementBuilder builder = new ElementBuilder();
element = builder.CreateForm(renderedPage, document);
// Cache element...
builder.Dispose();
}
element.GetGState().SetTransform(matrix);
-------
A: This is correct (http://www.pdftron.com/net/html/
classpdftron_1_1PDF_1_1ElementBuilder.html).
Analogous to ElementReader, ElementBuilder is the owner of all Element
objects it creates.
Similar to the behavior of ElementReader.Next(), every call to
ElementBuilder.Create?() or ElementBuilder.Dispose() method destroys
the previous element associated with ElementBuilder. This is done in
order to keep memory requirements low.
As a result, you should not dispose ElementBuilder until Element is no
longer in use. In case you need to keep multiple Elements alive at the
same time you could create an array/list of ElementBuilder-s and
dispose them when they are no longer in use.