Exemplo n.º 1
0
 internal override void writeTo(Stream ostr, PdfWriter writer)
 {
     if (dicBytes == null)
     {
         toPdf(writer);
     }
     ostr.Write(dicBytes, 0, dicBytes.Length);
     ostr.Write(STARTSTREAM, 0, STARTSTREAM.Length);
     if (length > 0)
     {
         PdfEncryption crypto = writer.Encryption;
         if (offset < 0)
         {
             if (crypto == null)
             {
                 ostr.Write(bytes, 0, bytes.Length);
             }
             else
             {
                 crypto.prepareKey();
                 byte[] buf = new byte[length];
                 Array.Copy(bytes, 0, buf, 0, length);
                 crypto.encryptRC4(buf);
                 ostr.Write(buf, 0, buf.Length);
             }
         }
         else
         {
             byte[] buf = new byte[Math.Min(length, 4092)];
             RandomAccessFileOrArray file = writer.getReaderFile(reader);
             file.seek(offset);
             int size = length;
             if (crypto != null)
             {
                 crypto.prepareKey();
             }
             while (size > 0)
             {
                 int r = file.read(buf, 0, Math.Min(size, buf.Length));
                 size -= r;
                 if (crypto != null)
                 {
                     crypto.encryptRC4(buf, 0, r);
                 }
                 ostr.Write(buf, 0, r);
             }
         }
     }
     ostr.Write(ENDSTREAM, 0, ENDSTREAM.Length);
 }
Exemplo n.º 2
0
        // methods overriding some methods in PdfObject

        /**
         * Returns the PDF representation of this <CODE>PdfString</CODE>.
         *
         * @return		an array of <CODE>byte</CODE>s
         */

        public override byte[] toPdf(PdfWriter writer)
        {
            byte[] b;
            b = PdfEncodings.convertToBytes(value, encoding);
            PdfEncryption crypto = writer.Encryption;

            if (crypto != null)
            {
                crypto.prepareKey();
                crypto.encryptRC4(b);
            }
            return(PdfContentByte.escapestring(b));
        }
Exemplo n.º 3
0
        internal virtual void writeTo(Stream outstr, PdfWriter writer)
        {
            if (dicBytes == null)
            {
                toPdf(writer);
            }
            outstr.Write(dicBytes, 0, dicBytes.Length);
            outstr.Write(STARTSTREAM, 0, STARTSTREAM.Length);
            PdfEncryption crypto = writer.Encryption;

            if (crypto == null)
            {
                if (streamBytes != null)
                {
                    streamBytes.WriteTo(outstr);
                }
                else
                {
                    outstr.Write(bytes, 0, bytes.Length);
                }
            }
            else
            {
                crypto.prepareKey();
                byte[] b;
                if (streamBytes != null)
                {
                    b = streamBytes.ToArray();
                    crypto.encryptRC4(b);
                }
                else
                {
                    b = new byte[bytes.Length];
                    crypto.encryptRC4(bytes, b);
                }
                outstr.Write(b, 0, b.Length);
            }
            outstr.Write(ENDSTREAM, 0, ENDSTREAM.Length);
        }