コード例 #1
0
        private void PdfSelect_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                if (fileDialog.FileName.Contains("pdf"))
                {
                    PdfForm frm = new PdfForm();
                    frm.Text = System.IO.Path.GetFileName(fileDialog.FileName);
                    frm.OpenDocument(fileDialog.FileName);
                    frm.Show(this.dockPanel1);
                    frm.Activate();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        //protected override void OnNavigatedTo(NavigationEventArgs e)
        //{
        //}

        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            PdfDocument document = new PdfDocument();

            PdfPageBase page     = document.Pages.Add();
            PdfGraphics graphics = page.Graphics;

            PdfStandardFont font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold);
            PdfBrush        brush = PdfBrushes.Black;
            PdfForm         form  = document.Form;

            //Document security
            PdfSecurity security = document.Security;

            //Specify key size and encryption algorithm
            if (encryptionTechnique.SelectionBoxItem.ToString() == "40-Bit RC4")
            {
                //use 40 bits key in RC4 mode
                security.KeySize   = PdfEncryptionKeySize.Key40Bit;
                security.Algorithm = PdfEncryptionAlgorithm.RC4;
            }
            else if (encryptionTechnique.SelectionBoxItem.ToString() == "128-Bit RC4")
            {
                //use 128 bits key in RC4 mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.RC4;
            }
            else if (encryptionTechnique.SelectionBoxItem.ToString() == "128-Bit AES")
            {
                //use 128 bits key in RC4 mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (encryptionTechnique.SelectionBoxItem.ToString() == "256-Bit AES")
            {
                //use 256 bits key in AES mode
                security.KeySize   = PdfEncryptionKeySize.Key256Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (encryptionTechnique.SelectionBoxItem.ToString() == "256-Bit AES Revision 6")
            {
                //use 256 bits key in AES mode with Revision 6
                security.KeySize   = PdfEncryptionKeySize.Key256BitRevision6;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            if (!cmbencryptOption.IsEnabled || cmbencryptOption.SelectedIndex == 0)
            {
                security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContents;
            }
            else if (cmbencryptOption.SelectedIndex == 1)
            {
                security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContentsExceptMetadata;
            }
            else if (cmbencryptOption.SelectedIndex == 2)
            {
                //Read the file
                Stream imgStream = typeof(Encryption).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Products.xml");

                PdfAttachment attachment = new PdfAttachment("Products.xml", imgStream);

                attachment.ModificationDate = DateTime.Now;

                attachment.Description = "About Syncfusion";

                attachment.MimeType = "application/txt";

                //Adds the attachment to the document
                document.Attachments.Add(attachment);

                security.EncryptionOptions = PdfEncryptionOptions.EncryptOnlyAttachments;
            }
            security.OwnerPassword = txtOwnerPassword.Password;
            security.Permissions   = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint;
            security.UserPassword  = txtUserPassword.Password;

            string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" +
                                                                  "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm);

            if (encryptionTechnique.SelectionBoxItem.ToString() == "256-Bit AES Revision 6")
            {
                text += String.Format("\n\nRevision: {0}", "Revision6");
            }
            else if (encryptionTechnique.SelectionBoxItem.ToString() == "256-Bit AES")
            {
                text += String.Format("\n\nRevision: {0}", "Revision5");
            }

            graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty);
            font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16f, PdfFontStyle.Bold);
            graphics.DrawString(text, font, brush, new PointF(0, 40));

            MemoryStream stream = new MemoryStream();
            await document.SaveAsync(stream);

            document.Close(true);
            Save(stream, "FormFilling.pdf");
        }
コード例 #3
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.Pages.Add();
            PdfGraphics graphics = page.Graphics;

            PdfStandardFont font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold);
            PdfBrush        brush = PdfBrushes.Black;
            PdfForm         form  = document.Form;

            //Document security
            PdfSecurity security = document.Security;

            //Specify key size and encryption algorithm
            if (rdButton40Bit.Checked)
            {
                //use 40 bits key in RC4 mode
                security.KeySize = PdfEncryptionKeySize.Key40Bit;
            }
            else if (rdButton128Bit.Checked && rdButtonRC4.Checked)
            {
                //use 128 bits key in RC4 mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.RC4;
            }
            else if (rdButton128Bit.Checked && rdButtonAES.Checked)
            {
                //use 128 bits key in AES mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (rdButton256Bit.Checked)
            {
                //use 256 bits key in AES mode
                security.KeySize   = PdfEncryptionKeySize.Key256Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (rdButton256BitRevision6.Checked)
            {
                security.KeySize   = PdfEncryptionKeySize.Key256BitRevision6;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            if (cmbEncrypt.SelectedIndex == 0 || !cmbEncrypt.Enabled)
            {
                security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContents;
            }
            else if (cmbEncrypt.SelectedIndex == 1)
            {
                security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContentsExceptMetadata;
            }
            else if (cmbEncrypt.SelectedIndex == 2)
            {
                security.EncryptionOptions = PdfEncryptionOptions.EncryptOnlyAttachments;
                //Read the file
                FileStream file = new FileStream(GetFullTemplatePath("Products.xml", false), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                //Creates an attachment
                PdfAttachment attachment = new PdfAttachment("Products.xml", file);

                attachment.ModificationDate = DateTime.Now;

                attachment.Description = "About Syncfusion";

                attachment.MimeType = "application/txt";

                //Adds the attachment to the document
                document.Attachments.Add(attachment);
            }

            security.OwnerPassword = "******";
            security.Permissions   = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint;
            security.UserPassword  = "******";

            string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" +
                                                                  "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm);

            if (rdButton256BitRevision6.Checked)
            {
                text += String.Format("\n\nRevision: {0}", "Revision6");
            }
            else if (rdButton256Bit.Checked)
            {
                text += String.Format("\n\nRevision: {0}", "Revision5");
            }

            graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty);
            font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16f, PdfFontStyle.Bold);
            graphics.DrawString(text, font, brush, new PointF(0, 40));

            document.Save("Sample.pdf");

            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
#if NETCORE
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                {
                    UseShellExecute = true
                };
                process.Start();
#else
                System.Diagnostics.Process.Start("Sample.pdf");
#endif
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
        }
コード例 #4
0
        private float DrawFormField(XPathNavigator fieldNode, PdfForm form, PdfPageBase page, float y, int fieldIndex)
        {
            float width   = page.Canvas.ClientSize.Width;
            float padding = 2;

            //measure field label
            String          label         = fieldNode.GetAttribute("label", "");
            PdfTrueTypeFont font1         = new PdfTrueTypeFont(new Font("Arial", 9f));
            PdfStringFormat format        = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            float           labelMaxWidth = width * 0.4f - 2 * padding;
            SizeF           labelSize     = font1.MeasureString(label, labelMaxWidth, format);

            //measure field height
            float fieldHeight = MeasureFieldHeight(fieldNode);

            float height = labelSize.Height > fieldHeight ? labelSize.Height : fieldHeight;

            height = height + 2;

            //draw background
            PdfBrush brush = PdfBrushes.SteelBlue;

            if (fieldIndex % 2 == 1)
            {
                brush = PdfBrushes.LightGreen;
            }
            page.Canvas.DrawRectangle(brush, 0, y, width, height);

            //draw field label
            PdfBrush   brush1      = PdfBrushes.LightYellow;
            RectangleF labelBounds = new RectangleF(padding, y, labelMaxWidth, height);

            page.Canvas.DrawString(label, font1, brush1, labelBounds, format);

            //daw field
            float  fieldMaxWidth = width * 0.57f - 2 * padding;
            float  fieldX        = labelBounds.Right + 2 * padding;
            float  fieldY        = y + (height - fieldHeight) / 2;
            String fieldType     = fieldNode.GetAttribute("type", "");
            String fieldId       = fieldNode.GetAttribute("id", "");
            bool   required      = "true" == fieldNode.GetAttribute("required", "");

            switch (fieldType)
            {
            case "text":
            case "password":
                PdfTextBoxField textField = new PdfTextBoxField(page, fieldId);
                textField.Bounds      = new RectangleF(fieldX, fieldY, fieldMaxWidth, fieldHeight);
                textField.BorderWidth = 0.75f;
                textField.BorderStyle = PdfBorderStyle.Solid;
                textField.Required    = required;
                if ("password" == fieldType)
                {
                    textField.Password = true;
                }
                if ("true" == fieldNode.GetAttribute("multiple", ""))
                {
                    textField.Multiline  = true;
                    textField.Scrollable = true;
                }
                form.Fields.Add(textField);
                break;

            case "checkbox":
                PdfCheckBoxField checkboxField  = new PdfCheckBoxField(page, fieldId);
                float            checkboxWidth  = fieldHeight - 2 * padding;
                float            checkboxHeight = checkboxWidth;
                checkboxField.Bounds      = new RectangleF(fieldX, fieldY + padding, checkboxWidth, checkboxHeight);
                checkboxField.BorderWidth = 0.75f;
                checkboxField.Style       = PdfCheckBoxStyle.Cross;
                checkboxField.Required    = required;
                form.Fields.Add(checkboxField);
                break;

            case "list":
                XPathNodeIterator itemNodes = fieldNode.Select("item");
                if ("true" == fieldNode.GetAttribute("multiple", ""))
                {
                    PdfListBoxField listBoxField = new PdfListBoxField(page, fieldId);
                    listBoxField.Bounds      = new RectangleF(fieldX, fieldY, fieldMaxWidth, fieldHeight);
                    listBoxField.BorderWidth = 0.75f;
                    listBoxField.MultiSelect = true;
                    listBoxField.Font        = new PdfFont(PdfFontFamily.Helvetica, 9f);
                    listBoxField.Required    = required;
                    //add items into list box.
                    foreach (XPathNavigator itemNode in itemNodes)
                    {
                        String text = itemNode.SelectSingleNode("text()").Value;
                        listBoxField.Items.Add(new PdfListFieldItem(text, text));
                    }
                    listBoxField.SelectedIndex = 0;
                    form.Fields.Add(listBoxField);

                    break;
                }
                if (itemNodes != null && itemNodes.Count <= 3)
                {
                    PdfRadioButtonListField radioButtonListFile
                        = new PdfRadioButtonListField(page, fieldId);
                    radioButtonListFile.Required = required;
                    //add items into radio button list.
                    float fieldItemHeight   = fieldHeight / itemNodes.Count;
                    float radioButtonWidth  = fieldItemHeight - 2 * padding;
                    float radioButtonHeight = radioButtonWidth;
                    foreach (XPathNavigator itemNode in itemNodes)
                    {
                        String text = itemNode.SelectSingleNode("text()").Value;
                        PdfRadioButtonListItem fieldItem = new PdfRadioButtonListItem(text);
                        fieldItem.BorderWidth = 0.75f;
                        fieldItem.Bounds      = new RectangleF(fieldX, fieldY + padding, radioButtonWidth, radioButtonHeight);
                        radioButtonListFile.Items.Add(fieldItem);

                        float fieldItemLabelX    = fieldX + radioButtonWidth + padding;
                        SizeF fieldItemLabelSize = font1.MeasureString(text);
                        float fieldItemLabelY    = fieldY + (fieldItemHeight - fieldItemLabelSize.Height) / 2;
                        page.Canvas.DrawString(text, font1, brush1, fieldItemLabelX, fieldItemLabelY);

                        fieldY = fieldY + fieldItemHeight;
                    }
                    form.Fields.Add(radioButtonListFile);

                    break;
                }

                //combo box
                PdfComboBoxField comboBoxField = new PdfComboBoxField(page, fieldId);
                comboBoxField.Bounds      = new RectangleF(fieldX, fieldY, fieldMaxWidth, fieldHeight);
                comboBoxField.BorderWidth = 0.75f;
                comboBoxField.Font        = new PdfFont(PdfFontFamily.Helvetica, 9f);
                comboBoxField.Required    = required;
                //add items into combo box.
                foreach (XPathNavigator itemNode in itemNodes)
                {
                    String text = itemNode.SelectSingleNode("text()").Value;
                    comboBoxField.Items.Add(new PdfListFieldItem(text, text));
                }
                form.Fields.Add(comboBoxField);
                break;
            }

            if (required)
            {
                //draw *
                float           flagX = width * 0.97f + padding;
                PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
                SizeF           size  = font3.MeasureString("*");
                float           flagY = y + (height - size.Height) / 2;
                page.Canvas.DrawString("*", font3, PdfBrushes.Red, flagX, flagY);
            }

            return(y + height);
        }
コード例 #5
0
        public void OnButtonClicked(object sender, EventArgs e)
        {
            //Create new PDF document.
            PdfDocument document = new PdfDocument();

            //Add page to the PDF document.
            PdfPage page = document.Pages.Add();

            PdfGraphics graphics = page.Graphics;

            //Create font object.
            PdfStandardFont font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Bold);
            PdfBrush        brush = PdfBrushes.Black;
            PdfForm         form  = document.Form;

            //Document security
            PdfSecurity security = document.Security;

            if (this.Algorithms.Items[this.Algorithms.SelectedIndex] == "AES")
            {
                security.Algorithm = PdfEncryptionAlgorithm.AES;
                if (this.keysize.SelectedIndex == 0)
                {
                    security.KeySize = PdfEncryptionKeySize.Key128Bit;
                }
                else if (this.keysize.SelectedIndex == 1)
                {
                    security.KeySize = PdfEncryptionKeySize.Key256Bit;
                }
                else if (this.keysize.SelectedIndex == 2)
                {
                    security.KeySize = PdfEncryptionKeySize.Key256BitRevision6;
                }
            }
            else if (this.Algorithms.Items[this.Algorithms.SelectedIndex] == "RC4")
            {
                security.Algorithm = PdfEncryptionAlgorithm.RC4;
                if (this.keysize.SelectedIndex == 0)
                {
                    security.KeySize = PdfEncryptionKeySize.Key40Bit;
                }
                else if (this.keysize.SelectedIndex == 1)
                {
                    security.KeySize = PdfEncryptionKeySize.Key128Bit;
                }
            }

            if (this.Options.Items[this.Options.SelectedIndex] == "Encrypt all contents")
            {
                security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContents;
            }
            else if (this.Options.Items[this.Options.SelectedIndex] == "Encrypt all contents except metadata")
            {
                security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContentsExceptMetadata;
            }
            else if (this.Options.Items[this.Options.SelectedIndex] == "Encrypt only attachments")
            {
                //Read the file
#if COMMONSB
                Stream file = typeof(Encryption).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Samples.Assets.Products.xml");
#else
                Stream file = typeof(Encryption).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.PDF.Samples.Assets.Products.xml");
#endif

                //Creates an attachment
                PdfAttachment attachment = new PdfAttachment("Products.xml", file);

                attachment.ModificationDate = DateTime.Now;

                attachment.Description = "About Syncfusion";

                attachment.MimeType = "application/txt";

                //Adds the attachment to the document
                document.Attachments.Add(attachment);

                security.EncryptionOptions = PdfEncryptionOptions.EncryptOnlyAttachments;
            }

            security.OwnerPassword = "******";
            security.Permissions   = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint;
            security.UserPassword  = "******";

            string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" +
                                                                  "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm);
            if (this.Algorithms.SelectedIndex == 1)
            {
                if (this.keysize.SelectedIndex == 2)
                {
                    text += String.Format("\n\nRevision: {0}", "Revision 6");
                }
                else if (this.keysize.SelectedIndex == 1)
                {
                    text += String.Format("\n\nRevision: {0}", "Revision 5");
                }
            }

            graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty);
            font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f, PdfFontStyle.Bold);
            graphics.DrawString(text, font, brush, new PointF(0, 40));

            MemoryStream stream = new MemoryStream();
            //Save the PDF document.
            document.Save(stream);

            if (Device.RuntimePlatform == Device.UWP)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("Secured.pdf", "application/pdf", stream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save("Secured.pdf", "application/pdf", stream);
            }
        }
        public void OnButtonClicked(object sender, EventArgs e)
        {
            //Create new PDF document.
            PdfDocument document = new PdfDocument();

            //Add page to the PDF document.
            PdfPage page = document.Pages.Add();

            PdfGraphics graphics = page.Graphics;

            //Create font object.
            PdfStandardFont font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Bold);
            PdfBrush        brush = PdfBrushes.Black;
            PdfForm         form  = document.Form;

            //Document security
            PdfSecurity security = document.Security;

            if (this.Algorithms.Items[this.Algorithms.SelectedIndex] == "AES")
            {
                security.Algorithm = PdfEncryptionAlgorithm.AES;
                if (this.keysize.SelectedIndex == 0)
                {
                    security.KeySize = PdfEncryptionKeySize.Key128Bit;
                }
                else if (this.keysize.SelectedIndex == 1)
                {
                    security.KeySize = PdfEncryptionKeySize.Key256Bit;
                }
                else if (this.keysize.SelectedIndex == 2)
                {
                    security.KeySize = PdfEncryptionKeySize.Key256BitRevision6;
                }
            }
            else if (this.Algorithms.Items[this.Algorithms.SelectedIndex] == "RC4")
            {
                security.Algorithm = PdfEncryptionAlgorithm.RC4;
                if (this.keysize.SelectedIndex == 0)
                {
                    security.KeySize = PdfEncryptionKeySize.Key40Bit;
                }
                else if (this.keysize.SelectedIndex == 1)
                {
                    security.KeySize = PdfEncryptionKeySize.Key128Bit;
                }
            }


            security.OwnerPassword = "******";
            security.Permissions   = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint;
            security.UserPassword  = "******";

            string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" +
                                                                  "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm);

            if (this.Algorithms.SelectedIndex == 1)
            {
                if (this.keysize.SelectedIndex == 2)
                {
                    text += String.Format("\n\nRevision: {0}", "Revision 6");
                }
                else if (this.keysize.SelectedIndex == 1)
                {
                    text += String.Format("\n\nRevision: {0}", "Revision 5");
                }
            }

            graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty);
            font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f, PdfFontStyle.Bold);
            graphics.DrawString(text, font, brush, new PointF(0, 40));

            MemoryStream stream = new MemoryStream();

            //Save the PDF document.
            document.Save(stream);

            if (Device.RuntimePlatform == Device.UWP)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("Secured.pdf", "application/pdf", stream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save("Secured.pdf", "application/pdf", stream);
            }
        }
コード例 #7
0
        public ActionResult Encryption(string InsideBrowser, string encryptionType)
        {
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.Pages.Add();
            PdfGraphics graphics = page.Graphics;

            PdfStandardFont font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Bold);
            PdfBrush        brush = PdfBrushes.Black;
            PdfForm         form  = document.Form;

            //Document security
            PdfSecurity security = document.Security;

            //Specify key size and encryption algorithm
            if (encryptionType == "40_RC4")
            {
                //use 40 bits key in RC4 mode
                security.KeySize = PdfEncryptionKeySize.Key40Bit;
            }
            else if (encryptionType == "128_RC4")
            {
                //use 128 bits key in RC4 mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.RC4;
            }
            else if (encryptionType == "128_AES")
            {
                //use 128 bits key in AES mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (encryptionType == "256_AES")
            {
                //use 256 bits key in AES mode
                security.KeySize   = PdfEncryptionKeySize.Key256Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (encryptionType == "256_AES_Revision_6")
            {
                security.KeySize   = PdfEncryptionKeySize.Key256BitRevision6;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }

            security.OwnerPassword = "******";
            security.Permissions   = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint;
            security.UserPassword  = "******";

            string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" +
                                                                  "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm);

            if (encryptionType == "256_AES_Revision_6")
            {
                text += String.Format("\n\nRevision: {0}", "Revision 6");
            }
            else if (encryptionType == "256_AES")
            {
                text += String.Format("\n\nRevision: {0}", "Revision 5");
            }
            graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty);
            font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f, PdfFontStyle.Bold);
            graphics.DrawString(text, font, brush, new PointF(0, 40));

            //Stream the output to the browser.
            if (InsideBrowser == "Browser")
            {
                return(document.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open));
            }
            else
            {
                return(document.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
        }
コード例 #8
0
        public ActionResult Encryption(string InsideBrowser, string encryptionType, string encryptOption)
        {
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.Pages.Add();
            PdfGraphics graphics = page.Graphics;

            PdfStandardFont font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Bold);
            PdfBrush        brush = PdfBrushes.Black;
            PdfForm         form  = document.Form;

            //Document security
            PdfSecurity security = document.Security;

            //Specify key size and encryption algorithm
            if (encryptionType == "40_RC4")
            {
                //use 40 bits key in RC4 mode
                security.KeySize = PdfEncryptionKeySize.Key40Bit;
            }
            else if (encryptionType == "128_RC4")
            {
                //use 128 bits key in RC4 mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.RC4;
            }
            else if (encryptionType == "128_AES")
            {
                //use 128 bits key in AES mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (encryptionType == "256_AES")
            {
                //use 256 bits key in AES mode
                security.KeySize   = PdfEncryptionKeySize.Key256Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (encryptionType == "256_AES_Revision_6")
            {
                security.KeySize   = PdfEncryptionKeySize.Key256BitRevision6;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            //set Encryption options
            if (encryptOption == "Encrypt only attachments [For AES only]")
            {
                string basePath = _hostingEnvironment.WebRootPath;
                string dataPath = basePath + @"/PDF/";

                //Read the file
                FileStream xmlStream = new FileStream(dataPath + "Products.xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                //Creates an attachment
                PdfAttachment attachment = new PdfAttachment("Products.xml", xmlStream);

                attachment.ModificationDate = DateTime.Now;

                attachment.Description = "About Syncfusion";

                attachment.MimeType = "application/txt";

                //Adds the attachment to the document
                document.Attachments.Add(attachment);

                security.EncryptionOptions = PdfEncryptionOptions.EncryptOnlyAttachments;
            }
            else if (encryptOption == "Encrypt all contents except metadata")
            {
                security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContentsExceptMetadata;
            }
            else
            {
                security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContents;
            }

            security.OwnerPassword = "******";
            security.Permissions   = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint;
            security.UserPassword  = "******";

            string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" +
                                                                  "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm);

            if (encryptionType == "256_AES_Revision_6")
            {
                text += String.Format("\n\nRevision: {0}", "Revision 6");
            }
            else if (encryptionType == "256_AES")
            {
                text += String.Format("\n\nRevision: {0}", "Revision 5");
            }
            graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty);
            font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f, PdfFontStyle.Bold);
            graphics.DrawString(text, font, brush, new PointF(0, 40));

            //Saving the PDF to the MemoryStream
            MemoryStream ms = new MemoryStream();

            document.Save(ms);
            //If the position is not set to '0' then the PDF will be empty.
            ms.Position = 0;

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");

            fileStreamResult.FileDownloadName = "Secure.pdf";
            return(fileStreamResult);
        }
コード例 #9
0
        public ActionResult Encryption(string InsideBrowser, string encryptionType, string encryptOptionType)
        {
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.Pages.Add();
            PdfGraphics graphics = page.Graphics;

            PdfStandardFont font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Bold);
            PdfBrush        brush = PdfBrushes.Black;
            PdfForm         form  = document.Form;

            //Document security
            PdfSecurity security = document.Security;

            //Specify key size and encryption algorithm
            if (encryptionType == "40_RC4")
            {
                //use 40 bits key in RC4 mode
                security.KeySize = PdfEncryptionKeySize.Key40Bit;
            }
            else if (encryptionType == "128_RC4")
            {
                //use 128 bits key in RC4 mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.RC4;
            }
            else if (encryptionType == "128_AES")
            {
                //use 128 bits key in AES mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (encryptionType == "256_AES")
            {
                //use 256 bits key in AES mode
                security.KeySize   = PdfEncryptionKeySize.Key256Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (encryptionType == "256_AES_Revision_6")
            {
                security.KeySize   = PdfEncryptionKeySize.Key256BitRevision6;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            //set Encryption options
            if (encryptOptionType == "Encrypt only attachments [For AES only]")
            {
                //Creates an attachment
                PdfAttachment attachment = new PdfAttachment(ResolveApplicationDataPath("Products.xml"));

                attachment.ModificationDate = DateTime.Now;

                attachment.Description = "About Syncfusion";

                attachment.MimeType = "application/txt";

                //Adds the attachment to the document
                document.Attachments.Add(attachment);

                security.EncryptionOptions = PdfEncryptionOptions.EncryptOnlyAttachments;
            }

            else if (encryptOptionType == "Encrypt all contents except metadata")
            {
                security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContentsExceptMetadata;
            }
            else
            {
                security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContents;
            }

            security.OwnerPassword = "******";
            security.Permissions   = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint;
            security.UserPassword  = "******";

            string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" +
                                                                  "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm);

            if (encryptionType == "256_AES_Revision_6")
            {
                text += String.Format("\n\nRevision: {0}", "Revision 6");
            }
            else if (encryptionType == "256_AES")
            {
                text += String.Format("\n\nRevision: {0}", "Revision 5");
            }
            graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty);
            font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f, PdfFontStyle.Bold);
            graphics.DrawString(text, font, brush, new PointF(0, 40));

            //Stream the output to the browser.
            if (InsideBrowser == "Browser")
            {
                return(document.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open));
            }
            else
            {
                return(document.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
        }
コード例 #10
0
        public ActionResult Encryption(string InsideBrowser, string encryptionType)
        {
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.Pages.Add();
            PdfGraphics graphics = page.Graphics;

            PdfStandardFont font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Bold);
            PdfBrush        brush = PdfBrushes.Black;
            PdfForm         form  = document.Form;

            //Document security
            PdfSecurity security = document.Security;

            //Specify key size and encryption algorithm
            if (encryptionType == "40_RC4")
            {
                //use 40 bits key in RC4 mode
                security.KeySize = PdfEncryptionKeySize.Key40Bit;
            }
            else if (encryptionType == "128_RC4")
            {
                //use 128 bits key in RC4 mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.RC4;
            }
            else if (encryptionType == "128_AES")
            {
                //use 128 bits key in AES mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (encryptionType == "256_AES")
            {
                //use 256 bits key in AES mode
                security.KeySize   = PdfEncryptionKeySize.Key256Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (encryptionType == "256_AES_Revision_6")
            {
                security.KeySize   = PdfEncryptionKeySize.Key256BitRevision6;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }

            security.OwnerPassword = "******";
            security.Permissions   = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint;
            security.UserPassword  = "******";

            string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" +
                                                                  "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm);

            if (encryptionType == "256_AES_Revision_6")
            {
                text += String.Format("\n\nRevision: {0}", "Revision 6");
            }
            else if (encryptionType == "256_AES")
            {
                text += String.Format("\n\nRevision: {0}", "Revision 5");
            }
            graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty);
            font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f, PdfFontStyle.Bold);
            graphics.DrawString(text, font, brush, new PointF(0, 40));

            //Saving the PDF to the MemoryStream
            MemoryStream ms = new MemoryStream();

            document.Save(ms);
            //If the position is not set to '0' then the PDF will be empty.
            ms.Position = 0;

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf");

            fileStreamResult.FileDownloadName = "Secure.pdf";
            return(fileStreamResult);
        }
コード例 #11
0
 public void DeletePdfForm(PdfForm PdfForm)
 {
     UnitOfWork.PdfFormRepository.Delete(PdfForm);
 }
コード例 #12
0
 public void UpdatePdfForm(PdfForm PdfForm)
 {
     UnitOfWork.PdfFormRepository.Update(PdfForm);
 }
コード例 #13
0
 public void InsertPdfForm(PdfForm PdfForm)
 {
     UnitOfWork.PdfFormRepository.Insert(PdfForm);
 }
コード例 #14
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        //protected override void OnNavigatedTo(NavigationEventArgs e)
        //{
        //}

        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            PdfDocument document = new PdfDocument();

            PdfPageBase page     = document.Pages.Add();
            PdfGraphics graphics = page.Graphics;

            PdfStandardFont font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold);
            PdfBrush        brush = PdfBrushes.Black;
            PdfForm         form  = document.Form;

            //Document security
            PdfSecurity security = document.Security;

            //Specify key size and encryption algorithm
            if (encryptionTechnique.SelectionBoxItem.ToString() == "40-Bit RC4")
            {
                //use 40 bits key in RC4 mode
                security.KeySize   = PdfEncryptionKeySize.Key40Bit;
                security.Algorithm = PdfEncryptionAlgorithm.RC4;
            }
            else if (encryptionTechnique.SelectionBoxItem.ToString() == "128-Bit RC4")
            {
                //use 128 bits key in RC4 mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.RC4;
            }
            else if (encryptionTechnique.SelectionBoxItem.ToString() == "128-Bit AES")
            {
                //use 128 bits key in RC4 mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (encryptionTechnique.SelectionBoxItem.ToString() == "256-Bit AES")
            {
                //use 256 bits key in AES mode
                security.KeySize   = PdfEncryptionKeySize.Key256Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (encryptionTechnique.SelectionBoxItem.ToString() == "256-Bit AES Revision 6")
            {
                //use 256 bits key in AES mode with Revision 6
                security.KeySize   = PdfEncryptionKeySize.Key256BitRevision6;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            security.OwnerPassword = txtOwnerPassword.Password;
            security.Permissions   = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint;
            security.UserPassword  = txtUserPassword.Password;

            string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" +
                                                                  "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm);

            if (encryptionTechnique.SelectionBoxItem.ToString() == "256-Bit AES Revision 6")
            {
                text += String.Format("\n\nRevision: {0}", "Revision6");
            }
            else if (encryptionTechnique.SelectionBoxItem.ToString() == "256-Bit AES")
            {
                text += String.Format("\n\nRevision: {0}", "Revision5");
            }

            graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty);
            font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16f, PdfFontStyle.Bold);
            graphics.DrawString(text, font, brush, new PointF(0, 40));

            MemoryStream stream = new MemoryStream();
            await document.SaveAsync(stream);

            document.Close(true);
            Save(stream, "FormFilling.pdf");
        }
コード例 #15
0
ファイル: Form1.cs プロジェクト: e-iceblue/Spire.PDF-for-.NET
        private float DrawFormField(XPathNavigator fieldNode, PdfForm form, PdfPageBase page, float y, int fieldIndex)
        {
            float width = page.Canvas.ClientSize.Width;
            float padding = 2;

            //measure field label
            String label = fieldNode.GetAttribute("label", "");
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 9f));
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            float labelMaxWidth = width * 0.4f - 2 * padding;
            SizeF labelSize = font1.MeasureString(label, labelMaxWidth, format);

            //measure field height
            float fieldHeight = MeasureFieldHeight(fieldNode);

            float height = labelSize.Height > fieldHeight ? labelSize.Height : fieldHeight;
            height = height + 2;

            //draw background
            PdfBrush brush = PdfBrushes.SteelBlue;
            if (fieldIndex % 2 == 1)
            {
                brush = PdfBrushes.LightGreen;
            }
            page.Canvas.DrawRectangle(brush, 0, y, width, height);

            //draw field label
            PdfBrush brush1 = PdfBrushes.LightYellow;
            RectangleF labelBounds = new RectangleF(padding, y, labelMaxWidth, height);
            page.Canvas.DrawString(label, font1, brush1, labelBounds, format);

            //daw field
            float fieldMaxWidth = width * 0.57f - 2 * padding;
            float fieldX = labelBounds.Right + 2 * padding;
            float fieldY = y + (height - fieldHeight) / 2;
            String fieldType = fieldNode.GetAttribute("type", "");
            String fieldId = fieldNode.GetAttribute("id", "");
            bool required = "true" == fieldNode.GetAttribute("required", "");
            switch (fieldType)
            {
                case "text":
                case "password":
                    PdfTextBoxField textField = new PdfTextBoxField(page, fieldId);
                    textField.Bounds = new RectangleF(fieldX, fieldY, fieldMaxWidth, fieldHeight);
                    textField.BorderWidth = 0.75f;
                    textField.BorderStyle = PdfBorderStyle.Solid;
                    textField.Required = required;
                    if ("password" == fieldType)
                    {
                        textField.Password = true;
                    }
                    if ("true" == fieldNode.GetAttribute("multiple", ""))
                    {
                        textField.Multiline = true;
                        textField.Scrollable = true;
                    }
                    form.Fields.Add(textField);
                    break;
                case "checkbox":
                    PdfCheckBoxField checkboxField = new PdfCheckBoxField(page, fieldId);
                    float checkboxWidth = fieldHeight - 2 * padding;
                    float checkboxHeight = checkboxWidth;
                    checkboxField.Bounds = new RectangleF(fieldX, fieldY + padding, checkboxWidth, checkboxHeight);
                    checkboxField.BorderWidth = 0.75f;
                    checkboxField.Style = PdfCheckBoxStyle.Cross;
                    checkboxField.Required = required;
                    form.Fields.Add(checkboxField);
                    break;

                case "list":
                    XPathNodeIterator itemNodes = fieldNode.Select("item");
                    if ("true" == fieldNode.GetAttribute("multiple", ""))
                    {
                        PdfListBoxField listBoxField = new PdfListBoxField(page, fieldId);
                        listBoxField.Bounds = new RectangleF(fieldX, fieldY, fieldMaxWidth, fieldHeight);
                        listBoxField.BorderWidth = 0.75f;
                        listBoxField.MultiSelect = true;
                        listBoxField.Font = new PdfFont(PdfFontFamily.Helvetica, 9f);
                        listBoxField.Required = required;
                        //add items into list box.
                        foreach (XPathNavigator itemNode in itemNodes)
                        {
                            String text = itemNode.SelectSingleNode("text()").Value;
                            listBoxField.Items.Add(new PdfListFieldItem(text, text));
                        }
                        listBoxField.SelectedIndex = 0;
                        form.Fields.Add(listBoxField);

                        break;
                    }
                    if (itemNodes != null && itemNodes.Count <= 3)
                    {
                        PdfRadioButtonListField radioButtonListFile
                            = new PdfRadioButtonListField(page, fieldId);
                        radioButtonListFile.Required = required;
                        //add items into radio button list.
                        float fieldItemHeight = fieldHeight / itemNodes.Count;
                        float radioButtonWidth = fieldItemHeight - 2 * padding;
                        float radioButtonHeight = radioButtonWidth;
                        foreach (XPathNavigator itemNode in itemNodes)
                        {
                            String text = itemNode.SelectSingleNode("text()").Value;
                            PdfRadioButtonListItem fieldItem = new PdfRadioButtonListItem(text);
                            fieldItem.BorderWidth = 0.75f;
                            fieldItem.Bounds = new RectangleF(fieldX, fieldY + padding, radioButtonWidth, radioButtonHeight);
                            radioButtonListFile.Items.Add(fieldItem);

                            float fieldItemLabelX = fieldX + radioButtonWidth + padding;
                            SizeF fieldItemLabelSize = font1.MeasureString(text);
                            float fieldItemLabelY = fieldY + (fieldItemHeight - fieldItemLabelSize.Height) / 2;
                            page.Canvas.DrawString(text, font1, brush1, fieldItemLabelX, fieldItemLabelY);

                            fieldY = fieldY + fieldItemHeight;
                        }
                        form.Fields.Add(radioButtonListFile);

                        break;
                    }

                    //combo box
                    PdfComboBoxField comboBoxField = new PdfComboBoxField(page, fieldId);
                    comboBoxField.Bounds = new RectangleF(fieldX, fieldY, fieldMaxWidth, fieldHeight);
                    comboBoxField.BorderWidth = 0.75f;
                    comboBoxField.Font = new PdfFont(PdfFontFamily.Helvetica, 9f);
                    comboBoxField.Required = required;
                    //add items into combo box.
                    foreach (XPathNavigator itemNode in itemNodes)
                    {
                        String text = itemNode.SelectSingleNode("text()").Value;
                        comboBoxField.Items.Add(new PdfListFieldItem(text, text));
                    }
                    form.Fields.Add(comboBoxField);
                    break;

            }

            if (required)
            {
                //draw *
                float flagX = width * 0.97f + padding;
                PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
                SizeF size = font3.MeasureString("*");
                float flagY = y + (height - size.Height) / 2;
                page.Canvas.DrawString("*", font3, PdfBrushes.Red, flagX, flagY);
            }

            return y + height;
        }
コード例 #16
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.Pages.Add();
            PdfGraphics graphics = page.Graphics;

            PdfStandardFont font  = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold);
            PdfBrush        brush = PdfBrushes.Black;
            PdfForm         form  = document.Form;

            //Document security
            PdfSecurity security = document.Security;

            //Specify key size and encryption algorithm
            if (rdButton40Bit.Checked)
            {
                //use 40 bits key in RC4 mode
                security.KeySize = PdfEncryptionKeySize.Key40Bit;
            }
            else if (rdButton128Bit.Checked && rdButtonRC4.Checked)
            {
                //use 128 bits key in RC4 mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.RC4;
            }
            else if (rdButton128Bit.Checked && rdButtonAES.Checked)
            {
                //use 128 bits key in AES mode
                security.KeySize   = PdfEncryptionKeySize.Key128Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (rdButton256Bit.Checked)
            {
                //use 256 bits key in AES mode
                security.KeySize   = PdfEncryptionKeySize.Key256Bit;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            else if (rdButton256BitRevision6.Checked)
            {
                security.KeySize   = PdfEncryptionKeySize.Key256BitRevision6;
                security.Algorithm = PdfEncryptionAlgorithm.AES;
            }
            security.OwnerPassword = "******";
            security.Permissions   = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint;
            security.UserPassword  = "******";

            string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" +
                                                                  "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm);

            if (rdButton256BitRevision6.Checked)
            {
                text += String.Format("\n\nRevision: {0}", "Revision6");
            }
            else if (rdButton256Bit.Checked)
            {
                text += String.Format("\n\nRevision: {0}", "Revision5");
            }

            graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty);
            font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16f, PdfFontStyle.Bold);
            graphics.DrawString(text, font, brush, new PointF(0, 40));

            document.Save("Sample.pdf");

            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
                System.Diagnostics.Process.Start("Sample.pdf");
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
        }