protected internal PdfDictionary ReadXrefSection() {
tokens.NextValidToken();
if (!tokens.StringValue.Equals("xref"))
tokens.ThrowError("xref subsection not found");
int start = 0;
int end = 0;
int pos = 0;
int gen = 0;
while (true) {
tokens.NextValidToken();
if (tokens.StringValue.Equals("trailer"))
break;
if (tokens.TokenType != PRTokeniser.TK_NUMBER)
tokens.ThrowError("Object number of the first object in this xref subsection not found");
start = tokens.IntValue;
tokens.NextValidToken();
if (tokens.TokenType != PRTokeniser.TK_NUMBER)
tokens.ThrowError("Number of entries in this xref subsection not found");
end = tokens.IntValue + start;
if (start == 1) { // fix incorrect start number
int back = tokens.FilePointer;
tokens.NextValidToken();
pos = tokens.IntValue;
tokens.NextValidToken();
gen = tokens.IntValue;
if (pos == 0 && gen == PdfWriter.GENERATION_MAX) {
--start;
--end;
}
tokens.Seek(back);
}
EnsureXrefSize(end * 2);
for (int k = start; k < end; ++k) {
tokens.NextValidToken();
pos = tokens.IntValue;
tokens.NextValidToken();
gen = tokens.IntValue;
tokens.NextValidToken();
int p = k * 2;
if (tokens.StringValue.Equals("n")) {
if (xref[p] == 0 && xref[p + 1] == 0) {
// if (pos == 0)
// tokens.ThrowError("File position 0 cross-reference entry in this xref subsection");
xref[p] = pos;
}
}
else if (tokens.StringValue.Equals("f")) {
if (xref[p] == 0 && xref[p + 1] == 0)
xref[p] = -1;
}
else
tokens.ThrowError("Invalid cross-reference entry in this xref subsection");
}
}
PdfDictionary trailer = (PdfDictionary)ReadPRObject();
PdfNumber xrefSize = (PdfNumber)trailer.Get(PdfName.SIZE);
EnsureXrefSize(xrefSize.IntValue * 2);
PdfObject xrs = trailer.Get(PdfName.XREFSTM);
if (xrs != null && xrs.IsNumber()) {
int loc = ((PdfNumber)xrs).IntValue;
try {
ReadXRefStream(loc);
newXrefType = true;
hybridXref = true;
}
catch (IOException e) {
xref = null;
throw e;
}
}
return trailer;
}