示例#1
0
        /// <summary>
        /// Instanciates a new Free Object refernce.
        /// </summary>
        /// <param name="objectId">The <see cref="PdfObjectId"/> to use for the next use of this object number.</param>
        /// <param name="nextFreeObjectNumber">The object number of the next free object.</param>
        public PdfFreeObjectReference(PdfObjectId objectId, int nextFreeObjectNumber) : base(objectId)
        {
            if (nextFreeObjectNumber < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(nextFreeObjectNumber), "Cannot be negative.");
            }

            this.nextFreeObjectNumber = nextFreeObjectNumber;
        }
示例#2
0
 /// <summary>
 /// Instanciates a new PdfObjectReference
 /// Reference is marked in use by default
 /// </summary>
 /// <param name="objectId">The referenced object's <see cref="PdfObjectId"/>.</param>
 /// <param name="position">The position of the object</param>
 public PdfObjectReference(PdfObjectId objectId, long position) : base(objectId)
 {
     this.position = position;
 }
示例#3
0
        /// <summary>
        /// Reads a section and append entries.
        /// </summary>
        /// <param name="reader">The <see cref="PdfReader"/> to use.</param>
        public static XRefSection FromReader(PdfReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            reader.ReadToken(StartKeyword);
            reader.MoveToNonWhiteSpace();

            var    entries = new Dictionary <int, PdfObjectReferenceBase>();
            string subsectionHeader;
            var    entryBuffer = new char[20];

            while (char.IsDigit(reader.Peek()))
            {
                int separatorIdx, firstId, count;

                try
                {
                    subsectionHeader = reader.ReadLine();
                    separatorIdx     = subsectionHeader.IndexOf(' ');
                    firstId          = Int32.Parse(subsectionHeader.Substring(0, separatorIdx));
                    count            = Int32.Parse(subsectionHeader.Substring(separatorIdx + 1));
                }
                catch
                {
                    throw new FormatException("Invalid Cross-Reference Table subsection header.");
                }

                for (int i = firstId; i < firstId + count; i++)
                {
                    // Each entry is exactly 20 bytes long, including the end-of - line marker.
                    reader.Read(entryBuffer, 0, entryBuffer.Length);

                    PdfObjectReferenceBase objectReference;

                    var objectId = new PdfObjectId(i, ushort.Parse(new string(entryBuffer, 11, 5)));
                    switch (entryBuffer[17])
                    {
                    case 'n':
                        objectReference = new PdfObjectReference(objectId, long.Parse(new string(entryBuffer, 0, 10)));
                        break;

                    case 'f':
                        objectReference = new PdfFreeObjectReference(objectId, int.Parse(new string(entryBuffer, 0, 10)));
                        break;

                    default:
                        throw new FormatException("Invalid Cross-Reference entry");
                    }

                    entries.Add(
                        i,
                        objectReference
                        );
                }
            }

            return(new XRefSection(entries, true));
        }