Save Pdf with Free text annotations

I load a pdf document that has several pages in my pdfviewer. The user can add free text annotations on few pages. I want to create a new pdf with the pages in which annotations are present along with user annotations on them. Is this possible?


I load my PDF using snippet:

                var pdfDocument = new PdfDocument();

                PdfDocumentBase.Merge(pdfDocument, fileStream);

                MemoryStream stream = new MemoryStream();

                pdfDocument.Save(stream);


I explored ExportAsImage option. However it fails to create a new stream from the above stream.


                Stream[] stream = new Stream[2];

                int index = 0;


                foreach(var pageIndex in page.Value)

                {

                    var image = pdfCtrl.ExportAsImage(pageIndex); //say this is 0

                    image.Position = 0;

                    stream[index++] = image;

                }

                PdfDocument pdfDocument = new PdfDocument();

                PdfDocumentBase.Merge(pdfDocument, stream); <--fails with "

could not find valid signature ( pdf-)"


                MemoryStream ms = new MemoryStream();

                pdfDocument.Save(ms);


1 Reply

SP SarathKumar Prakash Syncfusion Team January 24, 2022 03:32 PM UTC

Hi Sri Velic, 
  
On analyzing your code,We found that you are sending image stream to PdfDocumentBase.Merge(pdfDocument, stream) method.It will cause the exception “could not find valid signature ( pdf-)”.You can send only pdf stream to that method.
You can refer below link about converting image stream to pdf stream.
https://help.syncfusion.com/file-formats/pdf/working-with-images?cs-save-lang=1&cs-lang=xamarin

We have also created simple sample which will helps you to create new pdf with the pages in which annotations are present along with user annotations 
Please find the sample from below link, 
Regards, 
Sarath Kumar. 


Loader.
Up arrow icon