Skip to content

fix: incorrect use of interface pointer #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/phpdave11/gofpdi
module github.com/pzeinlinger/gofpdi

go 1.12

Expand Down
4 changes: 2 additions & 2 deletions importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ func (this *Importer) SetSourceFile(f string) {
}
}

func (this *Importer) SetSourceStream(rs *io.ReadSeeker) {
func (this *Importer) SetSourceStream(rs io.ReadSeeker) {
this.sourceFile = fmt.Sprintf("%v", rs)

if _, ok := this.readers[this.sourceFile]; !ok {
reader, err := NewPdfReaderFromStream(*rs)
reader, err := NewPdfReaderFromStream(this.sourceFile, rs)
if err != nil {
panic(err)
}
Expand Down
24 changes: 16 additions & 8 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"compress/zlib"
"encoding/binary"
"fmt"
"github.com/pkg/errors"
"io"
"io/ioutil"
"math"
"os"
"strconv"

"github.com/pkg/errors"
)

type PdfReader struct {
Expand All @@ -31,12 +32,12 @@ type PdfReader struct {
pageCount int
}

func NewPdfReaderFromStream(rs io.ReadSeeker) (*PdfReader, error) {
func NewPdfReaderFromStream(sourceFile string, rs io.ReadSeeker) (*PdfReader, error) {
length, err := rs.Seek(0, 2)
if err != nil {
return nil, errors.Wrapf(err, "Failed to determine stream length")
}
parser := &PdfReader{f: rs, nBytes: length}
parser := &PdfReader{f: rs, sourceFile: sourceFile, nBytes: length}
if err := parser.init(); err != nil {
return nil, errors.Wrap(err, "Failed to initialize parser")
}
Expand Down Expand Up @@ -1137,11 +1138,18 @@ func (this *PdfReader) readXref() error {
return errors.New("Expected objStatus to be 'n' or 'f', got: " + objStatus)
}

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

// Set object id, generation, and position
this.xref[i][objGen] = objPos
// Since the XREF table is read from newest to oldest, make sure an xref entry does not already exist for an object.
// If it already exists, that means a newer version of the object has already been added to the table.
// Replacing it would be using the old version of the object.
// https://github.com/phpdave11/gofpdi/issues/71
_, ok := this.xref[i]
if !ok {
// Append map[int]int
this.xref[i] = make(map[int]int, 1)

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

Expand Down