Exemple #1
0
        private static void SignExisting()
        {
            string              text        = string.Format("SignExisting.pdf", new object[0]);
            PdfDocument         pdfDocument = PdfReader.Open(new MemoryStream(Resources.doc1));
            PdfSignatureOptions options     = new PdfSignatureOptions
            {
                ContactInfo       = "Contact Info",
                Location          = "Paris",
                Reason            = "Test signatures",
                Rectangle         = new XRect(36.0, 735.0, 200.0, 50.0),
                AppearanceHandler = new Program.SignAppearenceHandler()
            };
            //PdfSignatureHandler pdfSignatureHandler = new PdfSignatureHandler(new DefaultSigner(Program.GetCertificate()), null, options);
            PdfSignatureHandler pdfSignatureHandler = new PdfSignatureHandler(new BouncySigner(Program.GetCertificate()), null, options);

            pdfSignatureHandler.AttachToDocument(pdfDocument);
            pdfDocument.Save(text);
            Process.Start(text);
        }
        private static void signPdfFile(string sourceDocument, string destinationPath, string privateKeyFile, string keyPassword, string reason, string location)
        {
            using (FileStream originalFileStream = new FileStream(sourceDocument, System.IO.FileMode.Open))
            {
                PdfDocument pdfDocument = PdfReader.Open(originalFileStream);

                PdfSignatureOptions options = new PdfSignatureOptions
                {
                    ContactInfo = "",
                    Location    = location,
                    Reason      = reason,
                    //Rectangle = new XRect(36.0, 735.0, 200.0, 50.0),
                    //AppearanceHandler = new Program.SignAppearenceHandler()
                };
                //PdfSignatureHandler pdfSignatureHandler = new PdfSignatureHandler(new DefaultSigner(Program.GetCertificate()), null, options);
                PdfSignatureHandler pdfSignatureHandler = new PdfSignatureHandler(getCertificate(privateKeyFile, keyPassword), null, options);
                pdfSignatureHandler.AttachToDocument(pdfDocument);
                pdfDocument.Save(destinationPath);
                Process.Start(destinationPath);
            }
        }
Exemple #3
0
        private static void CreateAndSign()
        {
            string      text            = "CreateAndSign.pdf";
            XFont       font            = new XFont("Verdana", 10.0, XFontStyle.Regular);
            PdfDocument pdfDocument     = new PdfDocument();
            PdfPage     pdfPage         = pdfDocument.AddPage();
            XGraphics   xGraphics       = XGraphics.FromPdfPage(pdfPage);
            XRect       layoutRectangle = new XRect(0.0, 0.0, pdfPage.Width, pdfPage.Height);

            xGraphics.DrawString("Sample document", font, XBrushes.Black, layoutRectangle, XStringFormats.TopCenter);
            PdfSignatureOptions options = new PdfSignatureOptions
            {
                ContactInfo = "Contact Info",
                Location    = "Paris",
                Reason      = "Test signatures",
                Rectangle   = new XRect(36.0, 700.0, 200.0, 50.0)
            };
            PdfSignatureHandler pdfSignatureHandler = new PdfSignatureHandler(new DefaultSigner(Program.GetCertificate()), null, options);

            //PdfSignatureHandler pdfSignatureHandler = new PdfSignatureHandler(new BouncySigner(Program.GetCertificate()), null, options);
            pdfSignatureHandler.AttachToDocument(pdfDocument);
            pdfDocument.Save(text);
            Process.Start(text);
        }