示例#1
0
        /// <summary>
        /// Write PDF document object summary to byte array
        /// </summary>
        /// <returns>Text string</returns>
        public static string PdfFileSummary
        (
            PdfReader Reader
        )
        {
            OutputCtrl Ctrl = new OutputCtrl();

            Ctrl.AppendMessage(string.Format("PDF file name: {0}", Reader.SafeFileName));
            Ctrl.AddEol();
            Ctrl.AppendMessage("Trailer Dictionary");
            Ctrl.AppendMessage("------------------");
            Reader.TrailerDict.ToByteArray(Ctrl);
            Ctrl.AddEol();

            Ctrl.AddEol();
            Ctrl.AppendMessage("Indirect Objects");
            Ctrl.AppendMessage("----------------");

            // output one object at a time
            foreach (PdfIndirectObject Obj in Reader.ObjectArray)
            {
                if (Obj != null)
                {
                    Obj.ObjectSummary(Ctrl);
                }
            }

            // successful exit
            return(ByteArrayToString(Ctrl.ToArray()));
        }
        ////////////////////////////////////////////////////////////////////
        // Write indirect object to object analysis file
        ////////////////////////////////////////////////////////////////////
        internal void  ObjectSummary
        (
            OutputCtrl Ctrl
        )
        {
            // write object header
            Ctrl.AppendMessage(string.Format("Object number: {0}", ObjectNumber));
            Ctrl.AppendMessage(string.Format("Object Value Type: {0}", ObjectDescription()));
            Ctrl.AppendMessage(string.Format("File Position: {0} Hex: {0:X}", FilePosition));
            if (ParentObjectNo != 0)
            {
                Ctrl.AppendMessage(string.Format("Parent object number: {0}", ParentObjectNo));
                Ctrl.AppendMessage(string.Format("Parent object index: {0}", ParentObjectIndex));
            }
            if (ObjectType == ObjectType.Stream)
            {
                Ctrl.AppendMessage(string.Format("Stream Position: {0} Hex: {0:X}", StreamFilePosition));
                Ctrl.AppendMessage(string.Format("Stream Length: {0} Hex: {0:X}", StreamLength));
            }

            // dictionary or stream
            if (ObjectType == ObjectType.Dictionary || ObjectType == ObjectType.Stream)
            {
                string ObjectTypeStr = Dictionary.FindValue("/Type").ToName;
                if (ObjectTypeStr == null)
                {
                    ObjectTypeStr = PdfObjectType;
                }
                if (ObjectTypeStr != null)
                {
                    Ctrl.AppendMessage(string.Format("Object Type: {0}", ObjectTypeStr));
                }

                string ObjectSubtypeStr = Dictionary.FindValue("/Subtype").ToName;
                if (ObjectSubtypeStr != null)
                {
                    Ctrl.AppendMessage(string.Format("Object Subtype: {0}", ObjectSubtypeStr));
                }

                // write to pdf file
                Dictionary.ToByteArray(Ctrl);

                // final terminator
                Ctrl.AddEol();
            }

            // object has contents that is not stream
            else if (ObjectType == ObjectType.Other)
            {
                // write content to pdf file
                Value.ToByteArray(Ctrl);

                // final terminator
                Ctrl.AddEol();
            }

            // final terminator
            Ctrl.AddEol();

            // return string
            return;
        }