Esempio n. 1
0
        /**
         * Returns the PDF representation of this <CODE>PdfArray</CODE>.
         *
         * @return		an array of <CODE>byte</CODE>s
         */

        public override byte[] toPdf(PdfWriter writer)
        {
            try {
                MemoryStream stream = new MemoryStream();
                byte[]       tmp    = DocWriter.getISOBytes("[");
                stream.Write(tmp, 0, tmp.Length);

                if (dash >= 0)
                {
                    tmp = new PdfNumber(dash).toPdf(null);
                    stream.Write(tmp, 0, tmp.Length);
                    if (gap >= 0)
                    {
                        tmp = DocWriter.getISOBytes(" ");
                        stream.Write(tmp, 0, tmp.Length);
                        tmp = new PdfNumber(gap).toPdf(null);
                        stream.Write(tmp, 0, tmp.Length);
                    }
                }
                tmp = DocWriter.getISOBytes("]");
                stream.Write(tmp, 0, tmp.Length);
                if (phase >= 0)
                {
                    tmp = DocWriter.getISOBytes(" ");
                    stream.Write(tmp, 0, tmp.Length);
                    tmp = new PdfNumber(phase).toPdf(null);
                    stream.Write(tmp, 0, tmp.Length);
                }

                return(stream.ToArray());
            }
            catch (IOException ioe) {
                throw ioe;
            }
        }
Esempio n. 2
0
 /**
  * Appends a <CODE>string</CODE> to the buffer. The <CODE>string</CODE> is
  * converted according to the encoding ISO-8859-1.
  * @param str the <CODE>string</CODE> to be appended
  * @return a reference to this <CODE>ByteBuffer</CODE> object
  */
 public ByteBuffer Append(string str)
 {
     if (str != null)
     {
         return(Append(DocWriter.getISOBytes(str)));
     }
     return(this);
 }
        /**
         * Constructs a <CODE>PdfIndirectObject</CODE>.
         *
         * @param		number			the object number
         * @param		generation		the generation number
         * @param		object			the direct object
         */

        internal PdfIndirectObject(int number, int generation, PdfObject obj, PdfWriter writer)
        {
            this.writer     = writer;
            this.number     = number;
            this.generation = generation;
            type            = obj.Type;
            isStream        = (obj.Type == PdfObject.STREAM);
            PdfEncryption crypto = writer.Encryption;

            if (crypto != null)
            {
                crypto.setHashKey(number, generation);
            }
            try {
                bytes = new MemoryStream();
                byte[] tmp = DocWriter.getISOBytes(number.ToString());
                bytes.Write(tmp, 0, tmp.Length);
                bytes.WriteByte((byte)32);
                tmp = DocWriter.getISOBytes(generation.ToString());
                bytes.Write(tmp, 0, tmp.Length);
                if (!isStream)
                {
                    bytes.Write(STARTOBJ, 0, STARTOBJ.Length);
                    tmp = obj.toPdf(writer);
                    bytes.Write(tmp, 0, tmp.Length);
                    bytes.Write(ENDOBJ, 0, ENDOBJ.Length);
                }
                else
                {
                    stream = (PdfStream)obj;
                }
            }
            catch (IOException ioe) {
                throw ioe;
            }
        }
Esempio n. 4
0
        // constructor

        /**
         * Constructs a <CODE>PdfContents</CODE>-object, containing text and general graphics.
         *
         * @param under the direct content that is under all others
         * @param content the graphics in a page
         * @param text the text in a page
         * @param secondContent the direct content that is over all others
         * @throws BadPdfFormatException on error
         */

        internal PdfContents(PdfContentByte under, PdfContentByte content, PdfContentByte text, PdfContentByte secondContent, Rectangle page) : base()
        {
            try {
                Stream ostr = null;
                streamBytes = new MemoryStream();
                if (Document.compress)
                {
                    compressed = true;
                    ostr       = new DeflaterOutputStream(streamBytes);
                }
                else
                {
                    ostr = streamBytes;
                }
                int    rotation = page.Rotation;
                byte[] tmp;
                switch (rotation)
                {
                case 90:
                    ostr.Write(ROTATE90, 0, ROTATE90.Length);
                    tmp = DocWriter.getISOBytes(ByteBuffer.formatDouble(page.Top));
                    ostr.Write(tmp, 0, tmp.Length);
                    ostr.WriteByte(System.Convert.ToByte(' '));
                    ostr.WriteByte(System.Convert.ToByte('0'));
                    ostr.Write(ROTATEFINAL, 0, ROTATEFINAL.Length);
                    break;

                case 180:
                    ostr.Write(ROTATE180, 0, ROTATE180.Length);
                    tmp = DocWriter.getISOBytes(ByteBuffer.formatDouble(page.Right));
                    ostr.Write(tmp, 0, tmp.Length);
                    ostr.WriteByte(System.Convert.ToByte(' '));
                    tmp = DocWriter.getISOBytes(ByteBuffer.formatDouble(page.Top));
                    ostr.Write(tmp, 0, tmp.Length);
                    ostr.Write(ROTATEFINAL, 0, ROTATEFINAL.Length);
                    break;

                case 270:
                    ostr.Write(ROTATE270, 0, ROTATE270.Length);
                    ostr.WriteByte(System.Convert.ToByte('0'));
                    ostr.WriteByte(System.Convert.ToByte(' '));
                    tmp = DocWriter.getISOBytes(ByteBuffer.formatDouble(page.Right));
                    ostr.Write(tmp, 0, tmp.Length);
                    ostr.Write(ROTATEFINAL, 0, ROTATEFINAL.Length);
                    break;
                }
                if (under.Size > 0)
                {
                    ostr.Write(SAVESTATE, 0, SAVESTATE.Length);
                    under.InternalBuffer.WriteTo(ostr);
                    ostr.Write(RESTORESTATE, 0, RESTORESTATE.Length);
                }
                if (content.Size > 0)
                {
                    ostr.Write(SAVESTATE, 0, SAVESTATE.Length);
                    content.InternalBuffer.WriteTo(ostr);
                    ostr.Write(RESTORESTATE, 0, RESTORESTATE.Length);
                }
                if (text != null)
                {
                    ostr.Write(SAVESTATE, 0, SAVESTATE.Length);
                    text.InternalBuffer.WriteTo(ostr);
                    ostr.Write(RESTORESTATE, 0, RESTORESTATE.Length);
                }
                if (secondContent.Size > 0)
                {
                    secondContent.InternalBuffer.WriteTo(ostr);
                }

                if (ostr is DeflaterOutputStream)
                {
                    ((DeflaterOutputStream)ostr).Finish();
                }
            }
            catch (Exception e) {
                throw new BadPdfFormatException(e.Message);
            }
            put(PdfName.LENGTH, new PdfNumber(streamBytes.Length));
            if (compressed)
            {
                put(PdfName.FILTER, PdfName.FLATEDECODE);
            }
        }