Socket
Socket
Sign inDemoInstall

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 0.5.0 to 0.5.1

lib/.tern-port

125

lib/content/image.js

@@ -1,10 +0,6 @@

var Image = require('../image')
var PDFXObject = require('../objects/xobject')
var PDFStream = require('../objects/stream')
var PDFArray = require('../objects/array')
var PDFName = require('../objects/name')
var Image = require('../image')
var utils = require('../utils')
module.exports = exports = function(img, opts) {
var image = new ImageInstance(this, img, opts)
var image = new ImageInstance(this, img, opts)
this.contents.push(image)

@@ -15,63 +11,65 @@ return this

var ImageInstance = function(doc, img, opts) {
this.doc = doc.doc || doc
this.image = img instanceof Image ? img : doc.createImage(img)
this.opts = opts || {}
this.doc = doc.doc || doc
this.image = img instanceof Image ? img : doc.createImage(img)
this.opts = opts || {}
}
ImageInstance.prototype.render = function(page, widthLeft) {
var width, height
if (this.opts.width && this.opts.height) {
width = this.opts.width
height = this.opts.height
} else if(this.opts.width) {
width = this.opts.width
height = this.image.height * (this.opts.width / this.image.width)
} else if (this.opts.height) {
height = this.opts.height
width = this.image.width * (this.opts.height / this.image.height)
} else {
width = Math.min(this.image.width, widthLeft)
height = this.image.height * (width / this.image.width)
var width, height
if (this.opts.width && this.opts.height) {
width = this.opts.width
height = this.opts.height
} else if(this.opts.width) {
width = this.opts.width
height = this.image.height * (this.opts.width / this.image.width)
} else if (this.opts.height) {
height = this.opts.height
width = this.image.width * (this.opts.height / this.image.height)
} else {
width = Math.min(this.image.width, widthLeft)
height = this.image.height * (width / this.image.width)
if (height > this.doc.innerHeight) {
height = this.doc.innerHeight
width = this.image.width * (height / this.image.height)
}
}
if (height > this.doc.innerHeight) {
height = this.doc.innerHeight
width = this.image.width * (height / this.image.height)
}
}
// page break
if (utils.round(page.spaceLeft) < utils.round(height)) {
var left = page.cursor.x
page = this.doc.pagebreak()
page.cursor.x = left
}
console.log(width, height)
this.image.addTo(page)
// page break
if (utils.round(page.spaceLeft) < utils.round(height)) {
var left = page.cursor.x
page = this.doc.pagebreak()
page.cursor.x = left
}
var x = page.cursor.x
var y = page.cursor.y - height
this.image.addTo(page)
switch (this.opts.align) {
case 'right':
x += widthLeft - width
break
case 'center':
x += (widthLeft - width) / 2
break
case 'left':
default:
break
}
var x = page.cursor.x
var y = page.cursor.y - height
if (this.opts.wrap === false) {
x = this.opts.x || x
y = this.opts.y && (this.doc.height - height - this.opts.y) || y
} else {
page.cursor.y = y
}
switch (this.opts.align) {
case 'right':
x += widthLeft - width
break
case 'center':
x += (widthLeft - width) / 2
break
case 'left':
default:
break
}
page.contents.writeLine('q') // save graphics state
page.contents.writeLine(width + ' 0 0 ' + height + ' ' + x + ' ' + y + ' cm') // translate and scale
page.contents.writeLine('/' + this.image.id + ' Do') // paint image
page.contents.writeLine('Q') // restore graphics state
if (this.opts.wrap === false) {
x = this.opts.x || x
y = this.opts.y && (this.doc.height - height - this.opts.y) || y
} else {
page.cursor.y = y
}
page.contents.writeLine('q') // save graphics state
page.contents.writeLine(width + ' 0 0 ' + height + ' ' + x + ' ' + y + ' cm') // translate and scale
page.contents.writeLine('/' + this.image.id + ' Do') // paint image
page.contents.writeLine('Q') // restore graphics state
}

@@ -83,16 +81,5 @@

get: function() {
return this.image.width
return this.image.width
}
}
})
// ImageInstance.prototype.render = function(page, width, context) {
// this.addTo(page);
// var renderedWidth = this.opts.isBackground? page.doc.innerWidth : this.width;
// var renderedHeight = this.opts.isBackground? page.doc.innerHeight : this.height;
// var startY = (this.opts.isBackground? page.doc.padding.top: page.cursor.y - renderedHeight);
// page.contents.writeLine("q " + renderedWidth + " 0 0 " + renderedHeight + " " + page.cursor.x + " " + startY + " cm /I" + this.id + " Do Q ")
// if(!this.opts.isBackground){
// page.cursor.y -= this.height;
// }
// }

@@ -81,3 +81,3 @@ 'use strict'

var xobject = new PDFXObject()
if (type) xobject.addProperty('Subtype', subtype)
if (subtype) xobject.addProperty('Subtype', subtype)
this.addObject(xobject)

@@ -124,4 +124,5 @@ return xobject

var base64 = require('base-64')
Document.prototype.toDataURL = function() {
return 'data:application/pdfbase64,' + Base64.encode(this.toString())
return 'data:application/pdf;base64,' + base64.encode(this.toString())
}

@@ -132,2 +133,3 @@

var PDFString = require('./objects/string')
var uuid = require('node-uuid')

@@ -181,3 +183,3 @@ Document.prototype.toString = function() {

// trailer
var id = (new PDFString(uuid4())).toHexString()
var id = (new PDFString(uuid.v4())).toHexString()
var version = require('../package.json').version

@@ -190,3 +192,3 @@ var trailer = new PDFDictionary({

Producer: new PDFString('pdfjs v' + version + ' (github.com/rkusa/pdfjs)'),
CreationDate: new PDFString(formatDate(new Date))
CreationDate: new PDFString(utils.formatDate(new Date))
})

@@ -229,118 +231,2 @@ })

/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/
var Base64 = {
// private property
_keyStr : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
// public method for encoding
encode : function (input) {
var output = ''
var chr1, chr2, chr3, enc1, enc2, enc3, enc4
var i = 0
input = Base64._utf8Encode(input)
while (i < input.length) {
chr1 = input.charCodeAt(i++)
chr2 = input.charCodeAt(i++)
chr3 = input.charCodeAt(i++)
enc1 = chr1 >> 2
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4)
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6)
enc4 = chr3 & 63
if (isNaN(chr2)) {
enc3 = enc4 = 64
} else if (isNaN(chr3)) {
enc4 = 64
}
output = output +
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4)
}
return output
},
// private method for UTF-8 encoding
_utf8Encode : function (string) {
string = string.replace(/\r\n/g,'\n')
var utftext = ''
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n)
// workaround to not encode UTF8 characters
// TODO: improve ...
utftext += String.fromCharCode(Math.min(c, 0xff))
// if (c < 128) {
// utftext += String.fromCharCode(c)
// }
// else if((c > 127) && (c < 2048)) {
// utftext += String.fromCharCode((c >> 6) | 192)
// utftext += String.fromCharCode((c & 63) | 128)
// }
// else {
// utftext += String.fromCharCode((c >> 12) | 224)
// utftext += String.fromCharCode(((c >> 6) & 63) | 128)
// utftext += String.fromCharCode((c & 63) | 128)
// }
}
return utftext
}
}
// UUID v4
// source: https://gist.github.com/jed/982883
function uuid4(
a // placeholder
){
return a // if the placeholder was passed, return
? ( // a random number from 0 to 15
a ^ // unless b is 8,
Math.random() // in which case
* 16 // a random number from
>> a / 4 // 8 to 11
).toString(16) // in hexadecimal
: ( // or otherwise a concatenated string:
[1e7] + // 10000000 +
-1e3 + // -1000 +
-4e3 + // -4000 +
-8e3 + // -80000000 +
-1e11 // -100000000000,
).replace( // replacing
/[018]/g, // zeroes, ones, and eights with
uuid4 // random hex digits
)
}
function formatDate(date) {
var str = 'D:'
+ date.getFullYear()
+ ('00' + (date.getMonth() + 1)).slice(-2)
+ ('00' + date.getDate()).slice(-2)
+ ('00' + date.getHours()).slice(-2)
+ ('00' + date.getMinutes()).slice(-2)
+ ('00' + date.getSeconds()).slice(-2)
var offset = date.getTimezoneOffset()
var rel = offset === 0 ? 'Z' : (offset > 0 ? '-' : '+')
offset = Math.abs(offset)
var hoursOffset = Math.floor(offset / 60)
var minutesOffset = offset - hoursOffset * 60
str += rel
+ ('00' + hoursOffset).slice(-2) + '\''
+ ('00' + minutesOffset).slice(-2) + '\''
return str
}

@@ -0,4 +1,5 @@

'use strict'
var PDFXObject = require('./objects/xobject')
var PDFArray = require('./objects/array')
var PDFName = require('./objects/name')
var utils = require('./utils')

@@ -29,8 +30,8 @@

this.colorSpace = 'DeviceRGB'
break;
break
case 1:
this.colorSpace = 'DeviceGRAY'
break;
break
default:
break;
break
}

@@ -73,10 +74,10 @@

if (
view.getUint8(i+1) === 0xc0 || //(SOF) Huffman - Baseline DCT
view.getUint8(i+1) === 0xc1 || //(SOF) Huffman - Extended sequential DCT
view.getUint8(i+1) === 0xc2 || // Progressive DCT (SOF2)
view.getUint8(i+1) === 0xc3 || // Spatial (sequential) lossless (SOF3)
view.getUint8(i+1) === 0xc4 || // Differential sequential DCT (SOF5)
view.getUint8(i+1) === 0xc5 || // Differential progressive DCT (SOF6)
view.getUint8(i+1) === 0xc6 || // Differential spatial (SOF7)
view.getUint8(i+1) === 0xc7
view.getUint8(i + 1) === 0xc0 || //(SOF) Huffman - Baseline DCT
view.getUint8(i + 1) === 0xc1 || //(SOF) Huffman - Extended sequential DCT
view.getUint8(i + 1) === 0xc2 || // Progressive DCT (SOF2)
view.getUint8(i + 1) === 0xc3 || // Spatial (sequential) lossless (SOF3)
view.getUint8(i + 1) === 0xc4 || // Differential sequential DCT (SOF5)
view.getUint8(i + 1) === 0xc5 || // Differential progressive DCT (SOF6)
view.getUint8(i + 1) === 0xc6 || // Differential spatial (SOF7)
view.getUint8(i + 1) === 0xc7
) {

@@ -83,0 +84,0 @@ return {

@@ -1,8 +0,4 @@

var PDFReference = require('./reference')
var PDFDictionary = require('./dictionary')
var PDFObject = require('./object')
var PDFStream = require('./stream')
var PDFXObject = module.exports = function(id, rev) {

@@ -9,0 +5,0 @@ PDFObject.call(this, id, rev)

@@ -46,8 +46,30 @@ exports.extend = function(destination, source) {

exports.toArrayBuffer = function(buffer) {
var ab = new ArrayBuffer(buffer.length);
var view = new Uint8Array(ab);
var ab = new ArrayBuffer(buffer.length)
var view = new Uint8Array(ab)
for (var i = 0; i < buffer.length; ++i) {
view[i] = buffer[i];
view[i] = buffer[i]
}
return ab;
return ab
}
exports.formatDate = function(date) {
var str = 'D:'
+ date.getFullYear()
+ ('00' + (date.getMonth() + 1)).slice(-2)
+ ('00' + date.getDate()).slice(-2)
+ ('00' + date.getHours()).slice(-2)
+ ('00' + date.getMinutes()).slice(-2)
+ ('00' + date.getSeconds()).slice(-2)
var offset = date.getTimezoneOffset()
var rel = offset === 0 ? 'Z' : (offset > 0 ? '-' : '+')
offset = Math.abs(offset)
var hoursOffset = Math.floor(offset / 60)
var minutesOffset = offset - hoursOffset * 60
str += rel
+ ('00' + hoursOffset).slice(-2) + '\''
+ ('00' + minutesOffset).slice(-2) + '\''
return str
}

@@ -7,6 +7,9 @@ {

},
"version": "0.5.0",
"version": "0.5.1",
"homepage": "https://github.com/rkusa/pdfjs",
"description": "A Portable Document Format (PDF) generation library targeting both the server- and client-side.",
"keywords": ["pdf", "generator"],
"keywords": [
"pdf",
"generator"
],
"license": "MIT",

@@ -21,14 +24,16 @@ "main": "lib/document",

"dependencies": {
"base-64": "^0.1.0",
"ttfjs": "0.2.x"
},
"devDependencies": {
"browserify": "2.x.x",
"chai": "1.8.x",
"mocha": "1.13.x",
"chai": "1.8.x",
"browserify": "2.x.x",
"node-uuid": "^1.4.1",
"uglify-js": "2.x.x"
},
"bugs": "https://github.com/rkusa/pdfjs/issues",
"repository" : {
"type" : "git",
"url" : "git://github.com/rkusa/pdfjs.git"
"repository": {
"type": "git",
"url": "git://github.com/rkusa/pdfjs.git"
},

@@ -35,0 +40,0 @@ "engines": {

@@ -1,2 +0,2 @@

# pdfjs
![pdfjs](https://raw.githubusercontent.com/rkusa/pdfjs/master/logo/pdfjs.png)

@@ -11,3 +11,3 @@ A Portable Document Format (PDF) generation library targeting both the server- and client-side.

- Text (+ formatting)
- Images (JPEG)
- Images (JPEGs)
- Tables

@@ -14,0 +14,0 @@ - Header & Footer

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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