I have this code:
private static byte[] ConvertPdfDocument(Document document, PdfPTable headerTable, PdfPTable affidavitsTable)
{
byte[] b;
using (MemoryStream ms = new MemoryStream())
{
PdfWriter writer = PdfWriter.GetInstance(document, ms);
if (document.IsOpen() == false)
{
document.Open();
}
document.Add(headerTable);
document.Add(affidavitsTable);
document.Close();
writer.Close();
b = ms.ToArray();
}
return b;
}
The document object is opened (using document.Open()outside this method, then passed.
The condition document.IsOpen()is True. I also confirmed that the document is indeed open by looking at the private properties of the "document" object in the debugger; it shows that "Open" is "true".
Accordingly, execution proceeds to the line document.Add(headerTable).
And at this moment an exception is thrown: "The document is not open." And although the debugger is stopped (due to the fact that this exception is thrown) using the same two methods as described above, I can still see that the document is open.
How could this be?
Google, , , ...
.
,