iTextSharp.text.pdf.PdfWriter.SetEncryption C# (CSharp) Méthode

SetEncryption() public méthode

public SetEncryption ( X509Certificate certs, int permissions, int encryptionType ) : void
certs Org.BouncyCastle.X509.X509Certificate
permissions int
encryptionType int
Résultat void
        public void SetEncryption(X509Certificate[] certs, int[] permissions, int encryptionType)
        {
            if (pdf.IsOpen())
                throw new DocumentException(MessageLocalization.GetComposedMessage("encryption.can.only.be.added.before.opening.the.document"));
            crypto = new PdfEncryption();
            if (certs != null) {
                for (int i=0; i < certs.Length; i++) {
                    crypto.AddRecipient(certs[i], permissions[i]);
                }
            }
            crypto.SetCryptoMode(encryptionType, 0);
            crypto.GetEncryptionDictionary();
        }

Same methods

PdfWriter::SetEncryption ( bool strength, String userPassword, String ownerPassword, int permissions ) : void
PdfWriter::SetEncryption ( byte userPassword, byte ownerPassword, int permissions, bool strength128Bits ) : void
PdfWriter::SetEncryption ( byte userPassword, byte ownerPassword, int permissions, int encryptionType ) : void
PdfWriter::SetEncryption ( int encryptionType, String userPassword, String ownerPassword, int permissions ) : void

Usage Example

Exemple #1
0
        /// <summary>
        /// Create a new PDF text document.
        /// </summary>
        /// <param name="pdf">The PDF file stream.</param>
        /// <param name="text">The text to add to the document.</param>
        /// <param name="font">The text font to create.</param>
        /// <param name="password">The password used to protect the document.</param>
        /// <exception cref="System.Exception"></exception>
        public void CreateText(Stream pdf, string text, Nequeo.Drawing.Pdf.Font font, string password)
        {
            iTextSharp.text.Document document = null;

            try
            {
                // Create the document.
                document = new iTextSharp.text.Document();
                iTextSharp.text.pdf.PdfWriter pdfWriter = iTextSharp.text.pdf.PdfAWriter.GetInstance(document, pdf);
                pdfWriter.SetEncryption(iTextSharp.text.pdf.PdfWriter.ENCRYPTION_AES_256, password, password, 0);
                document.Open();

                // Add the text.
                iTextSharp.text.Font fontText = font.GetFont();
                document.Add(new iTextSharp.text.Paragraph(text, fontText));

                // Close the document.
                document.Close();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (document != null)
                {
                    document.Dispose();
                }
            }
        }
All Usage Examples Of iTextSharp.text.pdf.PdfWriter::SetEncryption