コード例 #1
0
        ////////////////////////////////////////////////////////////////////
        // Constructor for objects with /Type in their dictionary
        // Note: access is internal. Used by derived classes only
        ////////////////////////////////////////////////////////////////////

        internal PdfObject
        (
            PdfDocument Document,
            ObjectType ObjType = ObjectType.Dictionary,
            string PdfDictType = null                       // object type (i.e. /Catalog, /Pages, /Font, /XObject, /OCG)
        )
        {
            // save link to main document object
            this.Document = Document;

            // save type
            ObjectType = ObjType;

            // save scale factor
            ScaleFactor = Document.ScaleFactor;

            // no compression
            NoCompression = Document.Debug;

            // switch based on object type
            switch (ObjectType)
            {
            case ObjectType.Free:
                XRefType = XRefObjType.Free;
                break;

            case ObjectType.Other:
                XRefType        = XRefObjType.ObjStm;
                ObjectValueList = new List <byte>();
                break;

            case ObjectType.Dictionary:
                XRefType   = XRefObjType.ObjStm;
                Dictionary = new PdfDictionary(this);
                break;

            case ObjectType.Stream:
                XRefType        = XRefObjType.InFile;
                Dictionary      = new PdfDictionary(this);
                ObjectValueList = new List <byte>();
                break;
            }

            // if object name is specified, create a dictionary and add /Type Name entry
            if (!string.IsNullOrEmpty(PdfDictType))
            {
                Dictionary.Add("/Type", PdfDictType);
            }

            // set PDF indirect object number to next available number
            ObjectNumber = Document.ObjectArray.Count;

            // add the new object to object array
            Document.ObjectArray.Add(this);
            return;
        }
コード例 #2
0
        ////////////////////////////////////////////////////////////////////
        // Write root object to PDF file
        ////////////////////////////////////////////////////////////////////
        internal void WriteRootToPdfFile()
        {
            // convert root object from ObjStm to InFile
            XRefType = XRefObjType.InFile;

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

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

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

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