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.4.0 to 0.5.0

lib/content/image.js

8

lib/content/table.js

@@ -75,4 +75,5 @@ 'use strict'

} else {
if ('width' in this.opts)
if ('width' in this.opts) {
minWidth = utils.resolveWidth(widths, maxWidth)
}

@@ -400,6 +401,3 @@ var highestRowWidth = Math.max.apply(Math, this.rows.map(function(row) {

}
}
})
Object.defineProperties(Cell.prototype, {
},
borderTopWidth: {

@@ -406,0 +404,0 @@ enumerable: true,

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

// page break
if (round(page.spaceLeft) < round(lineHeight)) {
if (utils.round(page.spaceLeft) < utils.round(lineHeight)) {
page = self.doc.pagebreak()

@@ -253,5 +253,1 @@ page.cursor.x = left

}
function round(num) {
return Math.round(num * 100) / 100
}
'use strict'
var PDFObject = require('./objects/object')
var Pages = require('./pages')
var Font = require('./font')
var utils = require('./utils')
var PDFObject = require('./objects/object')
var PDFXObject = require('./objects/xobject')
var Pages = require('./pages')
var Font = require('./font')
var Image = require('./image')
var utils = require('./utils')

@@ -12,3 +14,3 @@ var Document = module.exports = function Document(font, opts) {

// list of all objects in this document
this.objects = []
this.objects = []

@@ -20,2 +22,4 @@ // list of all fonts in this document

this.images = []
// call parents constructor

@@ -66,9 +70,27 @@ if (!opts) opts = {}

Document.prototype.addObject = function(object) {
this.objects.push(object)
}
Document.prototype.createObject = function(type) {
var object = new PDFObject()
if (type) object.addProperty('Type', type)
this.objects.push(object)
this.addObject(object)
return object
}
Document.prototype.createXObject = function(subtype) {
var xobject = new PDFXObject()
if (type) xobject.addProperty('Subtype', subtype)
this.addObject(xobject)
return xobject
}
Document.prototype.createImage = function(data) {
var image = new Image('Im' + (this.images.length + 1), data)
this.images.push(image)
this.addObject(image.xobject)
return image
}
// Transaction

@@ -121,3 +143,10 @@ Document.prototype.startTransaction = function() {

})
this.images.forEach(function(image) {
image.embed(self)
})
this.objects.forEach(function(obj, i) {
obj.id = i + 1
})
var buf = '', xref = [], startxref

@@ -135,6 +164,2 @@

this.objects.forEach(function(obj, i) {
obj.id = i + 1
})
// body

@@ -159,6 +184,11 @@ this.objects.forEach(function(object) {

var id = (new PDFString(uuid4())).toHexString()
var version = require('../package.json').version
var trailer = new PDFDictionary({
Size: (this.objects.length + 1),
Root: this.catalog.toReference(),
ID: new PDFArray([id, id])
ID: new PDFArray([id, id]),
Info: new PDFDictionary({
Producer: new PDFString('pdfjs v' + version + ' (github.com/rkusa/pdfjs)'),
CreationDate: new PDFString(formatDate(new Date))
})
})

@@ -295,1 +325,23 @@ buf += 'trailer\n'

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

@@ -10,2 +10,4 @@ 'use strict'

var utils = require('../utils')
var embed = TTFFont.Subset.prototype.embed

@@ -19,3 +21,3 @@ TTFFont.Subset.prototype.embed = function(doc) {

font.prop('Encoding', 'Identity-H')
doc.objects.push(font)
doc.addObject(font)

@@ -111,3 +113,3 @@ var descendant = doc.createObject('Font')

var data = this.save()
var hex = asHex(data)
var hex = utils.asHex(data)

@@ -132,14 +134,1 @@ var file = new PDFStream(doc.createObject())

}
function toHex(n) {
if (n < 16) return '0' + n.toString(16)
return n.toString(16)
}
function asHex(ab) {
var view = new Uint8Array(ab), hex = ''
for (var i = 0, len = ab.byteLength; i < len; ++i) {
hex += toHex(view[i])
}
return hex
}

@@ -112,7 +112,10 @@ var Fragment = module.exports = function(doc, opts) {

// Text objects
Fragment.prototype.createXObject = function(subtype) {
return this.doc.createXObject(subtype)
}
Fragment.prototype.image = require('./content/image')
Fragment.prototype.op = require('./content/operation')
Fragment.prototype.table = require('./content/table')
Fragment.prototype.text = require('./content/text')
Fragment.prototype.table = require('./content/table')
Fragment.prototype.op = require('./content/operation')

@@ -119,0 +122,0 @@ Fragment.prototype.fragment = function(opts, definition) {

@@ -11,2 +11,3 @@ var PDFStream = require('./objects/stream')

this.fonts = new PDFDictionary({})
this.xobjects = new PDFDictionary({})
this.pageNumber = 1

@@ -23,3 +24,4 @@

ProcSet: new PDFArray([new PDFName('PDF'), new PDFName('Text'), new PDFName('ImageB'), new PDFName('ImageC'), new PDFName('ImageI')]),
Font: this.fonts
Font: this.fonts,
XObject: this.xobjects
}))

@@ -26,0 +28,0 @@ }

@@ -16,2 +16,6 @@ exports.extend = function(destination, source) {

exports.round = function(num) {
return Math.round(num * 100) / 100
}
exports.resolveWidth = function(width, maxWidth) {

@@ -28,1 +32,23 @@ var isRelative = !!~width.toString().indexOf('%')

}
exports.toHex = function(n) {
if (n < 16) return '0' + n.toString(16)
return n.toString(16)
}
exports.asHex = function(ab) {
var view = new Uint8Array(ab), hex = ''
for (var i = 0, len = ab.byteLength; i < len; ++i) {
hex += exports.toHex(view[i])
}
return hex
}
exports.toArrayBuffer = function(buffer) {
var ab = new ArrayBuffer(buffer.length);
var view = new Uint8Array(ab);
for (var i = 0; i < buffer.length; ++i) {
view[i] = buffer[i];
}
return ab;
}

@@ -7,3 +7,3 @@ {

},
"version": "0.4.0",
"version": "0.5.0",
"homepage": "https://github.com/rkusa/pdfjs",

@@ -10,0 +10,0 @@ "description": "A Portable Document Format (PDF) generation library targeting both the server- and client-side.",

@@ -11,10 +11,11 @@ # pdfjs

- Text (+ formatting)
- Images (JPEG)
- Tables
- Header & Footer
- Automatic page breaks
- Font embedding (as CID font, i.e., does supports many characters)
- Font embedding (as CID fonts, i.e., supports large character set fonts)
#### Missing Features
AFM fonts and graphics are currently not implemented. If you are missing a feature, feel free to ask or to submit a PR.
AFM fonts and vector graphics are currently not implemented. If you are missing a feature, feel free to ask or to submit a PR.

@@ -25,5 +26,6 @@ #### Contents

2. [Text](#text)
3. [Table](#table)
4. [Font](#font)
5. [License](#license)
3. [Image](#image)
4. [Table](#table)
5. [Font](#font)
6. [License](#license)

@@ -40,3 +42,3 @@ ## Document

* **font** - a font; will be used as default font
- **font** - a font; will be used as default font

@@ -57,14 +59,14 @@ **Example:**

* **text** - the text that should be rendered
* **opts** - text options
- **text** - the text that should be rendered
- **opts** - text options
**Options:**
* **bold** - whether the text should be rendered bold (default: false)
* **italic** - whether the text should be rendered italic (default: false)
* **light** - whether the text should be rendered light (default: false)
* **align** - the text alignment (default: left, available: left, right, center or justify)
* **lineSpacing** - this is a factor that could be used to increase or decrease the line spacing (default: 1)
* **font** - the font that should be used
* **size** - the font size
- **bold** - whether the text should be rendered bold (default: false)
- **italic** - whether the text should be rendered italic (default: false)
- **light** - whether the text should be rendered light (default: false)
- **align** - the text alignment (default: left, available: left, right, center or justify)
- **lineSpacing** - this is a factor that could be used to increase or decrease the line spacing (default: 1)
- **font** - the font that should be used
- **size** - the font size

@@ -87,3 +89,3 @@ **Example:**

* **definition** - a function describing the text to be rendered; it gets the `text` object described in [Text](#text)
- **definition** - a function describing the text to be rendered; it gets the `text` object described in [Text](#text)

@@ -112,2 +114,28 @@ **Example:**

### .image(buffer, [opts])
This method can be used to render an image.
**Arguments:**
- **buffer** - a Buffer, ArrayBuffer or instance of [Image](#image)
- **opts** - render options
**Options:**
- **width**, **height** - Image size. If neither `width` nor `height` are provided, the image is rendered to fit into the current context (e.g. page size). When either `width` or `height` is provided, the images is scaled proportionally; if both are provided, the image is stretched.
- **wrap** - whether the image should wrap surrounding text (default: true)
- **align** - when `wrap` is set to `true`, `align` can be used to set the horizontal positon (left, right, or center)
- **x**, **y** - when `wrap` is set to `false`, `x` and `y` can be used to explicitly set the position if the image
**Example:**
```js
fs.readFile('./picture.jpg', function(err, b) {
if (err) throw err
doc.image(b, { align: 'center' })
})
```
### .table([opts, ] [definition])

@@ -119,10 +147,10 @@

* **opts** - table options
* **definition** - a function that contains the table definition
- **opts** - table options
- **definition** - a function that contains the table definition
**Options:**
* **borderWidth** -
* **width** - total width (absolute or relative) or an array of column widths
* + [Text Options](#texttext-opts)
- **borderWidth** -
- **width** - total width (absolute or relative) or an array of column widths
- + [Text Options](#texttext-opts)

@@ -222,2 +250,17 @@ **Example:**

## Image
The image object should be used, when adding an image multiple times.
### doc.createImage(buffer)
This method is used to create a new image from the given buffer.
**Example:**
```js
var img = doc.createImage(buffer)
doc.image(img, { align: 'right' })
```
## Table

@@ -233,9 +276,9 @@

* **opts** - row options
* **definition** - a function that contains the row definition
- **opts** - row options
- **definition** - a function that contains the row definition
**Options:**
* **borderWidth** -
* + [Text Options](#texttext-opts)
- **borderWidth** -
- + [Text Options](#texttext-opts)

@@ -298,10 +341,10 @@ ### .beforeBreak([opts,] definition)

* **text** - the text contained in the cell
* **opts** - cell options
- **text** - the text contained in the cell
- **opts** - cell options
**Options:**
* **borderWidth** -
* **colspan** -
* + [Text Options](#texttext-opts)
- **borderWidth** -
- **colspan** -
- + [Text Options](#texttext-opts)

@@ -314,10 +357,10 @@ ### .td([opts,] definition)

* **opts** - cell options
* **definition** - a function that contains the cell definition
- **opts** - cell options
- **definition** - a function that contains the cell definition
**Options:**
* **borderWidth** -
* **colspan** -
* + [Text Options](#texttext-opts)
- **borderWidth** -
- **colspan** -
- + [Text Options](#texttext-opts)

@@ -331,8 +374,8 @@ ## Font

* **normal** -
* **italic** -
* **bold** -
* **boldItalic** -
* **light** -
* **lightItalic** -
- **normal** -
- **italic** -
- **bold** -
- **boldItalic** -
- **light** -
- **lightItalic** -

@@ -339,0 +382,0 @@ ## MIT License

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