Comparing version 2.1.0 to 2.2.0
@@ -7,4 +7,14 @@ # Changelog | ||
## [Unreleased] | ||
## [2.2.0] - 2019-04-02 | ||
### Fixed | ||
- Pages from external documents should always be added with their original size #111 | ||
- Fix parsing documents with nested /Pages objects #117 | ||
- Fix parsing multi-line PDF strings #117 | ||
### Changed | ||
- `opentype.js` has been updated to `0.11.0`, which has a minor effect on kerning distances | ||
### Added | ||
- `end` option for `doc.asBuffer` #118 | ||
## [2.1.0] - 2018-09-22 | ||
@@ -11,0 +21,0 @@ ### Changed |
@@ -558,3 +558,3 @@ 'use strict' | ||
} | ||
catalog.prop('Outlines', this._outlines[0].toReference()) | ||
catalog.prop('Outlines', this._outlines[0].toReference()) | ||
} | ||
@@ -581,3 +581,9 @@ await this._writeObject(catalog) | ||
asBuffer(callback) { | ||
asBuffer(opts, callback) { | ||
if (typeof opts === 'function') { | ||
callback = opts | ||
opts = undefined | ||
} | ||
const shouldEnd = !opts || opts.end !== false | ||
let p = new Promise((resolve, reject) => { | ||
@@ -588,3 +594,5 @@ const chunks = [] | ||
this.on('error', reject) | ||
this.end() | ||
if (shouldEnd) { | ||
this.end() | ||
} | ||
}) | ||
@@ -658,3 +666,3 @@ if (typeof callback === 'function') { | ||
if (title === undefined || destination === undefined) return | ||
// Create the root outline the first time this method is called | ||
@@ -670,3 +678,3 @@ if (this._outlines.length === 0 ){ | ||
// the user provided a valid index number: use it as the parentIndex | ||
parentIndex = parent | ||
parentIndex = parent | ||
} else { | ||
@@ -690,3 +698,3 @@ // the user did not provide a valid index number: search for it in the outline array | ||
}, []) | ||
// Create item | ||
@@ -714,3 +722,3 @@ const outline = new PDF.Object() | ||
} | ||
// Chain to parents | ||
@@ -717,0 +725,0 @@ this._outlines[outlineIndex].data.parentIndex = parentIndex |
@@ -15,14 +15,20 @@ 'use strict' | ||
this.pages = pages | ||
this.mediaBox = pages.get('MediaBox') | ||
const kids = pages.get('Kids') | ||
this.pageCount = kids.length | ||
this.pageCount = this._countPagesRecursively(kids, 0) | ||
} | ||
this.objects = [] | ||
_countPagesRecursively(kids, i) { | ||
for (const kid of kids) { | ||
const page = kid.object | ||
if (page.properties.get('Type').toString() === '/Pages') { | ||
// encountered nested pages | ||
i = this._countPagesRecursively(page.properties.get('Kids'), i) | ||
} else { | ||
i++ | ||
} | ||
} | ||
const objects = [] | ||
Parser.addObjectsRecursive(objects, page) | ||
this.objects.push(objects) | ||
} | ||
return i | ||
} | ||
@@ -35,25 +41,47 @@ | ||
const kids = this.pages.get('Kids') | ||
const pages = page ? [kids[page - 1]] : kids | ||
const filter = page ? ((i) => i === (page - 1)) : undefined | ||
for (let i = page ? page - 1 : 0, len = page ? page : kids.length; i < len; ++i) { | ||
const page = kids[i].object | ||
const objects = this.objects[i] | ||
await this._addPagesRecursively(doc, kids, 0, filter) | ||
} | ||
doc._registerObject(page, true) | ||
async _addPagesRecursively(doc, kids, i, filter) { | ||
for (const kid of kids) { | ||
const page = kid.object | ||
// first, register objects to assign IDs (for references) | ||
for (const obj of objects) { | ||
doc._registerObject(obj, true) | ||
} | ||
if (page.properties.get('Type').toString() === '/Pages') { | ||
// encountered nested pages | ||
i = await this._addPagesRecursively(doc, page.properties.get('Kids'), i, filter) | ||
continue | ||
} else if (!filter || filter(i)) { | ||
// if the page object does not define its MediaBox, explicitly set its MediaBox to the | ||
// value defined by its parent Pages object | ||
if (!page.properties.has('MediaBox') && this.mediaBox) { | ||
page.properties.set('MediaBox', this.mediaBox) | ||
} | ||
// write objects | ||
for (const obj of objects) { | ||
await doc._writeObject(obj) | ||
// add single page | ||
doc._registerObject(page, true) | ||
// first, register objects to assign IDs (for references) | ||
const objects = [] | ||
Parser.addObjectsRecursive(objects, page, 0) | ||
for (const obj of objects) { | ||
doc._registerObject(obj, true) | ||
} | ||
// write objects | ||
for (const obj of objects) { | ||
await doc._writeObject(obj) | ||
} | ||
page.prop('Parent', doc._pagesObj.toReference()) | ||
await doc._writeObject(page) | ||
doc._pages.push(page.toReference()) | ||
} | ||
page.prop('Parent', doc._pagesObj.toReference()) | ||
await doc._writeObject(page) | ||
i++ | ||
} | ||
doc._pages.push(page.toReference()) | ||
} | ||
return i | ||
} | ||
@@ -68,4 +96,11 @@ | ||
} | ||
const first = kids[0].object.properties | ||
const objects = this.objects[0] | ||
const page = kids[0].object | ||
// if the page object does not define its MediaBox, explicitly set its MediaBox to the | ||
// value defined by its parent Pages object | ||
if (!page.properties.has('MediaBox') && this.mediaBox) { | ||
page.properties.set('MediaBox', this.mediaBox) | ||
} | ||
const first = page.properties | ||
const objects = [] | ||
Parser.addObjectsRecursive(objects, page, 0) | ||
@@ -125,1 +160,2 @@ // first, register objects to assign IDs (for references) | ||
@@ -114,3 +114,3 @@ 'use strict' | ||
case 0x0a: // LF | ||
lexer.skipEOL(1) | ||
// ignore EOL characters | ||
break | ||
@@ -117,0 +117,0 @@ default: |
{ | ||
"name": "pdfjs", | ||
"author": "Markus Ast <npm.m@rkusa.st>", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "A Portable Document Format (PDF) generation library targeting both the server- and client-side.", | ||
@@ -21,12 +21,12 @@ "keywords": [ | ||
"@rkusa/linebreak": "^1.0.0", | ||
"opentype.js": "^0.8.0", | ||
"pako": "^1.0.6", | ||
"readable-stream": "^2.3.6", | ||
"opentype.js": "^0.11.0", | ||
"pako": "^1.0.8", | ||
"readable-stream": "^3.1.1", | ||
"unorm": "^1.4.1", | ||
"uuid": "^3.0.1" | ||
"uuid": "^3.3.2" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^9.6.6", | ||
"tape": "^4.6.3", | ||
"typescript": "^2.8.3" | ||
"@types/node": "^10.12.23", | ||
"tape": "^4.9.2", | ||
"typescript": "^3.3.3" | ||
}, | ||
@@ -33,0 +33,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
9782979
0
76
6385
+ Addedopentype.js@0.11.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedstring.prototype.codepointat@0.2.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedisarray@1.0.0(transitive)
- Removedopentype.js@0.8.0(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
Updatedopentype.js@^0.11.0
Updatedpako@^1.0.8
Updatedreadable-stream@^3.1.1
Updateduuid@^3.3.2