mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-29 13:48:54 +08:00
Merge pull request #91 from adrg/xref-table-invalid-line
Attempt to parse invalid beginning lines of xref table subsections.
This commit is contained in:
commit
2daa144856
@ -768,6 +768,7 @@ func (parser *PdfParser) parseXrefTable() (*PdfObjectDictionary, error) {
|
|||||||
curObjNum := -1
|
curObjNum := -1
|
||||||
secObjects := 0
|
secObjects := 0
|
||||||
insideSubsection := false
|
insideSubsection := false
|
||||||
|
unmatchedContent := ""
|
||||||
for {
|
for {
|
||||||
parser.skipSpaces()
|
parser.skipSpaces()
|
||||||
_, err := parser.reader.Peek(1)
|
_, err := parser.reader.Peek(1)
|
||||||
@ -781,6 +782,16 @@ func (parser *PdfParser) parseXrefTable() (*PdfObjectDictionary, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result1 := reXrefSubsection.FindStringSubmatch(txt)
|
result1 := reXrefSubsection.FindStringSubmatch(txt)
|
||||||
|
if len(result1) == 0 {
|
||||||
|
// Try to match invalid subsection beginning lines from previously
|
||||||
|
// read, unidentified lines. Covers cases in which the object number
|
||||||
|
// and the number of entries in the subsection are not on the same line.
|
||||||
|
tryMatch := len(unmatchedContent) > 0
|
||||||
|
unmatchedContent += txt + "\n"
|
||||||
|
if tryMatch {
|
||||||
|
result1 = reXrefSubsection.FindStringSubmatch(unmatchedContent)
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(result1) == 3 {
|
if len(result1) == 3 {
|
||||||
// Match
|
// Match
|
||||||
first, _ := strconv.Atoi(result1[1])
|
first, _ := strconv.Atoi(result1[1])
|
||||||
@ -788,6 +799,7 @@ func (parser *PdfParser) parseXrefTable() (*PdfObjectDictionary, error) {
|
|||||||
curObjNum = first
|
curObjNum = first
|
||||||
secObjects = second
|
secObjects = second
|
||||||
insideSubsection = true
|
insideSubsection = true
|
||||||
|
unmatchedContent = ""
|
||||||
common.Log.Trace("xref subsection: first object: %d objects: %d", curObjNum, secObjects)
|
common.Log.Trace("xref subsection: first object: %d objects: %d", curObjNum, secObjects)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -801,6 +813,7 @@ func (parser *PdfParser) parseXrefTable() (*PdfObjectDictionary, error) {
|
|||||||
first, _ := strconv.ParseInt(result2[1], 10, 64)
|
first, _ := strconv.ParseInt(result2[1], 10, 64)
|
||||||
gen, _ := strconv.Atoi(result2[2])
|
gen, _ := strconv.Atoi(result2[2])
|
||||||
third := result2[3]
|
third := result2[3]
|
||||||
|
unmatchedContent = ""
|
||||||
|
|
||||||
if strings.ToLower(third) == "n" && first > 1 {
|
if strings.ToLower(third) == "n" && first > 1 {
|
||||||
// Object in use in the file! Load it.
|
// Object in use in the file! Load it.
|
||||||
@ -829,6 +842,7 @@ func (parser *PdfParser) parseXrefTable() (*PdfObjectDictionary, error) {
|
|||||||
curObjNum++
|
curObjNum++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len(txt) > 6) && (txt[:7] == "trailer") {
|
if (len(txt) > 6) && (txt[:7] == "trailer") {
|
||||||
common.Log.Trace("Found trailer - %s", txt)
|
common.Log.Trace("Found trailer - %s", txt)
|
||||||
// Sometimes get "trailer << ...."
|
// Sometimes get "trailer << ...."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user