Comparing version 2.0.0-alpha.1 to 2.0.0-alpha.2
@@ -71,2 +71,3 @@ 'use strict' | ||
this._pageFonts = {} | ||
this._annotations = [] | ||
@@ -91,6 +92,12 @@ // these properties are used to keep track of used Font and Image objects and assign ids to | ||
// init cursor | ||
this.padding = opts.padding >= 0 ? opts.padding : 20 | ||
// TODO: test for valid values | ||
const padding = opts.padding >= 0 ? opts.padding : 20 | ||
this.paddingTop = opts.paddingTop || padding | ||
this.paddingBottom = opts.paddingBottom || padding | ||
this.paddingLeft = opts.paddingLeft || padding | ||
this.paddingRight = opts.paddingRight || padding | ||
this._cursor = new Cursor( | ||
this.width - this.padding*2, this.height - this.padding*2, // width, height | ||
this.padding, this.height - this.padding // x, y | ||
this.width - this.paddingLeft - this.paddingRight, this.height - this.paddingTop - this.paddingBottom, // width, height | ||
this.paddingLeft, this.height - this.paddingTop // x, y | ||
) | ||
@@ -105,3 +112,3 @@ | ||
this._colorSpace = new PDF.Object() | ||
const iccProfile = require('./sRGB_IEC61966-2-1_black_scaled') | ||
const iccProfile = require('./sRGB_IEC61966-2-1_black_scaled') + '~>' | ||
this._colorSpace.content = 'stream\n' + iccProfile + '\nendstream\n' | ||
@@ -115,2 +122,4 @@ this._colorSpace.prop('Length', iccProfile.length) | ||
this._colorSpace.prop('Filter', new PDF.Name('ASCII85Decode')) | ||
this._registerObject(this._colorSpace) | ||
this._currentColorSpace = '/CS1' | ||
@@ -271,2 +280,15 @@ // start to work the _pending queue | ||
if (this._template) { | ||
const taken = {} | ||
for (const alias in this._template.colorSpaces) { | ||
taken[alias] = null | ||
} | ||
let i = 1 | ||
for (1; ('/CS' + i) in taken; ++i) {} | ||
this._currentColorSpace = '/CS' + i | ||
} else { | ||
this._currentColorSpace = '/CS1' | ||
} | ||
await this._startContentObject() | ||
@@ -336,3 +358,5 @@ | ||
const colorSpace = new PDF.Dictionary({}) | ||
const colorSpace = new PDF.Dictionary({ | ||
[this._currentColorSpace]: new PDF.Array([new PDF.Name('ICCBased'), this._colorSpace.toReference()]) | ||
}) | ||
page.prop('Resources', new PDF.Dictionary({ | ||
@@ -351,7 +375,10 @@ ColorSpace: colorSpace, | ||
if (this._annotations.length > 0) { | ||
page.prop('Annots', new PDF.Array(this._annotations)) | ||
this._annotations = [] | ||
} | ||
const contents = this._contents.map(c => c._object.toReference()) | ||
page.prop('Contents', new PDF.Array(contents)) | ||
let hasColorSpace = false | ||
if (this._template) { | ||
@@ -362,3 +389,2 @@ contents.unshift.apply(contents, this._template.contents) | ||
colorSpace.dictionary[alias] = this._template.colorSpaces[alias] | ||
hasColorSpace = true | ||
} | ||
@@ -375,16 +401,2 @@ | ||
if (!hasColorSpace) { | ||
this._registerObject(this._colorSpace) | ||
colorSpace.add('CS1', new PDF.Array([new PDF.Name('ICCBased'), this._colorSpace.toReference()])) | ||
} else { | ||
// re-use colorSpace | ||
if (!colorSpace.has('CS1')) { | ||
// create reference for CS1 alias | ||
for (const alias in colorSpace.dictionary) { | ||
colorSpace.dictionary[new PDF.Name('CS1')] = colorSpace.dictionary[alias] | ||
break // only interested in the first element | ||
} | ||
} | ||
} | ||
await this._writeObject(page) | ||
@@ -435,3 +447,3 @@ | ||
// set color space | ||
chunk += ops.CS('/CS1') + ops.cs('/CS1') | ||
chunk += ops.CS(this._currentColorSpace) + ops.cs(this._currentColorSpace) | ||
await this._write(chunk) | ||
@@ -499,6 +511,3 @@ | ||
await this._writeObject(this._pagesObj) | ||
if (this._colorSpace.id) { | ||
// only write colorspace if it is actually used (can tell by id being set) | ||
await this._writeObject(this._colorSpace) | ||
} | ||
await this._writeObject(this._colorSpace) | ||
@@ -505,0 +514,0 @@ for (const alias in this._fonts) { |
@@ -87,18 +87,6 @@ 'use strict' | ||
async write(doc, fontObj) { | ||
const descriptor = new PDFObject('FontDescriptor') | ||
descriptor.prop('FontName', this._data.fontName) | ||
descriptor.prop('FontBBox', new PDFArray(this._data.fontBBox)) | ||
descriptor.prop('ItalicAngle', this._data.italicAngle) | ||
descriptor.prop('Ascent', this.ascent) | ||
descriptor.prop('Descent', this.descent) | ||
descriptor.prop('XHeight', this._data.xHeight) | ||
descriptor.prop('CapHeight', this._data.capHeight) | ||
descriptor.prop('StemV', 0) | ||
fontObj.prop('Subtype', 'Type1') | ||
fontObj.prop('BaseFont', this._data.fontName) | ||
fontObj.prop('Encoding', 'WinAnsiEncoding') | ||
fontObj.prop('FontDescriptor', descriptor.toReference()) | ||
await doc._writeObject(descriptor) | ||
await doc._writeObject(fontObj) | ||
@@ -105,0 +93,0 @@ } |
@@ -9,2 +9,3 @@ 'use strict' | ||
const Font = require('./font/base') | ||
const PDF = require('./object') | ||
@@ -34,2 +35,4 @@ module.exports = class Text extends Fragment { | ||
this.alignment = opts.alignment || opts.textAlign || 'left' | ||
this.link = opts.link | ||
} | ||
@@ -59,2 +62,3 @@ | ||
const lineHeight = opts.lineHeight || this.defaultLineHeight | ||
const link = opts.link || this.link | ||
@@ -324,2 +328,19 @@ if (!Font.isFont(font)) { | ||
if (this.link) { | ||
// TODO: implement annotations in a more generic way | ||
const rectWidth = this._cursor.width - freeSpace | ||
const annot = new PDF.Dictionary({ | ||
Type: 'Annot', | ||
Subtype: 'Link', | ||
Rect: new PDF.Array([left, this._cursor.y, left + rectWidth, this._cursor.y + height]), | ||
Border: new PDF.Array([0, 0, 0]), | ||
A: new PDF.Dictionary({ | ||
Type: 'Action', | ||
S: 'URI', | ||
URI: new PDF.String(link), | ||
}), | ||
}) | ||
this._doc._annotations.push(annot) | ||
} | ||
this._cursor.y -= descent | ||
@@ -326,0 +347,0 @@ |
{ | ||
"name": "pdfjs", | ||
"author": "Markus Ast <npm.m@rkusa.st>", | ||
"version": "2.0.0-alpha.1", | ||
"version": "2.0.0-alpha.2", | ||
"description": "A Portable Document Format (PDF) generation library targeting both the server- and client-side.", | ||
@@ -18,3 +18,3 @@ "keywords": [ | ||
"dependencies": { | ||
"linebreak": "^0.3.0", | ||
"linebreak": "rkusa/linebreak", | ||
"opentype.js": "^0.6.2", | ||
@@ -21,0 +21,0 @@ "unorm": "^1.4.1", |
@@ -12,3 +12,3 @@ ![pdfjs](https://cdn.rawgit.com/rkusa/pdfjs/2.x/logo.svg) | ||
```bash | ||
npm install rkusa/pdfjs@2.0.0-alpha.1 | ||
npm install pdfjs@2.0.0-alpha.1 | ||
``` | ||
@@ -18,3 +18,3 @@ | ||
Version `2.0.0` is a re-write. I tried completely different approaches of the last years. Finally, this version has streaming layouting with smart content chunking, which allows for having a small memory footprint even when creating a PDF document with thousands of pages. I highly expect to settle with this implementation. | ||
Version `2.0.0` is a re-write. The implementation is expected to settle with the current approach of streaming layouting with smart content chunking, which allows for having a small memory footprint even when creating a PDF document with thousands of pages. | ||
@@ -21,0 +21,0 @@ ---------------- |
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
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
891537
3999
1
- Removedacorn@7.4.1(transitive)
- Removedbase64-js@0.0.8(transitive)
- Removedbrfs@1.6.1(transitive)
- Removedbuffer-equal@0.0.1(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedconvert-source-map@1.9.0(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddeep-is@0.1.4(transitive)
- Removedduplexer2@0.1.4(transitive)
- Removedescodegen@1.9.12.1.0(transitive)
- Removedesprima@3.1.34.0.1(transitive)
- Removedestraverse@4.3.05.3.0(transitive)
- Removedesutils@2.0.3(transitive)
- Removedfalafel@2.2.5(transitive)
- Removedfast-levenshtein@2.0.6(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedhas@1.0.4(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedisarray@1.0.02.0.5(transitive)
- Removedlevn@0.3.0(transitive)
- Removedlinebreak@0.3.0(transitive)
- Removedmagic-string@0.22.5(transitive)
- Removedmerge-source-map@1.0.4(transitive)
- Removedminimist@1.2.8(transitive)
- Removedobject-inspect@1.4.1(transitive)
- Removedoptionator@0.8.3(transitive)
- Removedpako@0.2.9(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedprelude-ls@1.1.2(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedquote-stream@1.0.2(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedshallow-copy@0.0.1(transitive)
- Removedsource-map@0.5.70.6.1(transitive)
- Removedstatic-eval@2.1.1(transitive)
- Removedstatic-module@2.2.5(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedthrough2@2.0.5(transitive)
- Removedtype-check@0.3.2(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedunicode-trie@0.3.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedvlq@0.2.3(transitive)
- Removedword-wrap@1.2.5(transitive)
- Removedxtend@4.0.2(transitive)
Updatedlinebreak@rkusa/linebreak