GetBatchDocContent() public static method

public static GetBatchDocContent ( int id ) : byte[]
id int
return byte[]
Example #1
0
        public static string Start(int id)
        {
            // Get an instance of the PadesSignatureStarter class, responsible for receiving the signature elements and start the
            // signature process
            var signatureStarter = new PadesSignatureStarter(Util.GetRestPkiClient())
            {
                // Set the unit of measurement used to edit the pdf marks and visual representations
                MeasurementUnits = PadesMeasurementUnits.Centimeters,

                // Set the signature policy
                SignaturePolicyId = StandardPadesSignaturePolicies.Basic,

                // Set the security context to be used to determine trust in the certificate chain
                SecurityContextId = Util.GetSecurityContextId(),

                // Set a visual representation for the signature (see function below)
                VisualRepresentation = getVisualRepresentation(),
            };

            /*
             * Optionally, add marks to the PDF before signing. These differ from the signature visual representation in that
             * they are actually changes done to the document prior to signing, not binded to any signature. Therefore, any number
             * of marks can be added, for instance one per page, whereas there can only be one visual representation per signature.
             * However, since the marks are in reality changes to the PDF, they can only be added to documents which have no previous
             * signatures, otherwise such signatures would be made invalid by the changes to the document (see property
             * PadesSignatureStarter.BypassMarksIfSigned). This problem does not occurr with signature visual representations.
             *
             * We have encapsulated this code in a method to include several possibilities depending on the argument passed.
             * Experiment changing the argument to see different examples of PDF marks. Once you decide which is best for your case,
             * you can place the code directly here.
             */
            //signatureStarter.PdfMarks.Add(PadesVisualElements.GetPdfMark(1));

            // Set the PDF to be signed
            signatureStarter.SetPdfToSign(Util.GetBatchDocContent(id));

            // Call the StartWithWebPki() method, which initiates the signature. This yields the token, a 43-character
            // case-sensitive URL-safe string, which identifies this signature process. We'll use this value to call the
            // signWithRestPki() method on the Web PKI component (see batch-signature-optimized-form.js) and also to complete
            // the signature on the POST action below (this should not be mistaken with the API access token).
            var token = signatureStarter.StartWithWebPki();

            // Send to the javascript the token of the signature process to be used to call Web PKI to perform the signature
            return(token);
        }
Example #2
0
        private void startNextSignature()
        {
            // Increment the index of the document currently being signed
            DocumentIndex += 1;

            // Check if we have reached the end of the batch, in which case we fill the hidden field "TokenField" with value "(end)",
            // which signals to the javascript on batch-signature-form.js that the process is completed and the page can be unblocked.
            if (DocumentIndex == DocumentIds.Count)
            {
                TokenField.Value = "(end)";
                return;
            }

            // Get the ID of the document currently being signed
            var docId = DocumentIds[DocumentIndex];

            string token;

            try {
                // Get an instance of the PadesSignatureStarter class, responsible for receiving the signature elements and start the
                // signature process
                var signatureStarter = new PadesSignatureStarter(Util.GetRestPkiClient())
                {
                    // Set the unit of measurement used to edit the pdf marks and visual representations
                    MeasurementUnits = PadesMeasurementUnits.Centimeters,

                    // Set the signature policy
                    SignaturePolicyId = StandardPadesSignaturePolicies.Basic,

                    // Set the security context to be used to determine trust in the certificate chain
                    SecurityContextId = Util.GetSecurityContextId(),

                    // Set a visual representation for the signature (see function below)
                    VisualRepresentation = getVisualRepresentation(),
                };

                /*
                 * Optionally, add marks to the PDF before signing. These differ from the signature visual representation in that
                 * they are actually changes done to the document prior to signing, not binded to any signature. Therefore, any number
                 * of marks can be added, for instance one per page, whereas there can only be one visual representation per signature.
                 * However, since the marks are in reality changes to the PDF, they can only be added to documents which have no previous
                 * signatures, otherwise such signatures would be made invalid by the changes to the document (see property
                 * PadesSignatureStarter.BypassMarksIfSigned). This problem does not occurr with signature visual representations.
                 *
                 * We have encapsulated this code in a method to include several possibilities depending on the argument passed.
                 * Experiment changing the argument to see different examples of PDF marks. Once you decide which is best for your case,
                 * you can place the code directly here.
                 */
                //signatureStarter.PdfMarks.Add(PadesVisualElements.GetPdfMark(1));

                // Set the PDF to be signed
                signatureStarter.SetPdfToSign(Util.GetBatchDocContent(docId));

                // Call the StartWithWebPki() method, which initiates the signature.
                token = signatureStarter.StartWithWebPki();
            } catch (ValidationException ex) {
                // One or more validations failed. We log the error, update the page with a summary of what happened to this document and start the next signature
                setValidationError(ex.ValidationResults);
                startNextSignature();
                return;
            } catch (Exception ex) {
                // An error has occurred. We log the error, update the page with a summary of what happened to this document and start the next signature
                setError(ex.Message);
                startNextSignature();
                return;
            }

            // Send to the javascript the token of the signature process to be used to call Web PKI to perform the signature
            TokenField.Value = token;
        }