Hello,
Migrated from 1.21 to PDFSharp. Version - 1.31.1789.0 and got some surprises
.
One of them...
PdfDocument doc = new PdfDocument(groupedPdfName);
..
foreach (Guid customerId in customerInvoices.Keys)
{
//Opens created PDF file with all invoices for single customer
PdfDocument documentByCustomer = PdfReader.Open(filepath, PdfDocumentOpenMode.Import);
// Ads pages to document which contains invoice data from all customers
foreach (PdfPage page in documentByCustomer.Pages)
{
doc.AddPage(page);
}
documentByCustomer.Close(); //This throws an exception -> Can't save modified file.
documentByCustomer.Dispose(); // This doesn't throw anything.
...
}
foreach (PdfPage page in groupedDocument.Pages)
{
XGraphics gfx = XGraphics.FromPdfPage(page);
gfx.MFEH = PdfFontEmbedding.Always;
}
doc.Save(pdfPath);
doc.Close(); //Close throws "An item with the same key has already been added". Exception was thrown in Release mode.
Currently the only solution is not to use Close(). Fortunately it works without it.