コード例 #1
0
        ////////////////////////////////////////////////////////////////////
        // Write stream object to PDF file
        // Called by PdfDocument.CreateFile(FileName) method
        // to output one indirect stream PDF object.
        ////////////////////////////////////////////////////////////////////
        internal void WriteToPdfFile()
        {
            // already done or not in file object
            if (FilePosition != 0 || XRefType != XRefObjType.InFile)
            {
                return;
            }

            // save file position for this object
            FilePosition = Document.PdfFile.BaseStream.Position;

            // write object header
            Document.PdfFile.WriteFormat("{0} 0 obj\n", ObjectNumber);

            // stream object
            if (ObjectType == ObjectType.Stream)
            {
                // convert byte list to array
                if (ObjectValueList.Count > 0)
                {
                    ObjectValueArray = ObjectValueList.ToArray();
                }

                // object value is empty
                if (ObjectValueArray == null)
                {
                    ObjectValueArray = new byte[0];
                }

                // compress the stream and update dictionary if successful
                if (!NoCompression && PdfDocument.CompressStream(ref ObjectValueArray))
                {
                    Dictionary.Add("/Filter", "/FlateDecode");
                }

                // encryption
                if (Document.Encryption != null)
                {
                    ObjectValueArray = Document.Encryption.EncryptByteArray(ObjectNumber, ObjectValueArray);
                }

                // stream length
                Dictionary.AddInteger("/Length", ObjectValueArray.Length);

                // write dictionary
                Document.PdfFile.Write(Dictionary.ToByteArray());

                // write stream reserved word
                Document.PdfFile.WriteString("stream\n");

                // write content to pdf file
                Document.PdfFile.Write(ObjectValueArray);

                // write end of stream
                Document.PdfFile.WriteString("\nendstream\nendobj\n");
            }

            else
            {
                // write dictionary
                Document.PdfFile.Write(Dictionary.ToByteArray());

                // write end of object
                Document.PdfFile.WriteString("\nendobj\n");
            }

            // this indirect object was written to output file
            // tell the garbage collector that these objects are not used any more
            Dictionary       = null;
            ObjectValueList  = null;
            ObjectValueArray = null;
            return;
        }