New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pdfmake

Package Overview
Dependencies
Maintainers
4
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdfmake - npm Package Compare versions

Comparing version 0.1.27 to 0.1.28

dev-playground/public/mode-javascript.js

10

dev-playground/server.js

@@ -14,3 +14,3 @@

app.use(express.static(rootDir + '/dev-playground/public/'));
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json({ limit: '50mb' }));

@@ -23,6 +23,6 @@ app.use(bodyParser.urlencoded({ extended: false }));

Roboto: {
normal: 'examples/fonts/Roboto-Regular.ttf',
bold: 'examples/fonts/Roboto-Medium.ttf',
italics: 'examples/fonts/Roboto-Italic.ttf',
bolditalics: 'examples/fonts/Roboto-MediumItalic.ttf'
normal: path.join(__dirname, '..', 'examples', '/fonts/Roboto-Regular.ttf'),
bold: path.join(__dirname, '..', 'examples', '/fonts/Roboto-Medium.ttf'),
italics: path.join(__dirname, '..', 'examples', '/fonts/Roboto-Italic.ttf'),
bolditalics: path.join(__dirname, '..', 'examples', '/fonts/Roboto-MediumItalic.ttf')
}

@@ -29,0 +29,0 @@ };

@@ -87,3 +87,3 @@ var gulp = require('gulp');

.pipe(each(function (content, file, callback) {
var newContent = 'window.pdfMake = window.pdfMake || {}; window.pdfMake.vfs = ' + content + ';';
var newContent = 'this.pdfMake = this.pdfMake || {}; this.pdfMake.vfs = ' + content + ';';
callback(null, newContent);

@@ -90,0 +90,0 @@ }, 'buffer'))

{
"name": "pdfmake",
"version": "0.1.27",
"version": "0.1.28",
"description": "Client/server side PDF printing in pure JavaScript",

@@ -20,4 +20,4 @@ "main": "src/printer.js",

"gulp-replace": "^0.5.4",
"gulp-sourcemaps": "^2.4.1",
"gulp-spawn-mocha": "^3.1.0",
"gulp-sourcemaps": "^2.6.0",
"gulp-spawn-mocha": "^3.3.0",
"gulp-uglify": "^2.1.2",

@@ -28,6 +28,6 @@ "gulp-util": "^3.0.8",

"gulp-header": "^1.8.8",
"iconv-lite":"^0.4.15",
"iconv-lite":"^0.4.16",
"json-loader": "^0.5.4",
"sinon": "^2.1.0",
"mocha":"^3.2.0",
"mocha":"^3.3.0",
"jshint":"^2.9.4",

@@ -37,3 +37,3 @@ "string-replace-webpack-plugin": "^0.1.3",

"brfs": "^1.4.3",
"webpack": "^2.3.2",
"webpack": "^2.4.1",
"webpack-stream": "^3.2.0"

@@ -40,0 +40,0 @@ },

@@ -32,11 +32,11 @@ # pdfmake [![Build Status][travis_img]][travis_url] [![GitHub][github_img]][github_url] [![npm][npm_img]][npm_url] [![Bower][bower_img]][bower_url] [![Packagist][packagist_img]][packagist_url] [![CDNJS][cdnjs_img]][cndjs_url]

* tables and columns
* auto/fixed/star-sized widths,
* col-spans and row-spans,
* headers automatically repeated in case of a page-break,
* auto/fixed/star-sized widths,
* col-spans and row-spans,
* headers automatically repeated in case of a page-break,
* images and vector graphics,
* convenient styling and style inheritance,
* page headers and footers:
* static or dynamic content,
* access to current page number and page count,
* background-layer
* static or dynamic content,
* access to current page number and page count,
* background-layer,
* page dimensions and orientations,

@@ -47,4 +47,4 @@ * margins,

* support for complex, multi-level (nested) structures,
* helper methods for opening/printing/downloading the generated PDF.
* setting of PDF metadata (e.g. author, subject)
* helper methods for opening/printing/downloading the generated PDF,
* setting of PDF metadata (e.g. author, subject).

@@ -97,15 +97,65 @@ ## Getting Started

As soon as you have the document-definition-object, you're ready to create and open/print/download the PDF:
As soon as you have the document-definition-object, you're ready to create and download/open/print the PDF:
```js
pdfMake.createPdf(docDefinition).download();
```js
// open the PDF in a new window
pdfMake.createPdf(docDefinition).open();
// print the PDF
pdfMake.createPdf(docDefinition).print();
```
Details in the next chapters.
// download the PDF
#### Download the PDF
```js
pdfMake.createPdf(docDefinition).download();
```
Parameters:
* `defaultFileName` _(optional)_ - file name
* `cb` _(optional)_ - callback function
* `options` _(optional)_
// put the PDF into your own page as URL data
#### Open the PDF in a new window
```js
pdfMake.createPdf(docDefinition).open();
```
Parameters:
* `options` _(optional)_
* `win` _(optional)_ - window (when an asynchronous operation)
Name can be defined only by using metadata `title` property (see [Document metadata](#document-metadata)).
Asynchronous example:
```js
$scope.generatePdf = function() {
// create the window before the callback
var win = window.open('', '_blank');
$http.post('/someUrl', data).then(function(response) {
// pass the "win" argument
pdfMake.createPdf(docDefinition).open({}, win);
});
};
```
#### Print the PDF
```js
pdfMake.createPdf(docDefinition).print();
```
Parameters:
* `options` _(optional)_
* `win` _(optional)_ - window (when an asynchronous operation)
Asynchronous example:
```js
$scope.generatePdf = function() {
// create the window before the callback
var win = window.open('', '_blank');
$http.post('/someUrl', data).then(function(response) {
// pass the "win" argument
pdfMake.createPdf(docDefinition).print({}, win);
});
};
```
#### Put the PDF into your own page as URL data
```js
const pdfDocGenerator = pdfMake.createPdf(docDefinition);

@@ -118,4 +168,9 @@ pdfDocGenerator.getDataUrl((dataUrl) => {

});
```
Parameters:
* `cb` - callback function
* `options` _(optional)_
// get the PDF as base64 data
#### Get the PDF as base64 data
```js
const pdfDocGenerator = pdfMake.createPdf(docDefinition);

@@ -125,4 +180,9 @@ pdfDocGenerator.getBase64((data) => {

});
```
Parameters:
* `cb` - callback function
* `options` _(optional)_
// or get the PDF as buffer
#### Get the PDF as buffer
```js
const pdfDocGenerator = pdfMake.createPdf(docDefinition);

@@ -133,2 +193,5 @@ pdfDocGenerator.getBuffer((buffer) => {

```
Parameters:
* `cb` - callback function
* `options` _(optional)_

@@ -499,3 +562,10 @@ #### Styling

#### Links
To add external or internal links, use the following syntax:
```
{text: 'google', link: 'http://google.com'}
{text:'Go to page 2', linkToPage: 2}
```
#### Page dimensions, orientation and margins

@@ -540,3 +610,2 @@

(From PdfKit Guide)
PDF documents can have various metadata associated with them, such as the title, or author

@@ -557,2 +626,18 @@ of the document. You can add that information by adding it to the document definition

Standard properties:
* **title** - the title of the document
* **author** - the name of the author
* **subject** - the subject of the document
* **keywords** - keywords associated with the document
* **creator** - the creator of the document (default is 'pdfmake')
* **producer** - the producer of the document (default is 'pdfmake')
* **creationDate** - the date the document was created (added automatically by pdfmake)
* **modDate** - the date the document was last modified
* **trapped** - the trapped flag in a PDF document indicates whether the document has been "trapped"
Custom properties:
You can add custom properties. Key of property not contain spaces.
#### Compression

@@ -594,6 +679,8 @@

-------
## Authors
* [@bpampuch](https://github.com/bpampuch) (founder)
* [@liborm85](https://github.com/liborm85)
pdfmake is based on a truly amazing library pdfkit.org - credits to @devongovett
pdfmake is based on a truly amazing library [pdfkit](https://github.com/devongovett/pdfkit) (credits to [@devongovett](https://github.com/devongovett)).
big thanks to @yelouafi for making this library even better
Thanks to all contributors.

@@ -90,3 +90,3 @@ /* jslint node: true */

// otherwise popup blockers will stop us
var win = window.open('', '_blank');
var win = global.open('', '_blank');
if (win === null) {

@@ -99,7 +99,9 @@ throw 'Open PDF in new window blocked by browser';

Document.prototype._openPdf = function (options) {
var win = this._openWindow();
Document.prototype._openPdf = function (options, win) {
if (!win) {
win = this._openWindow();
}
try {
this.getBlob(function (result) {
var urlCreator = window.URL || window.webkitURL;
var urlCreator = global.URL || global.webkitURL;
var pdfUrl = urlCreator.createObjectURL(result);

@@ -114,15 +116,17 @@ win.location.href = pdfUrl;

Document.prototype.open = function (options) {
Document.prototype.open = function (options, win) {
options = options || {};
options.autoPrint = false;
win = win || null;
this._openPdf(options);
this._openPdf(options, win);
};
Document.prototype.print = function (options) {
Document.prototype.print = function (options, win) {
options = options || {};
options.autoPrint = true;
win = win || null;
this._openPdf(options);
this._openPdf(options, win);
};

@@ -189,4 +193,4 @@

}
return new Document(docDefinition, window.pdfMake.tableLayouts, window.pdfMake.fonts, window.pdfMake.vfs);
return new Document(docDefinition, global.pdfMake.tableLayouts, global.pdfMake.fonts, global.pdfMake.vfs);
}
};

@@ -181,2 +181,22 @@ /* jslint node: true */

node._height = node.height || (imageSize.height * node._width / imageSize.width);
if (typeof node.maxWidth === "number" && node.maxWidth < node._width) {
node._width = node._minWidth = node._maxWidth = node.maxWidth;
node._height = node._width * imageSize.height / imageSize.width;
}
if (typeof node.maxHeight === "number" && node.maxHeight < node._height) {
node._height = node.maxHeight;
node._width = node._minWidth = node._maxWidth = node._height * imageSize.width / imageSize.height;
}
if (typeof node.minWidth === "number" && node.minWidth > node._width) {
node._width = node._minWidth = node._maxWidth = node.minWidth;
node._height = node._width * imageSize.height / imageSize.width;
}
if (typeof node.minHeight === "number" && node.minHeight > node._height) {
node._height = node.minHeight;
node._width = node._minWidth = node._maxWidth = node._height * imageSize.width / imageSize.height;
}
}

@@ -183,0 +203,0 @@

@@ -85,2 +85,3 @@ /* jslint node: true */

line.inlines[i].x += offset;
line.inlines[i].justifyShift = additionalSpacing;
}

@@ -87,0 +88,0 @@ }

@@ -168,3 +168,3 @@ /* jslint node: true */

this.addDynamicRepeatable(function () {
return headerOrFooter;
return JSON.parse(JSON.stringify(headerOrFooter)); // copy to new object
}, sizeFunction);

@@ -171,0 +171,0 @@ };

@@ -128,15 +128,28 @@ /* jslint node: true */

function setMetadata(docDefinition, pdfKitDoc) {
// PDF standard has these properties reserved: Title, Author, Subject, Keywords,
// Creator, Producer, CreationDate, ModDate, Trapped.
// To keep the pdfmake api consistent, the info field are defined lowercase.
// Custom properties don't contain a space.
function standardizePropertyKey(key) {
var standardProperties = ['Title', 'Author', 'Subject', 'Keywords',
'Creator', 'Producer', 'CreationDate', 'ModDate', 'Trapped'];
var standardizedKey = key.charAt(0).toUpperCase() + key.slice(1);
if (standardProperties.indexOf(standardizedKey) !== -1) {
return standardizedKey;
}
return key.replace(/\s+/g, '');
}
pdfKitDoc.info.Producer = 'pdfmake';
pdfKitDoc.info.Creator = 'pdfmake';
// pdf kit maintains the uppercase fieldnames from pdf spec
// to keep the pdfmake api consistent, the info field are defined lowercase
if (docDefinition.info) {
var info = docDefinition.info;
// check for falsey an set null, so that pdfkit always get either null or value
pdfKitDoc.info.Title = info.title ? info.title : null;
pdfKitDoc.info.Author = info.author ? info.author : null;
pdfKitDoc.info.Subject = info.subject ? info.subject : null;
pdfKitDoc.info.Keywords = info.keywords ? info.keywords : null;
pdfKitDoc.info.CreationDate = info.creationDate ? info.creationDate : null;
for (var key in docDefinition.info) {
var value = docDefinition.info[key];
if (value) {
key = standardizePropertyKey(key);
pdfKitDoc.info[key] = value;
}
}
}

@@ -350,5 +363,12 @@ }

textWidth: inline.width,
characterSpacing: inline.characterSpacing,
wordCount: 1,
link: inline.link
});
if (inline.linkToPage) {
var _ref = pdfKitDoc.ref({Type: 'Action', S: 'GoTo', D: [inline.linkToPage, 0, 0]}).end();
pdfKitDoc.annotate(x + inline.x, y + shiftToBaseline, inline.width, inline.height, {Subtype: 'Link', Dest: [inline.linkToPage - 1, 'XYZ', null, null, null]});
}
}

@@ -388,4 +408,2 @@

}
pdfKitDoc.fillOpacity(vector.fillOpacity || 1);
pdfKitDoc.strokeOpacity(vector.strokeOpacity || 1);
pdfKitDoc.lineJoin(vector.lineJoin || 'miter');

@@ -443,7 +461,11 @@

if (vector.color && vector.lineColor) {
pdfKitDoc.fillAndStroke(vector.color, vector.lineColor);
pdfKitDoc.fillColor(vector.color, vector.fillOpacity || 1);
pdfKitDoc.strokeColor(vector.lineColor, vector.strokeOpacity || 1);
pdfKitDoc.fillAndStroke();
} else if (vector.color) {
pdfKitDoc.fill(vector.color);
pdfKitDoc.fillColor(vector.color, vector.fillOpacity || 1);
pdfKitDoc.fill();
} else {
pdfKitDoc.stroke(vector.lineColor || 'black');
pdfKitDoc.strokeColor(vector.lineColor || 'black', vector.strokeOpacity || 1);
pdfKitDoc.stroke();
}

@@ -450,0 +472,0 @@ }

@@ -100,2 +100,3 @@ /* jslint node: true */

'lineHeight',
'characterSpacing',
'noWrap',

@@ -102,0 +103,0 @@ 'markerColor'

@@ -137,4 +137,5 @@ /* jslint node: true */

if (inline.background) {
var justifyShift = (inline.justifyShift || 0);
pdfKitDoc.fillColor(inline.background)
.rect(x + inline.x, y, inline.width, height)
.rect(x + inline.x - justifyShift, y, inline.width + justifyShift, height)
.fill();

@@ -141,0 +142,0 @@ }

@@ -81,2 +81,3 @@ /* jslint node: true */

var lineHeight = getStyleProperty({}, styleContextStack, 'lineHeight', 1);
var characterSpacing = getStyleProperty({}, styleContextStack, 'characterSpacing', 0);

@@ -86,3 +87,3 @@ var font = this.fontProvider.provideFont(fontName, bold, italics);

return {
width: font.widthOfString(text, fontSize),
width: widthOfString(text, font, fontSize, characterSpacing),
height: font.lineHeight(fontSize) * lineHeight,

@@ -225,8 +226,9 @@ fontSize: fontSize,

var lineHeight = getStyleProperty(item, styleContextStack, 'lineHeight', 1);
var characterSpacing = getStyleProperty(item, styleContextStack, 'characterSpacing', 0);
var link = getStyleProperty(item, styleContextStack, 'link', null);
var linkToPage = getStyleProperty(item, styleContextStack, 'linkToPage', null);
var font = fontProvider.provideFont(fontName, bold, italics);
// TODO: character spacing
item.width = font.widthOfString(item.text, fontSize);
item.width = widthOfString(item.text, font, fontSize, characterSpacing);
item.height = font.lineHeight(fontSize) * lineHeight;

@@ -237,3 +239,3 @@

if (leadingSpaces) {
item.leadingCut = font.widthOfString(leadingSpaces[0], fontSize);
item.leadingCut = widthOfString(leadingSpaces[0], font, fontSize, characterSpacing);
} else {

@@ -244,3 +246,3 @@ item.leadingCut = 0;

if (trailingSpaces) {
item.trailingCut = font.widthOfString(trailingSpaces[0], fontSize);
item.trailingCut = widthOfString(trailingSpaces[0], font, fontSize, characterSpacing);
} else {

@@ -253,2 +255,3 @@ item.trailingCut = 0;

item.fontSize = fontSize;
item.characterSpacing = characterSpacing;
item.color = color;

@@ -260,2 +263,3 @@ item.decoration = decoration;

item.link = link;
item.linkToPage = linkToPage;
});

@@ -266,2 +270,6 @@

function widthOfString(text, font, fontSize, characterSpacing) {
return font.widthOfString(text, fontSize) + ((characterSpacing || 0) * (text.length - 1));
}
/****TESTS**** (add a leading '/' to uncomment)

@@ -268,0 +276,0 @@ TextTools.prototype.splitWords = splitWords;

@@ -41,2 +41,13 @@ var path = require('path');

},
/* hack for Web Worker support */
{test: /FileSaver.js$/, loader: StringReplacePlugin.replace({
replacements: [
{
pattern: 'doc.createElementNS("http://www.w3.org/1999/xhtml", "a")',
replacement: function () {
return 'doc ? doc.createElementNS("http://www.w3.org/1999/xhtml", "a") : []';
}
}
]})
},
/* hack for IE 10 */

@@ -43,0 +54,0 @@ {test: /brotli[\/\\]dec[\/\\]/, loader: StringReplacePlugin.replace({

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

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