public virtual void MakeIndirectDirectOnlyPdfBoolean()
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new ByteArrayOutputStream()));
            PdfBoolean  t      = PdfBoolean.ValueOf(true);

            t.MakeIndirect(pdfDoc);
        }
Esempio n. 2
0
 /// <summary>
 /// Create a new PdfArray filled with the values in the boolean[] as
 /// <see cref="PdfBoolean"/>.
 /// </summary>
 /// <param name="values">values to be added to this PdfArray</param>
 public PdfArray(bool[] values)
 {
     list = new List <PdfObject>(values.Length);
     foreach (bool b in values)
     {
         list.Add(PdfBoolean.ValueOf(b));
     }
 }
Esempio n. 3
0
        public virtual void EqualBoolean()
        {
            PdfBoolean f = (PdfBoolean) new PdfBoolean(false).MakeIndirect(new PdfDocument(new PdfWriter(new ByteArrayOutputStream
                                                                                                             ())));
            PdfBoolean t = new PdfBoolean(true);

            NUnit.Framework.Assert.IsFalse(f.Equals(t));
            NUnit.Framework.Assert.IsTrue(f.Equals(PdfBoolean.FALSE));
            NUnit.Framework.Assert.IsTrue(t.Equals(PdfBoolean.TRUE));
        }
Esempio n. 4
0
        /// <summary>Returns the value associated to this key as a Boolean.</summary>
        /// <remarks>Returns the value associated to this key as a Boolean. If the value isn't a PdfBoolean, null is returned.
        ///     </remarks>
        /// <param name="key">the key of which the associated value needs to be returned</param>
        /// <returns>Boolean associated with this key</returns>
        public virtual bool?GetAsBool(PdfName key)
        {
            PdfBoolean b            = GetAsBoolean(key);
            bool?      booleanValue = null;

            if (b != null)
            {
                booleanValue = b.GetValue();
            }
            return(booleanValue);
        }
Esempio n. 5
0
 /// <summary>This method sets HideWindowUI flag to true or false</summary>
 /// <param name="hideWindowUI"/>
 public virtual iText.Kernel.Pdf.PdfViewerPreferences SetHideWindowUI(bool hideWindowUI)
 {
     return(Put(PdfName.HideWindowUI, PdfBoolean.ValueOf(hideWindowUI)));
 }
Esempio n. 6
0
 /// <summary>This method sets HideMenuBar flag to true or false</summary>
 /// <param name="hideMenubar"/>
 public virtual iText.Kernel.Pdf.PdfViewerPreferences SetHideMenubar(bool hideMenubar)
 {
     return(Put(PdfName.HideMenubar, PdfBoolean.ValueOf(hideMenubar)));
 }
Esempio n. 7
0
 /// <summary>This method sets PickTrayByPDFSize flag to true or false.</summary>
 /// <param name="pickTrayByPdfSize"/>
 public virtual iText.Kernel.Pdf.PdfViewerPreferences SetPickTrayByPDFSize(bool pickTrayByPdfSize)
 {
     return(Put(PdfName.PickTrayByPDFSize, PdfBoolean.ValueOf(pickTrayByPdfSize)));
 }
Esempio n. 8
0
 /// <summary>This method sets DisplayDocTitle flag to true or false</summary>
 /// <param name="displayDocTitle"/>
 public virtual iText.Kernel.Pdf.PdfViewerPreferences SetDisplayDocTitle(bool displayDocTitle)
 {
     return(Put(PdfName.DisplayDocTitle, PdfBoolean.ValueOf(displayDocTitle)));
 }
Esempio n. 9
0
 /// <summary>This method sets CenterWindow flag to true or false</summary>
 /// <param name="centerWindow"/>
 public virtual iText.Kernel.Pdf.PdfViewerPreferences SetCenterWindow(bool centerWindow)
 {
     return(Put(PdfName.CenterWindow, PdfBoolean.ValueOf(centerWindow)));
 }
Esempio n. 10
0
 /// <summary>This method sets FitWindow flag to true or false</summary>
 /// <param name="fitWindow"/>
 public virtual iText.Kernel.Pdf.PdfViewerPreferences SetFitWindow(bool fitWindow)
 {
     return(Put(PdfName.FitWindow, PdfBoolean.ValueOf(fitWindow)));
 }
Esempio n. 11
0
        private int ReadAndSetCryptoModeForPubSecHandler(PdfDictionary encDict)
        {
            int       cryptoMode;
            int       length = 0;
            PdfNumber vValue = encDict.GetAsNumber(PdfName.V);

            if (vValue == null)
            {
                throw new PdfException(PdfException.IllegalVValue);
            }
            int v = vValue.IntValue();

            switch (v)
            {
            case 1: {
                cryptoMode = EncryptionConstants.STANDARD_ENCRYPTION_40;
                length     = 40;
                break;
            }

            case 2: {
                PdfNumber lengthValue = encDict.GetAsNumber(PdfName.Length);
                if (lengthValue == null)
                {
                    throw new PdfException(PdfException.IllegalLengthValue);
                }
                length = lengthValue.IntValue();
                if (length > 128 || length < 40 || length % 8 != 0)
                {
                    throw new PdfException(PdfException.IllegalLengthValue);
                }
                cryptoMode = EncryptionConstants.STANDARD_ENCRYPTION_128;
                break;
            }

            case 4:
            case 5: {
                PdfDictionary dic = encDict.GetAsDictionary(PdfName.CF);
                if (dic == null)
                {
                    throw new PdfException(PdfException.CfNotFoundEncryption);
                }
                dic = (PdfDictionary)dic.Get(PdfName.DefaultCryptFilter);
                if (dic == null)
                {
                    throw new PdfException(PdfException.DefaultcryptfilterNotFoundEncryption);
                }
                if (PdfName.V2.Equals(dic.Get(PdfName.CFM)))
                {
                    cryptoMode = EncryptionConstants.STANDARD_ENCRYPTION_128;
                    length     = 128;
                }
                else
                {
                    if (PdfName.AESV2.Equals(dic.Get(PdfName.CFM)))
                    {
                        cryptoMode = EncryptionConstants.ENCRYPTION_AES_128;
                        length     = 128;
                    }
                    else
                    {
                        if (PdfName.AESV3.Equals(dic.Get(PdfName.CFM)))
                        {
                            cryptoMode = EncryptionConstants.ENCRYPTION_AES_256;
                            length     = 256;
                        }
                        else
                        {
                            throw new PdfException(PdfException.NoCompatibleEncryptionFound);
                        }
                    }
                }
                PdfBoolean em = dic.GetAsBoolean(PdfName.EncryptMetadata);
                if (em != null && !em.GetValue())
                {
                    cryptoMode |= EncryptionConstants.DO_NOT_ENCRYPT_METADATA;
                }
                break;
            }

            default: {
                throw new PdfException(PdfException.UnknownEncryptionTypeVEq1, vValue);
            }
            }
            return(SetCryptoMode(cryptoMode, length));
        }
Esempio n. 12
0
        private int ReadAndSetCryptoModeForStdHandler(PdfDictionary encDict)
        {
            int       cryptoMode;
            int       length = 0;
            PdfNumber rValue = encDict.GetAsNumber(PdfName.R);

            if (rValue == null)
            {
                throw new PdfException(PdfException.IllegalRValue);
            }
            int revision = rValue.IntValue();

            switch (revision)
            {
            case 2: {
                cryptoMode = EncryptionConstants.STANDARD_ENCRYPTION_40;
                break;
            }

            case 3: {
                PdfNumber lengthValue = encDict.GetAsNumber(PdfName.Length);
                if (lengthValue == null)
                {
                    throw new PdfException(PdfException.IllegalLengthValue);
                }
                length = lengthValue.IntValue();
                if (length > 128 || length < 40 || length % 8 != 0)
                {
                    throw new PdfException(PdfException.IllegalLengthValue);
                }
                cryptoMode = EncryptionConstants.STANDARD_ENCRYPTION_128;
                break;
            }

            case 4: {
                PdfDictionary dic = (PdfDictionary)encDict.Get(PdfName.CF);
                if (dic == null)
                {
                    throw new PdfException(PdfException.CfNotFoundEncryption);
                }
                dic = (PdfDictionary)dic.Get(PdfName.StdCF);
                if (dic == null)
                {
                    throw new PdfException(PdfException.StdcfNotFoundEncryption);
                }
                if (PdfName.V2.Equals(dic.Get(PdfName.CFM)))
                {
                    cryptoMode = EncryptionConstants.STANDARD_ENCRYPTION_128;
                }
                else
                {
                    if (PdfName.AESV2.Equals(dic.Get(PdfName.CFM)))
                    {
                        cryptoMode = EncryptionConstants.ENCRYPTION_AES_128;
                    }
                    else
                    {
                        throw new PdfException(PdfException.NoCompatibleEncryptionFound);
                    }
                }
                PdfBoolean em = encDict.GetAsBoolean(PdfName.EncryptMetadata);
                if (em != null && !em.GetValue())
                {
                    cryptoMode |= EncryptionConstants.DO_NOT_ENCRYPT_METADATA;
                }
                break;
            }

            case 5:
            case 6: {
                cryptoMode = EncryptionConstants.ENCRYPTION_AES_256;
                PdfBoolean em5 = encDict.GetAsBoolean(PdfName.EncryptMetadata);
                if (em5 != null && !em5.GetValue())
                {
                    cryptoMode |= EncryptionConstants.DO_NOT_ENCRYPT_METADATA;
                }
                break;
            }

            default: {
                throw new PdfException(PdfException.UnknownEncryptionTypeREq1).SetMessageParams(rValue);
            }
            }
            revision = SetCryptoMode(cryptoMode, length);
            return(revision);
        }
 /// <summary>This method sets HideToolBar flag to true or false</summary>
 /// <param name="hideToolbar">HideToolBar flag's boolean value</param>
 /// <returns>
 /// current instance of
 /// <see cref="PdfViewerPreferences"/>
 /// </returns>
 public virtual PdfViewerPreferences SetHideToolbar(bool hideToolbar)
 {
     return(Put(PdfName.HideToolbar, PdfBoolean.ValueOf(hideToolbar)));
 }