This is a migrated thread and some comments may be shown as answers.

Digital Signature Pls help

1 Answer 349 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
DeveloperTeam
Top achievements
Rank 1
DeveloperTeam asked on 26 Dec 2018, 01:15 AM
I tried to user your product and I have a problem.
I tried the following code to DigitalSign document and it says:
An unhandled exception of type 'System.NotSupportedException' occurred in mscorlib.dll

Additional information: Stream does not support reading.
Please help me what is problem?
Thank you
 X509Certificate2 certificate = new X509Certificate2("JohnDoe.pfx", "johndoe");
            // The name of the signature must be unique.
            string signatureName = "SampleSignature";

            // This is the Form XObject element that represents the contents of the signature field.
            Telerik.Windows.Documents.Fixed.Model.Objects.Form form = new Telerik.Windows.Documents.Fixed.Model.Objects.Form();
            form.FormSource = new FormSource();
            form.FormSource.Size = new System.Windows.Size(120, 120);

            // We will use the editor to fill the Form XObject.
            FixedContentEditor formEditor = new FixedContentEditor(form.FormSource);
            formEditor.DrawCircle(new System.Windows.Point(50, 50), 20);
            formEditor.DrawText(signatureName);

            // The Signature object is added to a signature field, so we can add a visualization to it.
            SignatureField signatureField = new SignatureField(signatureName);
            signatureField.Signature = new Signature(certificate);

            // The widget contains the Form XObject and defines the appearance of the signature field.
            SignatureWidget widget = signatureField.Widgets.AddWidget();
            widget.Rect = new Rect(new System.Windows.Point(200, 600), new System.Windows.Size(100, 100));
            widget.Border = new AnnotationBorder(10, AnnotationBorderStyle.Solid, null);
            widget.Content.NormalContentSource = form.FormSource;
            widget.RecalculateContent();

            // The Widget class inherits from Annotation. And, as any other annotation, must be added to the respective collection of the page.

            RadFixedDocument document = new RadFixedDocument();
            RadFixedPage page = document.Pages.AddPage();
            page.Annotations.Add(widget);
            document.AcroForm.FormFields.Add(signatureField);

            using (Stream stream = File.OpenWrite("signed.pdf"))
            {
                new PdfFormatProvider().Export(document, stream);
            }

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 27 Dec 2018, 02:58 PM
Hello Dragan,

I answered in another ticket that you open about this unexpected behavior but will paste the answer here to share the information with the community.

After reviewing the presented code snippet, it seems that our code snippet is not correct and the exception was caused because read-only FileStream object is passed to the FileStream.Write method. We will do our best to fix the documentation article as soon as possible. Please take a look at this article in Microsoft documentation for reference. You can replace the Write method with Open and use FileMode.OpenOrCreate as a parameter of the method. Please take a look of the code snippet below for example:
using (Stream stream = File.Open("signed.pdf", FileMode.OpenOrCreate))
{
      new PdfFormatProvider().Export(document, stream);
}

I hope that this helps.

Regards,
Martin
Progress Telerik
Get quickly and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PdfProcessing
Asked by
DeveloperTeam
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or