/// <summary>
        /// Overrides the base implementation to write strings that are encrypted if they are not a part of an object stream
        /// </summary>
        /// <param name="value"></param>
        /// <param name="encoding"></param>
        public override void WriteStringLiteral(string value, Scryber.FontEncoding encoding)
        {
            PDFObjectEncryptionStream encrypting = this.AssertEncrypterStream;

            if (encrypting.InsideStream == false)
            {
                //If we are not in an object stream, then we want to encrypt the text
                if (encrypting.HasEncrypter == false)
                {
                    encrypting.Encrypter = this.CreateEncryptionFilter(encrypting.ObjectRef);
                }
                byte[] all = GetStringBytes(value, encoding);
                all = encrypting.Encrypter.FilterStream(all);
                this.WriteStringHex(all);
            }
            else
            {
                //We are in an object stream so don't do any encryption now - wait until we close the indirect object
                base.WriteStringLiteral(value, encoding);
            }
        }
Exemple #2
0
 public override void WriteStringLiteral(string value, Scryber.FontEncoding encoding)
 {
     if (UseHex && encoding != FontEncoding.PDFDocEncoding)
     {
         //TODO Write encoding prefix
         CurrentStream.Write(Constants.StartHexString);
         value = ToHex(value, encoding);
         CurrentStream.Write(value);
         CurrentStream.Write(Constants.EndHexString);
     }
     else
     {
         Scryber.Text.PDFEncoding enc = Scryber.Text.PDFEncoding.GetEncoding(encoding);
         CurrentStream.Write(Constants.StartString);
         if (null != enc.Prefix && enc.Prefix.Length > 0)
         {
             CurrentStream.Write(enc.Prefix);
         }
         CurrentStream.Write(enc.GetBytes(value));
         CurrentStream.Write(Constants.EndString);
     }
 }
        //
        // support methods
        //

        #region private byte[] GetStringBytes(string value, Scryber.FontEncoding encoding)

        /// <summary>
        /// Converts a string in the specified encoding into a byte[]
        /// </summary>
        /// <param name="value"></param>
        /// <param name="encoding"></param>
        /// <returns></returns>
        private byte[] GetStringBytes(string value, Scryber.FontEncoding encoding)
        {
            Scryber.Text.PDFEncoding enc = Scryber.Text.PDFEncoding.GetEncoding(encoding);
            byte[] all = enc.GetBytes(value);
            return(all);
        }