Flatten annotations doesn't work in UWP

Hi guys! I have problems with flattening annotations in PDF documents. None of the approaches I've tried so far works. Please see the demo, files, and project attached. 


To be noticed: Very often when I try to load the previously saved file (with the help of await this.SfPdfViewerControl.SaveAsync();) that contains any kind of stamp (added with SfPdfViewerControl.AddStamp();) I get a crush with error message exception "An item with the same key has already been added. Key: 1_CustomView1". But I guess this issue is not related to flattened annotations.


I appreciate any help you can provide!


Attachment: flattenAnnotationsIssue_c2e1038a.zip


3 Replies 1 reply marked as answer

DR Deepika Ravi Syncfusion Team March 29, 2024 06:18 AM UTC

Hi Roxy,

Natively, we don't have support to flatten annotations from the viewer. From the sample, we were able to see that you are trying to flatten the annotations using our library directly from the Loadedocument that is available in SfPdfViewerControl, but this LoadedDocment is not updated every time annotations are added. You need to save the document and convert it to a loaded document before saving or loading it again in the viewer.

Kindly refer to the following code to flatten and save for reference.

var stream = await this.SfPdfViewerControl.SaveAsync();

PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream);

loadedDocument.FlattenAnnotations();

loadedDocument.Save(stream);

stream.Position = 0;

await StorageItemPickerProvider.Instance.SaveStreamToFile(this.file, stream);


Regards,

Deepika R


Marked as answer

RC Roxy Cole April 2, 2024 12:48 AM UTC

It works, thank you for solution!



MA ManojKumar Arumugasamy Syncfusion Team April 2, 2024 04:54 AM UTC

Thank you for your reply. I'm glad to hear that the provided solution works for your scenario. We're marking this ticket as closed.

If you have any other questions or concerns, please don't hesitate to contact us.


Loader.
Up arrow icon