Good day all,
I have a document that is building and viewing correctly in PDF form. However, when I want to add an extra commentary section to this PDF document I am unable to copy the document contents.
Code:
//
// adds extra commentary to the document
//
public Document genCommentary(string commentary, string author, string function)
{
Document docWithCommentary = new Document();
// docWithCommentary = this.doc;
docWithCommentary = doc.Clone();
Section sectionCommentary = docWithCommentary.AddSection();
Paragraph paragraph = new Paragraph();
paragraph = sectionCommentary.AddParagraph("Adviesrapport", "Adviesrapport");
paragraph = sectionCommentary.AddParagraph(commentary, "Normal");
paragraph = sectionCommentary.AddParagraph(author + ',', "Normal");
paragraph = sectionCommentary.AddParagraph(function, "writerFunction");
return docWithCommentary;
}
//
// render and stream PDF document
//
public MemoryStream renderandStreamPDF(Document docWithCommentary)
{
PdfDocumentRenderer renderer = new PdfDocumentRenderer();
if (docWithCommentary == null)
{
renderer.Document = this.doc;
} else
{
renderer.Document = docWithCommentary;
}
renderer.RenderDocument();
MemoryStream stream = new MemoryStream();
renderer.PdfDocument.Save(stream, false);
return stream;
}
So a new document is being created, based on the contents of the old document. It is a new object, yet I get the following error message:
Quote:
The document is already bound to another renderer.
But why? I create a new renderer and my docWithCommentary to be rendered is also a new object.
SIDENOTE: when I completely rebuild the content instead of copying I do not get this error message, but it costs the machine extra resources while it just needs to copy the doc rather than entirely rebuild it from scratch