Skip to content

Commit e3cdf6e

Browse files
committedSep 24, 2018
fix page size of some externally added pages
Refs rkusa#111
1 parent 20cf74b commit e3cdf6e

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed
 

‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- Pages from external documents should always be added with their original size #111
810

911
## [2.1.0] - 2018-09-22
1012
### Changed

‎lib/external.js

+7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@ module.exports = class ExternalDocument {
1212
const pages = catalog.get('Pages').object.properties
1313

1414
this.pages = pages
15+
const mediaBox = pages.get('MediaBox')
1516
const kids = pages.get('Kids')
1617
this.pageCount = kids.length
1718

1819
this.objects = []
1920
for (const kid of kids) {
2021
const page = kid.object
2122

23+
// if the page object does not define its MediaBox, explicitly set its MediaBox to the
24+
// value defined by its parent Pages object
25+
if (!page.properties.has('MediaBox') && mediaBox) {
26+
page.properties.set('MediaBox', mediaBox)
27+
}
28+
2229
const objects = []
2330
Parser.addObjectsRecursive(objects, page)
2431

4.77 KB
Binary file not shown.

‎test/pdfs/external/pagesize.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = function(doc, {document}) {
2+
doc.text('First')
3+
4+
const pdf = require('../../../')
5+
const path = require('path')
6+
const fs = require('fs')
7+
8+
const external = new pdf.ExternalDocument(fs.readFileSync(path.join(__dirname, '/fixtures/200x200.pdf')))
9+
doc.addPagesOf(external)
10+
11+
doc.text('Second')
12+
}

‎test/pdfs/external/pagesize.pdf

9.11 KB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.