Unplanned
Last Updated: 10 Jan 2023 09:02 by Martin
Martin
Created on: 10 Jan 2023 09:02
Category: PDFViewer
Type: Bug Report
0
PdfViewer: KeyNotFoundException when changing Form fields then flattening them and invoking the viewer`s Save method

When making changes to Form fields then flattening them and invoking the viewer`s Save method an exception is thrown: System.Collections.Generic.KeyNotFoundException: 'The given key was not present in the dictionary.'

Code to reproduce the issue:

this.pdfViewer.Document.AcroForm.FlattenFormFields();

using (Stream output = File.OpenWrite("Exported.pdf"))
{
	this.pdfViewer.Save(output);
}
Workaround: Export the document using the PdfFormatProvider:
this.pdfViewer.Document.AcroForm.FlattenFormFields();

using (Stream output = File.OpenWrite("Exported.pdf"))
{
	PdfFormatProvider provider = new PdfFormatProvider();
	provider.Export(this.pdfViewer.Document, output);
}

0 comments