Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 41 additions & 21 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,19 +851,19 @@ func (this *PdfReader) readXref() error {
// Check for /DecodeParms
paethDecode := false
if _, ok := v.Dictionary["/DecodeParms"]; ok {
columns := 0
predictor := 0

if _, ok2 := v.Dictionary["/DecodeParms"].Dictionary["/Columns"]; ok2 {
columns = v.Dictionary["/DecodeParms"].Dictionary["/Columns"].Int
}
if _, ok2 := v.Dictionary["/DecodeParms"].Dictionary["/Predictor"]; ok2 {
predictor = v.Dictionary["/DecodeParms"].Dictionary["/Predictor"].Int
}

if columns > 4 || predictor > 12 {
return errors.New("Unsupported /DecodeParms - only tested with /Columns <= 4 and /Predictor <= 12")
}
// columns := 0
// predictor := 0

// if _, ok2 := v.Dictionary["/DecodeParms"].Dictionary["/Columns"]; ok2 {
// columns = v.Dictionary["/DecodeParms"].Dictionary["/Columns"].Int
// }
// if _, ok2 := v.Dictionary["/DecodeParms"].Dictionary["/Predictor"]; ok2 {
// predictor = v.Dictionary["/DecodeParms"].Dictionary["/Predictor"].Int
// }

// if columns > 4 || predictor > 12 {
// return errors.New("Unsupported /DecodeParms - only tested with /Columns <= 4 and /Predictor <= 12")
// }
paethDecode = true
}

Expand Down Expand Up @@ -999,6 +999,7 @@ func (this *PdfReader) readXref() error {
lastFieldSize := v.Dictionary["/W"].Array[2].Int

fieldSize := firstFieldSize + middleFieldSize + lastFieldSize
column := fieldSize
if paethDecode {
fieldSize++
}
Expand All @@ -1020,36 +1021,55 @@ func (this *PdfReader) readXref() error {
copy(prevRow, result)
}

objectData := make([]byte, fieldSize)
objectData := make([]byte, column)
if paethDecode {
copy(objectData, result[1:fieldSize])
} else {
copy(objectData, result[0:fieldSize])
}

if objectData[0] == 1 {
switch objectData[0] {
case 1:
// Regular objects
b := make([]byte, 4)
copy(b[4-middleFieldSize:], objectData[1:1+middleFieldSize])
b2 := make([]byte, 4)
copy(b[4-middleFieldSize:], objectData[firstFieldSize:firstFieldSize+middleFieldSize])
copy(b2[4-lastFieldSize:], objectData[column-lastFieldSize:])

objPos = int(binary.BigEndian.Uint32(b))
objGen = int(objectData[firstFieldSize+middleFieldSize])

objGen = int(binary.BigEndian.Uint32(b2))
// Append map[int]int
this.xref[i] = make(map[int]int, 1)

// Set object id, generation, and position
this.xref[i][objGen] = objPos
} else if objectData[0] == 2 {
case 2:
// Compressed objects
b := make([]byte, 4)
copy(b[4-middleFieldSize:], objectData[1:1+middleFieldSize])
b2 := make([]byte, 4)
copy(b[4-middleFieldSize:], objectData[firstFieldSize:firstFieldSize+middleFieldSize])
copy(b2[4-lastFieldSize:], objectData[column-lastFieldSize:])

objId := int(binary.BigEndian.Uint32(b))
objIdx := int(objectData[firstFieldSize+middleFieldSize])
objIdx := int(binary.BigEndian.Uint32(b2))

// object id (i) is located in StmObj (objId) at index (objIdx)
this.xrefStream[i] = [2]int{objId, objIdx}
case 0:
//
b := make([]byte, 4)
b2 := make([]byte, 4)
copy(b[4-middleFieldSize:], objectData[firstFieldSize:firstFieldSize+middleFieldSize])
copy(b2[4-lastFieldSize:], objectData[column-lastFieldSize:])

objPos = int(binary.BigEndian.Uint32(b))
objGen = int(binary.BigEndian.Uint32(b2))

// Append map[int]int
this.xref[i] = make(map[int]int, 1)

// Set object id, generation, and position
this.xref[i][objGen] = objPos
}

i++
Expand Down