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);
}this.pdfViewer.Document.AcroForm.FlattenFormFields();
using (Stream output = File.OpenWrite("Exported.pdf"))
{
PdfFormatProvider provider = new PdfFormatProvider();
provider.Export(this.pdfViewer.Document, output);
}
From the PDF Specification: "An ink annotation represents a freehand “scribble” composed of one or more disjoint paths. When opened, it displays a pop-up window containing the text of the associated note."
Sometimes the Ink annotations are imported as UnsupportedAnnotation and not displayed as expected. In such cases, the annotations could be removed from the RadFixedPage content in the following manner:
foreach (RadFixedPage page in document.Pages)
{
List<Annotation> inkAnnotations = page.Annotations.Where(a => a.Type == AnnotationType.Ink).ToList();
foreach (Annotation inkAnnotation in inkAnnotations)
{
page.Annotations.Remove(inkAnnotation);
}
}