예제 #1
0
        private void InitializeInputProperties(ref int propertyOrder)
        {
            Property inputPDFFilePathProperty = Properties.AddOrRetrieve(PropertyNames.InputFilePath, typeof(string), ValueUseOption.RuntimeRead, string.Empty);

            inputPDFFilePathProperty.Order       = propertyOrder++;
            inputPDFFilePathProperty.Description = "Path to the PDF file.";
            inputPDFFilePathProperty.Editor      = typeof(FilePathEditor);
            inputPDFFilePathProperty.Validations.Add(new RequiredValidator());

            VisibleDependency certVisibleDependency = new VisibleDependency(() => Properties.PropertyValueEquals(PropertyNames.InputAuthenticationType,
                                                                                                                 AuthenticationType.Certificate));

            void applyVisibility()
            {
                AuthenticationType authenticationTypeValue = Properties[PropertyNames.InputAuthenticationType].GetValue <AuthenticationType>();

                Properties[PropertyNames.InputPassword].IsVisible = authenticationTypeValue == AuthenticationType.Password;
            }

            void updateVisibility(object sender, EventArgs args)
            {
                applyVisibility();
                certVisibleDependency.Refresh();
            }

            Property authenticationTypeProperty = Properties.AddOrRetrieve(PropertyNames.InputAuthenticationType, typeof(AuthenticationType),
                                                                           ValueUseOption.DesignTime, AuthenticationType.None);

            authenticationTypeProperty.Order       = propertyOrder++;
            authenticationTypeProperty.Description = "Authentication type required to open the PDF file.";
            authenticationTypeProperty.Validations.Add(new CertificateAuthenticationValidator());
            authenticationTypeProperty.ValueChanged += updateVisibility;

            Property pdfPassword = Properties.AddOrRetrieve(PropertyNames.InputPassword, typeof(string), ValueUseOption.RuntimeRead, string.Empty);

            pdfPassword.Order       = propertyOrder++;
            pdfPassword.Description = "Password required to access the PDF file.";
            pdfPassword.Validations.Add(new RequiredValidator());

            Properties.InitializeCertificateProperties(
                PropertyNames.InputCertificateSource,
                PropertyNames.InputCertificateFilePath,
                PropertyNames.InputCertificateFilePassword,
                PropertyNames.InputCertificate,
                ref propertyOrder,
                certVisibleDependency);

            applyVisibility();
        }
예제 #2
0
        private void InitializeProperties()
        {
            int propertyOrder = 1;

            var fillFormDependency       = new VisibleDependency(() => Properties.PropertyValueEquals(PropertyNames.Operation, Operation.FillForm));
            var protectDependency        = new VisibleDependency(() => Properties.PropertyValueEquals(PropertyNames.Operation, Operation.Protect));
            var splitDependency          = new VisibleDependency(() => Properties.PropertyValueEquals(PropertyNames.Operation, Operation.Split));
            var concatenateDependency    = new VisibleDependency(() => Properties.PropertyValueEquals(PropertyNames.Operation, Operation.Concatenate));
            var notConcatenateDependency = new VisibleDependency(() => !Properties.PropertyValueEquals(PropertyNames.Operation, Operation.Concatenate));
            var addWatermarkDependency   = new VisibleDependency(() => Properties.PropertyValueEquals(PropertyNames.Operation, Operation.AddWatermark));
            var signDependency           = new VisibleDependency(() => Properties.PropertyValueEquals(PropertyNames.Operation, Operation.Sign));

            Property operation = Properties.AddOrRetrieve(PropertyNames.Operation, typeof(Operation), ValueUseOption.DesignTime, Operation.FillForm);

            operation.Order         = propertyOrder++;
            operation.Description   = "The operation to perform on the document.";
            operation.ValueChanged += RefreshOutput;
            operation.ValueChanged += (sender, args) =>
            {
                fillFormDependency.Refresh();
                protectDependency.Refresh();
                splitDependency.Refresh();
                concatenateDependency.Refresh();
                notConcatenateDependency.Refresh();
                addWatermarkDependency.Refresh();
                signDependency.Refresh();
            };

            InitializeInputProperties(notConcatenateDependency, ref propertyOrder);
            InitializeConcatenateProperties(concatenateDependency, ref propertyOrder);
            InitializeSplitProperties(splitDependency, ref propertyOrder);
            InitializeAddWatermarkProperties(addWatermarkDependency, ref propertyOrder);
            InitializeSignProperties(signDependency, ref propertyOrder);

            Property outputFilePath = Properties.AddOrRetrieve(PropertyNames.OutputFilePath, typeof(string), ValueUseOption.RuntimeRead, string.Empty);

            outputFilePath.Order       = propertyOrder++;
            outputFilePath.Description = "Path of the PDF file to write to.";
            outputFilePath.Editor      = typeof(FilePathEditor);
            outputFilePath.Validations.Add(new RequiredValidator());

            InitializeFillFormProperties(fillFormDependency, ref propertyOrder);
            InitializeProtectProperties(protectDependency, ref propertyOrder);
        }
예제 #3
0
        private void InitializeProtectProperties(VisibleDependency visibleDependency, ref int propertyOrder)
        {
            var protectCertDependency = new VisibleDependency(() => visibleDependency.Visible && Properties.PropertyValueEquals(PropertyNames.ProtectProtection, AuthenticationType.Certificate));

            Action <bool> applyVisibility = (isVisible) =>
            {
                AuthenticationType protectionValue = Properties[PropertyNames.ProtectProtection].GetValue <AuthenticationType>();
                bool addDocumentRestrictionsValue  = Properties[PropertyNames.ProtectAddDocumentRestrictions].GetValue <bool>();

                Properties[PropertyNames.ProtectProtection].IsVisible              = isVisible;
                Properties[PropertyNames.ProtectDocumentOpenPassword].IsVisible    = (isVisible && protectionValue == AuthenticationType.Password);
                Properties[PropertyNames.ProtectAddDocumentRestrictions].IsVisible = (isVisible && (protectionValue == AuthenticationType.Certificate || protectionValue == AuthenticationType.Password));
                Properties[PropertyNames.ProtectAllowPrinting].IsVisible           = (isVisible && addDocumentRestrictionsValue);
                Properties[PropertyNames.ProtectAllowChanges].IsVisible            = (isVisible && addDocumentRestrictionsValue);
                Properties[PropertyNames.ProtectAllowCopying].IsVisible            = (isVisible && addDocumentRestrictionsValue);
                Properties[PropertyNames.ProtectAllowScreenReaders].IsVisible      = (isVisible && addDocumentRestrictionsValue);
                Properties[PropertyNames.ProtectPermissionsPassword].IsVisible     = (isVisible && addDocumentRestrictionsValue && protectionValue == AuthenticationType.Password);
                Properties[PropertyNames.ProtectEncryption].IsVisible              = (isVisible && (protectionValue == AuthenticationType.Certificate || protectionValue == AuthenticationType.Password));
                Properties[PropertyNames.ProtectDontEncryptMetadata].IsVisible     = (isVisible && (protectionValue == AuthenticationType.Certificate || protectionValue == AuthenticationType.Password));
            };
            EventHandler updateVisibility = (sender, args) =>
            {
                applyVisibility(visibleDependency.Visible);
                protectCertDependency.Refresh();
            };

            visibleDependency.VisibleChanged += (visible) =>
            {
                applyVisibility(visible);
                protectCertDependency.Refresh();
            };

            Property protection = Properties.AddOrRetrieve(PropertyNames.ProtectProtection, typeof(AuthenticationType), ValueUseOption.DesignTime, AuthenticationType.None);

            protection.Order         = propertyOrder++;
            protection.Description   = "Method used to protect the PDF.";
            protection.ValueChanged += updateVisibility;

            Property documentOpenPassword = Properties.AddOrRetrieve(PropertyNames.ProtectDocumentOpenPassword, typeof(string), ValueUseOption.RuntimeRead, string.Empty);

            documentOpenPassword.Order       = propertyOrder++;
            documentOpenPassword.Description = "Password required to open the PDF document.";

            Properties.InitializeCertificateProperties(
                PropertyNames.ProtectCertificateSource,
                PropertyNames.ProtectCertificateFilePath,
                PropertyNames.ProtectCertificateFilePassword,
                PropertyNames.ProtectCertificate,
                ref propertyOrder,
                protectCertDependency);

            Property addDocumentRestrictions = Properties.AddOrRetrieve(PropertyNames.ProtectAddDocumentRestrictions, typeof(bool), ValueUseOption.DesignTime, false);

            addDocumentRestrictions.Order         = propertyOrder++;
            addDocumentRestrictions.Description   = "Specify restrictions on the PDF document.";
            addDocumentRestrictions.ValueChanged += updateVisibility;

            Property allowPrinting = Properties.AddOrRetrieve(PropertyNames.ProtectAllowPrinting, typeof(Printing), ValueUseOption.DesignTime, Printing.None);

            allowPrinting.Order       = propertyOrder++;
            allowPrinting.Description = "The level of printing allowed on the PDF document.";

            Property allowChanges = Properties.AddOrRetrieve(PropertyNames.ProtectAllowChanges, typeof(Changes), ValueUseOption.DesignTime, Changes.None);

            allowChanges.Order       = propertyOrder++;
            allowChanges.Description = "The editing actions allowed on the PDF document.";

            Property allowCopying = Properties.AddOrRetrieve(PropertyNames.ProtectAllowCopying, typeof(bool), ValueUseOption.DesignTime, false);

            allowCopying.Order         = propertyOrder++;
            allowCopying.Description   = "Enable copying of text, images and other content.";
            allowCopying.ValueChanged += (sender, args) =>
            {
                bool currentValue = Properties[PropertyNames.ProtectAllowCopying].GetValue <bool>();
                if (currentValue)
                {
                    Properties[PropertyNames.ProtectAllowScreenReaders].Value = true;
                }
            };

            Property allowScreenReaders = Properties.AddOrRetrieve(PropertyNames.ProtectAllowScreenReaders, typeof(bool), ValueUseOption.DesignTime, false);

            allowScreenReaders.Order       = propertyOrder++;
            allowScreenReaders.Description = "Enable text access for screen reader devices for the visually impaired.";

            Property permissionsPassword = Properties.AddOrRetrieve(PropertyNames.ProtectPermissionsPassword, typeof(string), ValueUseOption.RuntimeRead, string.Empty);

            permissionsPassword.Order       = propertyOrder++;
            permissionsPassword.Description = "Password to override restrictions placed on the PDF document.";
            permissionsPassword.Validations.Add(new RequiredValidator());

            Property encryption = Properties.AddOrRetrieve(PropertyNames.ProtectEncryption, typeof(Encryption), ValueUseOption.DesignTime, Encryption.AES128);

            encryption.Order       = propertyOrder++;
            encryption.Description = "Encryption method used to proptect the PDF.";

            Property dontEncryptMetadata = Properties.AddOrRetrieve(PropertyNames.ProtectDontEncryptMetadata, typeof(bool), ValueUseOption.DesignTime, false);

            dontEncryptMetadata.Order       = propertyOrder++;
            dontEncryptMetadata.Description = "Don't encrypt the document metadata.";

            applyVisibility(visibleDependency.Visible);
        }
        public static void InitializeInputFileProperties(
            this PropertyCollection properties,
            string inputFilePathPropertyName,
            string authenticationTypePropertyName,
            string passwordPropertyName,
            string certificateSourcePropertyName,
            string certificateFilePathPropertyName,
            string certificateFilePasswordPropertyName,
            string certificatePropertyName,
            bool supportCertificateAuthentication,
            ref int propertyOrder,
            VisibleDependency visibleDependency)
        {
            var           certVisibleDependency = new VisibleDependency(() => visibleDependency.Visible && properties.PropertyValueEquals(authenticationTypePropertyName, AuthenticationType.Certificate));
            Action <bool> applyVisibility       = (isVisible) =>
            {
                AuthenticationType authenticationTypeValue = properties[authenticationTypePropertyName].GetValue <AuthenticationType>();

                properties[inputFilePathPropertyName].IsVisible      = isVisible;
                properties[authenticationTypePropertyName].IsVisible = isVisible;
                properties[passwordPropertyName].IsVisible           = (isVisible && authenticationTypeValue == AuthenticationType.Password);
            };
            EventHandler updateVisibility = (sender, args) =>
            {
                applyVisibility(visibleDependency.Visible);
                certVisibleDependency.Refresh();
            };

            visibleDependency.VisibleChanged += (visible) =>
            {
                applyVisibility(visible);
                certVisibleDependency.Refresh();
            };

            Property pdfFilePath = properties.AddOrRetrieve(inputFilePathPropertyName, typeof(string), ValueUseOption.RuntimeRead, string.Empty);

            pdfFilePath.Order       = propertyOrder++;
            pdfFilePath.Description = "Path to the PDF file.";
            pdfFilePath.Editor      = typeof(FilePathEditor);
            pdfFilePath.Validations.Add(new RequiredValidator());

            Property authenticationType = properties.AddOrRetrieve(authenticationTypePropertyName, typeof(AuthenticationType), ValueUseOption.DesignTime, AuthenticationType.None);

            authenticationType.Order       = propertyOrder++;
            authenticationType.Description = "Authentication type required to open the PDF file.";
            if (!supportCertificateAuthentication)
            {
                authenticationType.Validations.Add(new CertificateAuthenticationValidator());
            }
            authenticationType.ValueChanged += updateVisibility;

            Property pdfPassword = properties.AddOrRetrieve(passwordPropertyName, typeof(string), ValueUseOption.RuntimeRead, string.Empty);

            pdfPassword.Order       = propertyOrder++;
            pdfPassword.Description = "Password required to access the PDF file.";
            pdfPassword.Validations.Add(new RequiredValidator());

            properties.InitializeCertificateProperties(
                certificateSourcePropertyName,
                certificateFilePathPropertyName,
                certificateFilePasswordPropertyName,
                certificatePropertyName,
                ref propertyOrder,
                certVisibleDependency);

            applyVisibility(visibleDependency.Visible);
        }