Beispiel #1
0
        /// <summary>Flushes the object.</summary>
        /// <remarks>Flushes the object. Override this method if you want to define custom behaviour for object flushing.
        ///     </remarks>
        /// <param name="pdfObject">object to flush.</param>
        /// <param name="canBeInObjStm">indicates whether object can be placed into object stream.</param>
        /// <exception cref="System.IO.IOException">on error.</exception>
        protected internal virtual void FlushObject(PdfObject pdfObject, bool canBeInObjStm)
        {
            PdfIndirectReference indirectReference = pdfObject.GetIndirectReference();

            if (IsFullCompression() && canBeInObjStm)
            {
                PdfObjectStream objectStream = GetObjectStream();
                objectStream.AddObject(pdfObject);
            }
            else
            {
                indirectReference.SetOffset(GetCurrentPos());
                WriteToBody(pdfObject);
            }
            ((PdfIndirectReference)indirectReference.SetState(PdfObject.FLUSHED)).ClearState(PdfObject.MUST_BE_FLUSHED
                                                                                             );
            switch (pdfObject.GetObjectType())
            {
            case PdfObject.BOOLEAN:
            case PdfObject.NAME:
            case PdfObject.NULL:
            case PdfObject.NUMBER:
            case PdfObject.STRING: {
                ((PdfPrimitiveObject)pdfObject).content = null;
                break;
            }

            case PdfObject.ARRAY: {
                PdfArray array = ((PdfArray)pdfObject);
                MarkArrayContentToFlush(array);
                array.ReleaseContent();
                break;
            }

            case PdfObject.STREAM:
            case PdfObject.DICTIONARY: {
                PdfDictionary dictionary = ((PdfDictionary)pdfObject);
                MarkDictionaryContentToFlush(dictionary);
                dictionary.ReleaseContent();
                break;
            }

            case PdfObject.INDIRECT_REFERENCE: {
                MarkObjectToFlush(((PdfIndirectReference)pdfObject).GetRefersTo(false));
                break;
            }
            }
        }