Skip to content

Commit

Permalink
allow any whitespace between obj parts
Browse files Browse the repository at this point in the history
  • Loading branch information
rkusa committed Apr 28, 2020
1 parent 0a0caf0 commit 04c1cab
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- allow any whitespace between obj version and rev numbers when parsing PDF (fixes parsing of some PDF)

## [2.3.5] - 2020-03-03
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion lib/object/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PDFName {
return undefined
}

throw new Error('Invalid name')
throw new Error('Name must start with a leading slash, found: ' + lexer.getString(1))
}

lexer.shift(1)
Expand Down
4 changes: 2 additions & 2 deletions lib/object/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class PDFObject {
if (id === undefined && !trial) {
throw new Error('Invalid object')
}
lexer.skipSpace(1, trial)
lexer.skipWhitespace(1, trial)
const generation = lexer.readNumber(trial)
if (generation === undefined && !trial) {
throw new Error('Invalid object')
}

lexer.skipSpace(1, trial)
lexer.skipWhitespace(1, trial)
if (lexer.getString(3) !== 'obj') {
if (trial) {
lexer.pos = before
Expand Down
4 changes: 2 additions & 2 deletions lib/object/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class PDFReference {
throw new Error('Invalid indirect')
}

lexer.skipSpace(1, trial)
lexer.skipWhitespace(1, trial)
const generation = lexer.readNumber(trial)
if (generation === undefined && !trial) {
throw new Error('Invalid indirect')
}

lexer.skipSpace(1, trial)
lexer.skipWhitespace(1, trial)
if (lexer.getString(1) !== 'R') {
if (trial) {
lexer.pos = before
Expand Down
Binary file added test/pdfs/parser/fixtures/google.pdf
Binary file not shown.
11 changes: 11 additions & 0 deletions test/pdfs/parser/google.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const pdf = require('../../../')
const path = require('path')
const fs = require('fs')

module.exports = function(doc) {
const img = new pdf.Image(fs.readFileSync(path.join(__dirname, '/fixtures/google.pdf')))

doc.image(img, {
wrap: false, x: 0, y: 841.89, width: 595.28
})
}
Binary file added test/pdfs/parser/google.pdf
Binary file not shown.

0 comments on commit 04c1cab

Please sign in to comment.