/// <summary> /// Writes the specified value to the PDF stream. /// </summary> public void Write(PdfInteger value) { WriteSeparator(CharCat.Character); this.lastCat = CharCat.Character; WriteRaw(value.Value.ToString(CultureInfo.InvariantCulture)); }
/// <summary> /// Sets the entry to a direct integer value. /// </summary> public void SetInteger(string key, int value) { this[key] = new PdfInteger(value); }
/// <summary> /// Prepares the security handler for encrypting the document. /// </summary> public void PrepareEncryption() { #if !SILVERLIGHT Debug.Assert(this.document.securitySettings.DocumentSecurityLevel != PdfDocumentSecurityLevel.None); int permissions = (int)this.Permission; bool strongEncryption = this.document.securitySettings.DocumentSecurityLevel == PdfDocumentSecurityLevel.Encrypted128Bit; PdfInteger vValue; PdfInteger length; PdfInteger rValue; if (strongEncryption) { vValue = new PdfInteger(2); length = new PdfInteger(128); rValue = new PdfInteger(3); } else { vValue = new PdfInteger(1); length = new PdfInteger(40); rValue = new PdfInteger(2); } if (String.IsNullOrEmpty(this.userPassword)) this.userPassword = ""; // Use user password twice if no owner password provided. if (String.IsNullOrEmpty(this.ownerPassword)) this.ownerPassword = this.userPassword; // Correct permission bits permissions |= (int)(strongEncryption ? (uint)0xfffff0c0 : (uint)0xffffffc0); permissions &= unchecked((int)0xfffffffc); PdfInteger pValue = new PdfInteger(permissions); Debug.Assert(this.ownerPassword.Length > 0, "Empty owner password."); byte[] userPad = PadPassword(this.userPassword); byte[] ownerPad = PadPassword(this.ownerPassword); this.md5.Initialize(); this.ownerKey = ComputeOwnerKey(userPad, ownerPad, strongEncryption); byte[] documentID = PdfEncoders.RawEncoding.GetBytes(this.document.Internals.FirstDocumentID); InitWidhUserPassword(documentID, this.userPassword, this.ownerKey, permissions, strongEncryption); PdfString oValue = new PdfString(PdfEncoders.RawEncoding.GetString(this.ownerKey)); PdfString uValue = new PdfString(PdfEncoders.RawEncoding.GetString(this.userKey)); Elements[Keys.Filter] = new PdfName("/Standard"); Elements[Keys.V] = vValue; Elements[Keys.Length] = length; Elements[Keys.R] = rValue; Elements[Keys.O] = oValue; Elements[Keys.U] = uValue; Elements[Keys.P] = pValue; #endif }
/// <summary> /// Converts the specified value to integer. /// If the value not exists, the function returns 0. /// If the value is not convertible, the function throws an InvalidCastException. /// </summary> public int GetInteger(string key, bool create) { object obj = this[key]; if (obj == null) { if (create) this[key] = new PdfInteger(); return 0; } if (obj is PdfReference) obj = ((PdfReference)obj).Value; if (obj is PdfInteger) return ((PdfInteger)obj).Value; if (obj is PdfIntegerObject) return ((PdfIntegerObject)obj).Value; throw new InvalidCastException("GetInteger: Object is not an integer."); }
/// <summary> /// Writes the specified value to the PDF stream. /// </summary> public void Write(PdfInteger value) { WriteSeparator(CharCat.Character); this.lastCat = CharCat.Character; WriteRaw(value.Value.ToString()); }