Esempio n. 1
0
        public void SignImagePdf()
        {
            // Set request
            var testFile       = TestFiles.PdfStorage.FirstOrDefault();
            var fileInfo       = testFile.GetFileInfo();
            var signedFileName = $@"Output\PdfImageSigned.{testFile.Extension}";

            var options = new SignImageOptions();

            PopulateOptions(options);
            var signSettings = new SignSettings();

            signSettings.FileInfo    = fileInfo;
            signSettings.SaveOptions = new SaveOptions()
            {
                OutputFilePath = signedFileName
            };
            signSettings.Options = new List <SignOptions>()
            {
                options
            };
            var request = new CreateSignaturesRequest(signSettings);

            // Get and check result
            var response = SignatureApi.CreateSignatures(request);

            CheckResponse(response, testFile);

            //Download the signed file
            this.DownloadFile(signedFileName);
        }
        public void SignCollectionPdf()
        {
            // Set request
            var testFile       = TestFiles.PdfStorage.FirstOrDefault();
            var fileInfo       = testFile.GetFileInfo();
            var signedFileName = $@"Output\PdfCollectionSigned.{testFile.Extension}";

            var optionsBarcode = new SignBarcodeOptions();

            TestsSignBarcode.PopulateOptions(optionsBarcode);
            optionsBarcode.Top = 0;

            var optionsQrCode = new SignQRCodeOptions();

            TestsSignQrCode.PopulateOptions(optionsQrCode);
            optionsQrCode.Top = optionsBarcode.Height + 20;

            var optionsDigital = new SignDigitalOptions();

            TestsSignDigital.PopulateOptions(optionsDigital);
            optionsDigital.Top = optionsQrCode.Top + optionsQrCode.Height + 20;

            var optionsText = new SignTextOptions();

            TestsSignText.PopulateOptions(optionsText);
            optionsText.Top = optionsDigital.Top + optionsDigital.Height + 20;

            var optionsImage = new SignImageOptions();

            TestsSignImage.PopulateOptions(optionsImage);
            optionsImage.Top = optionsText.Top + optionsText.Height + 20;

            var optionsStamp = new SignStampOptions();

            TestsSignStamp.PopulateOptions(optionsStamp);
            optionsStamp.Top = optionsImage.Top + optionsImage.Height + 20;

            var signSettings = new SignSettings();

            signSettings.FileInfo    = fileInfo;
            signSettings.SaveOptions = new SaveOptions()
            {
                OutputFilePath = signedFileName
            };
            signSettings.Options = new List <SignOptions>()
            {
                optionsBarcode, optionsQrCode, optionsDigital, optionsText, optionsImage, optionsStamp
            };
            var request = new CreateSignaturesRequest(signSettings);

            // Get and check result
            var response = SignatureApi.CreateSignatures(request);

            CheckResponse(response, testFile);

            //Download the signed file
            this.DownloadFile(signedFileName);
        }
Esempio n. 3
0
        public static void PopulateOptions(SignImageOptions options)
        {
            options.SignatureType = SignatureTypeEnum.Image;

            // set signature properties
            options.ImageFilePath = @"Additional\JohnSmithSign.png";

            // set signature position on a page
            options.Left   = 100;
            options.Top    = 100;
            options.Width  = 200;
            options.Height = 100;
            options.LocationMeasureType = SignImageOptions.LocationMeasureTypeEnum.Pixels;
            options.SizeMeasureType     = SignImageOptions.SizeMeasureTypeEnum.Pixels;
            options.RotationAngle       = 0;
            options.HorizontalAlignment = SignImageOptions.HorizontalAlignmentEnum.None;
            options.VerticalAlignment   = SignImageOptions.VerticalAlignmentEnum.None;
            options.Margin = new Padding()
            {
                All = 5
            };
            options.MarginMeasureType = SignImageOptions.MarginMeasureTypeEnum.Pixels;

            // set signature appearance
            options.Transparency = 0.8;

            //set pages for signing (each of these page settings could be used singly)
            options.Page       = 1;
            options.AllPages   = true;
            options.PagesSetup = new PagesSetup()
            {
                EvenPages   = false,
                FirstPage   = true,
                LastPage    = false,
                OddPages    = false,
                PageNumbers = new List <int?>()
                {
                    1
                }
            };
            options.SignatureType = SignatureTypeEnum.Image;
        }
        protected internal string SignDocumentWithImage(string rootPath,
                                                        string fileName,
                                                        Stream imageStream,
                                                        int pageNumber,
                                                        int left,
                                                        int top,
                                                        int width,
                                                        int height,
                                                        int signatureColumnNum, int signatureRowNum)
        {
            string storagePath = rootPath;
            string outputPath  = Path.Combine(rootPath, @"Output");
            string imagesPath  = Path.Combine(rootPath, @"Images");

            // set up a configuration
            SignatureConfig config = new SignatureConfig()
            {
                StoragePath = storagePath,
                OutputPath  = outputPath,
                ImagesPath  = imagesPath
            };

            // instantiating the handler
            SignatureHandler handler = new SignatureHandler(config);

            // Set a license if you have one
            _licensing.ApplyLicense();

            // setup PDF image signature options
            SignImageOptions signOptions       = null;
            string           fileNameExtension = Path.GetExtension(fileName).TrimStart('.');

            fileNameExtension = fileNameExtension.ToLower();
            int pageWidth = 0, pageHeight = 0;
            DocumentViewType fileType = GetDocumentType(fileNameExtension);

            switch (fileType)
            {
            case DocumentViewType.Pdf:
                signOptions = new PdfSignImageOptions(imageStream);
                break;

            case DocumentViewType.Words:
                signOptions = new WordsSignImageOptions(imageStream);
                break;

            case DocumentViewType.Cells:
                signOptions = new CellsSignImageOptions(imageStream)
                {
                    ColumnNumber = signatureColumnNum,
                    RowNumber    = signatureRowNum
                };
                break;

            case DocumentViewType.Slides:
                signOptions = new SlidesSignImageOptions(imageStream);
                break;
            }
            signOptions.DocumentPageNumber = pageNumber;
            signOptions.Left         = left;
            signOptions.Top          = top;
            signOptions.Width        = width;
            signOptions.Height       = height;
            signOptions.SignAllPages = false;

            GroupDocs.Signature.Options.SaveOptions saveOptions = new GroupDocs.Signature.Options.SaveOptions(OutputType.String);
            // sign the document
            string outputFilePath = handler.Sign <string>(fileName, signOptions, saveOptions);

            return(outputFilePath);
        }