Skip to content
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ A simple Go library which enables reading PDF files. Forked from https://github.
Features
- Get plain text content (without format)
- Get Content (including all font and formatting information)
## DEBUG

```go
// string(b.r.Reader.r.buf) corresponds to the PDF content.
// b.r.Reader.r.w correspond to the PDF content length and can be searched directly
// string(b.r.Reader.decompressor.dict.hist) is the decompressed PDF stream
// b.tmp and tok is the keyword
//(*b).pos +1 is the current read position

// strm.ptr.id is the object id example:xx 0 obj
```

## Install:

Expand Down
18 changes: 17 additions & 1 deletion lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
// string, a PDF string literal
// keyword, a PDF keyword
// name, a PDF name without the leading slash
//
type token interface{}

// A name is a PDF name, without the leading slash.
Expand Down Expand Up @@ -125,6 +124,7 @@ func (b *buffer) unreadToken(t token) {
}

func (b *buffer) readToken() token {

if n := len(b.unread); n > 0 {
t := b.unread[n-1]
b.unread = b.unread[:n-1]
Expand Down Expand Up @@ -419,6 +419,10 @@ func (b *buffer) readObject() object {
return b.readDict()
case "[":
return b.readArray()
case ">>":
return nil
case "]":
return nil
}
b.errorf("unexpected keyword %q parsing object", kw)
return nil
Expand Down Expand Up @@ -467,6 +471,12 @@ func (b *buffer) readArray() object {
if tok == nil || tok == keyword("]") {
break
}

// Check EOF
if err, ok := tok.(error); ok && err == io.EOF {
break
}

b.unreadToken(tok)
x = append(x, b.readObject())
}
Expand All @@ -480,6 +490,12 @@ func (b *buffer) readDict() object {
if tok == nil || tok == keyword(">>") {
break
}

// Check EOF
if err, ok := tok.(error); ok && err == io.EOF {
break
}

n, ok := tok.(name)
if !ok {
b.errorf("unexpected non-name key %T(%v) parsing dictionary", tok, tok)
Expand Down
Loading