Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pdfjs

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdfjs - npm Package Compare versions

Comparing version 2.0.0-alpha.1 to 2.0.0-alpha.2

63

lib/document.js

@@ -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 @@ ----------------

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc