Exemple #1
0
        public override void ToPdf(PdfWriter writer, Stream os)
        {
            byte[]        b      = PdfReader.GetStreamBytesRaw(this);
            PdfEncryption crypto = null;

            if (writer != null)
            {
                crypto = writer.Encryption;
            }
            PdfObject objLen = Get(PdfName.LENGTH);
            int       nn     = b.Length;

            if (crypto != null)
            {
                nn = crypto.CalculateStreamSize(nn);
            }
            Put(PdfName.LENGTH, new PdfNumber(nn));
            SuperToPdf(writer, os);
            Put(PdfName.LENGTH, objLen);
            os.Write(STARTSTREAM, 0, STARTSTREAM.Length);
            if (length > 0)
            {
                if (crypto != null && !crypto.IsEmbeddedFilesOnly())
                {
                    b = crypto.EncryptByteArray(b);
                }
                os.Write(b, 0, b.Length);
            }
            os.Write(ENDSTREAM, 0, ENDSTREAM.Length);
        }
Exemple #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 void ToPdf(PdfWriter writer, Stream os)
        {
            byte[]        b      = GetBytes();
            PdfEncryption crypto = null;

            if (writer != null)
            {
                crypto = writer.Encryption;
            }
            if (crypto != null && !crypto.IsEmbeddedFilesOnly())
            {
                b = crypto.EncryptByteArray(b);
            }
            if (hexWriting)
            {
                ByteBuffer buf = new ByteBuffer();
                buf.Append('<');
                int len = b.Length;
                for (int k = 0; k < len; ++k)
                {
                    buf.AppendHex(b[k]);
                }
                buf.Append('>');
                os.Write(buf.ToByteArray(), 0, buf.Size);
            }
            else
            {
                b = PdfContentByte.EscapeString(b);
                os.Write(b, 0, b.Length);
            }
        }
Exemple #3
0
        public override void ToPdf(PdfWriter writer, Stream os)
        {
            if (inputStream != null && compressed)
            {
                Put(PdfName.FILTER, PdfName.FLATEDECODE);
            }
            PdfEncryption crypto = null;

            if (writer != null)
            {
                crypto = writer.Encryption;
            }
            if (crypto != null)
            {
                PdfObject filter = Get(PdfName.FILTER);
                if (filter != null)
                {
                    if (PdfName.CRYPT.Equals(filter))
                    {
                        crypto = null;
                    }
                    else if (filter.IsArray())
                    {
                        PdfArray a = ((PdfArray)filter);
                        if (a.Size > 0 && PdfName.CRYPT.Equals(a[0]))
                        {
                            crypto = null;
                        }
                    }
                }
            }
            PdfObject nn = Get(PdfName.LENGTH);

            if (crypto != null && nn != null && nn.IsNumber())
            {
                int sz = ((PdfNumber)nn).IntValue;
                Put(PdfName.LENGTH, new PdfNumber(crypto.CalculateStreamSize(sz)));
                SuperToPdf(writer, os);
                Put(PdfName.LENGTH, nn);
            }
            else
            {
                SuperToPdf(writer, os);
            }
            os.Write(STARTSTREAM, 0, STARTSTREAM.Length);
            if (inputStream != null)
            {
                rawLength = 0;
                ZDeflaterOutputStream  def = null;
                OutputStreamCounter    osc = new OutputStreamCounter(os);
                OutputStreamEncryption ose = null;
                Stream fout = osc;
                if (crypto != null && !crypto.IsEmbeddedFilesOnly())
                {
                    fout = ose = crypto.GetEncryptionStream(fout);
                }
                if (compressed)
                {
                    fout = def = new ZDeflaterOutputStream(fout, compressionLevel);
                }

                byte[] buf = new byte[4192];
                while (true)
                {
                    int n = inputStream.Read(buf, 0, buf.Length);
                    if (n <= 0)
                    {
                        break;
                    }
                    fout.Write(buf, 0, n);
                    rawLength += n;
                }
                if (def != null)
                {
                    def.Finish();
                }
                if (ose != null)
                {
                    ose.Finish();
                }
                inputStreamLength = osc.Counter;
            }
            else
            {
                if (crypto != null && !crypto.IsEmbeddedFilesOnly())
                {
                    byte[] b;
                    if (streamBytes != null)
                    {
                        b = crypto.EncryptByteArray(streamBytes.ToArray());
                    }
                    else
                    {
                        b = crypto.EncryptByteArray(bytes);
                    }
                    os.Write(b, 0, b.Length);
                }
                else
                {
                    if (streamBytes != null)
                    {
                        streamBytes.WriteTo(os);
                    }
                    else
                    {
                        os.Write(bytes, 0, bytes.Length);
                    }
                }
            }
            os.Write(ENDSTREAM, 0, ENDSTREAM.Length);
        }