コード例 #1
0
ファイル: PdfReader.cs プロジェクト: Kwesoft/Pdf
        public PdfCrossReferenceTable ReadCrossReferenceTable(PdfTrailer trailer)
        {
            var pos                = trailer.CrossReferenceTableOffset;
            var length             = trailer.Index - pos;
            var crossReferenceData = _document.Encoding.GetString(_document.Read(pos, length - 1)).Split(new[] { PdfKeywords.LineBreak }, StringSplitOptions.RemoveEmptyEntries);

            var crossReferenceTableSummary = crossReferenceData[1].Split(new[] { PdfKeywords.Space }, StringSplitOptions.RemoveEmptyEntries);
            var firstObjectNumber          = int.Parse(crossReferenceTableSummary[0]);
            var objectCount = int.Parse(crossReferenceTableSummary[1]);

            var result = new PdfCrossReferenceTable
            {
                ObjectOffsets     = new Dictionary <int, int>(),
                Offset            = pos,
                Length            = length,
                FirstObjectNumber = firstObjectNumber,
                ObjectCount       = objectCount,
                Document          = _document
            };

            for (var i = 2; i < crossReferenceData.Length; i++)
            {
                result.ObjectOffsets.Add(firstObjectNumber + i - 2, int.Parse(crossReferenceData[i].Split(new[] { PdfKeywords.Space }, StringSplitOptions.RemoveEmptyEntries)[0]));
            }

            return(result);
        }
コード例 #2
0
ファイル: PdfReader.cs プロジェクト: Kwesoft/Pdf
        public PdfTrailer ReadTrailer()
        {
            var eofPos = _document.FindReverse(_document.Keywords.EOFLine);

            var startxrefPos  = _document.FindReverse(_document.Keywords.StartXRefLine, eofPos);
            var startxrefData = _document.Encoding.GetString(_document.Read(startxrefPos + 11, eofPos - (startxrefPos + 11)));

            var trailerPos = _document.FindReverse(_document.Keywords.TrailerLine, startxrefPos) + 1;
            var result     = new PdfTrailer
            {
                Offset = trailerPos,
                Length = eofPos - trailerPos,
                CrossReferenceTableOffset = int.Parse(startxrefData),
                Document = _document
            };

            result.TrailerDictionary = _ReadDictionary(trailerPos + 8, result);
            return(result);
        }