@react-pdf/pdfkit
Advanced tools
Comparing version 1.2.0 to 1.3.0
{ | ||
"name": "@react-pdf/pdfkit", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "A PDF generation library for Node.js", | ||
@@ -17,6 +17,13 @@ "main": "dist/pdfkit.cjs.js", | ||
"scripts": { | ||
"build": "rollup -c", | ||
"build": "rimraf ./dist && rollup -c", | ||
"prepublish": "npm run build", | ||
"prebuild": "node ./src/font/data/compressData.js", | ||
"postbuild": "rimraf ./src/font/data/*.b64.afm" | ||
"prebuild": "node ./lib/font/data/compressData.js", | ||
"postbuild": "rimraf ./lib/font/data/*.b64.afm", | ||
"browser-demo": "browserify demo/browser.js > demo/bundle.js", | ||
"pdf-guide": "node docs/generate.js", | ||
"website": "node docs/generate_website.js", | ||
"docs": "npm run pdf-guide && npm run website && npm run browser-demo", | ||
"test": "jest -i", | ||
"test:integration": "jest integration/ -i", | ||
"test:unit": "jest unit/ -i" | ||
}, | ||
@@ -26,16 +33,23 @@ "files": [ | ||
], | ||
"dependencies": { | ||
"@react-pdf/fontkit": "^1.11.0", | ||
"@react-pdf/png-js": "^1.0.0", | ||
"lz-string": "^1.4.4" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.26.3", | ||
"babel-jest": "^23.6.0", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-preset-env": "^1.7.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"blob-stream": "^0.1.2", | ||
"brace": "^0.2.1", | ||
"brfs": "~2.0.1", | ||
"browserify": "^13.3.0", | ||
"codemirror": "~3.20.0", | ||
"eslint": "^5.3.0", | ||
"iconv-lite": "^0.4.13", | ||
"jade": "~1.1.5", | ||
"jest": "^23.4.2", | ||
"markdown": "~0.5.0", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.52.2", | ||
"rollup-plugin-babel": "^2.7.1", | ||
"rollup-plugin-babel": "3", | ||
"rollup-plugin-bundle-size": "https://github.com/vimeo/rollup-plugin-bundle-size", | ||
"rollup-plugin-cpy": "^1.0.0", | ||
"rollup-plugin-ignore": "^1.0.3", | ||
@@ -47,3 +61,18 @@ "rollup-plugin-json": "^2.1.0", | ||
"rollup-plugin-uglify": "^3.0.0" | ||
}, | ||
"dependencies": { | ||
"@react-pdf/fontkit": "^1.11.0", | ||
"@react-pdf/png-js": "^1.0.0", | ||
"crypto-js": "^3.1.9-1", | ||
"linebreak": "^0.3.0", | ||
"lz-string": "^1.4.4", | ||
"saslprep": "1.0.1" | ||
}, | ||
"jest": { | ||
"testPathIgnorePatterns": [ | ||
"/node_modules/", | ||
"<rootDir>/demo/" | ||
], | ||
"testURL": "http://localhost/" | ||
} | ||
} |
113
README.md
@@ -5,9 +5,7 @@ # PDFKit | ||
[![](https://img.shields.io/gratipay/devongovett.svg)](https://gratipay.com/devongovett) | ||
## Description | ||
PDFKit is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable documents easy. | ||
It's written in CoffeeScript, but you can choose to use the API in plain 'ol JavaScript if you like. The API embraces | ||
chainability, and includes both low level functions as well as abstractions for higher level functionality. The PDFKit API | ||
PDFKit is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable documents easy. | ||
It's written in CoffeeScript, but you can choose to use the API in plain 'ol JavaScript if you like. The API embraces | ||
chainability, and includes both low level functions as well as abstractions for higher level functionality. The PDFKit API | ||
is designed to be simple, so generating complex documents is often as simple as a few function calls. | ||
@@ -52,30 +50,32 @@ | ||
* etc. | ||
* Outlines | ||
* PDF security | ||
* Encryption | ||
* Access privileges (printing, copying, modifying, annotating, form filling, content accessibility, document assembly) | ||
## Coming soon! | ||
* Patterns fills | ||
* Outlines | ||
* PDF Security | ||
* Higher level APIs for creating tables and laying out content | ||
* More performance optimizations | ||
* Even more awesomeness, perhaps written by you! Please fork this repository and send me pull requests. | ||
## Example | ||
```coffeescript | ||
PDFDocument = require 'pdfkit' | ||
```javascript | ||
const PDFDocument = require('pdfkit'); | ||
# Create a document | ||
doc = new PDFDocument | ||
// Create a document | ||
const doc = new PDFDocument; | ||
# Pipe its output somewhere, like to a file or HTTP response | ||
# See below for browser usage | ||
doc.pipe fs.createWriteStream('output.pdf') | ||
// Pipe its output somewhere, like to a file or HTTP response | ||
// See below for browser usage | ||
doc.pipe(fs.createWriteStream('output.pdf')); | ||
# Embed a font, set the font size, and render some text | ||
// Embed a font, set the font size, and render some text | ||
doc.font('fonts/PalatinoBold.ttf') | ||
.fontSize(25) | ||
.text('Some text with an embedded font!', 100, 100) | ||
.text('Some text with an embedded font!', 100, 100); | ||
# Add an image, constrain it to a given size, and center it vertically and horizontally | ||
// Add an image, constrain it to a given size, and center it vertically and horizontally | ||
doc.image('path/to/image.png', { | ||
@@ -87,8 +87,8 @@ fit: [250, 300], | ||
# Add another page | ||
// Add another page | ||
doc.addPage() | ||
.fontSize(25) | ||
.text('Here is some vector graphics...', 100, 100) | ||
.text('Here is some vector graphics...', 100, 100); | ||
# Draw a triangle | ||
// Draw a triangle | ||
doc.save() | ||
@@ -98,5 +98,5 @@ .moveTo(100, 150) | ||
.lineTo(200, 250) | ||
.fill("#FF3300") | ||
.fill("#FF3300"); | ||
# Apply some transforms and render an SVG path with the 'even-odd' fill rule | ||
// Apply some transforms and render an SVG path with the 'even-odd' fill rule | ||
doc.scale(0.6) | ||
@@ -106,17 +106,17 @@ .translate(470, -380) | ||
.fill('red', 'even-odd') | ||
.restore() | ||
.restore(); | ||
# Add some text with annotations | ||
// Add some text with annotations | ||
doc.addPage() | ||
.fillColor("blue") | ||
.text('Here is a link!', 100, 100) | ||
.underline(100, 100, 160, 27, color: "#0000FF") | ||
.link(100, 100, 160, 27, 'http://google.com/') | ||
.underline(100, 100, 160, 27, {color: "#0000FF"}) | ||
.link(100, 100, 160, 27, 'http://google.com/'); | ||
# Finalize PDF file | ||
doc.end() | ||
// Finalize PDF file | ||
doc.end(); | ||
``` | ||
[The PDF output from this example](http://pdfkit.org/demo/out.pdf) (with a few additions) shows the power of PDFKit — producing | ||
complex documents with a very small amount of code. For more, see the `demo` folder and the | ||
[The PDF output from this example](http://pdfkit.org/demo/out.pdf) (with a few additions) shows the power of PDFKit — producing | ||
complex documents with a very small amount of code. For more, see the `demo` folder and the | ||
[PDFKit programming guide](http://pdfkit.org/docs/getting_started.html). | ||
@@ -130,33 +130,34 @@ | ||
In addition to PDFKit, you'll need somewhere to stream the output to. HTML5 has a | ||
In addition to PDFKit, you'll need somewhere to stream the output to. HTML5 has a | ||
[Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) object which can be used to store binary data, and | ||
get URLs to this data in order to display PDF output inside an iframe, or upload to a server, etc. In order to | ||
get URLs to this data in order to display PDF output inside an iframe, or upload to a server, etc. In order to | ||
get a Blob from the output of PDFKit, you can use the [blob-stream](https://github.com/devongovett/blob-stream) | ||
module. | ||
The following example uses Browserify to load `PDFKit` and `blob-stream`, but if you're not using Browserify, | ||
The following example uses Browserify to load `PDFKit` and `blob-stream`, but if you're not using Browserify, | ||
you can load them in whatever way you'd like (e.g. script tags). | ||
```coffeescript | ||
# require dependencies | ||
PDFDocument = require 'pdfkit' | ||
blobStream = require 'blob-stream' | ||
```javascript | ||
// require dependencies | ||
const PDFDocument = require('pdfkit'); | ||
const blobStream = require('blob-stream'); | ||
# create a document the same way as above | ||
doc = new PDFDocument | ||
// create a document the same way as above | ||
const doc = new PDFDocument; | ||
# pipe the document to a blob | ||
stream = doc.pipe(blobStream()) | ||
// pipe the document to a blob | ||
const stream = doc.pipe(blobStream()); | ||
# add your content to the document here, as usual | ||
// add your content to the document here, as usual | ||
# get a blob when you're done | ||
doc.end() | ||
stream.on 'finish', -> | ||
# get a blob you can do whatever you like with | ||
blob = stream.toBlob('application/pdf') | ||
// get a blob when you're done | ||
doc.end(); | ||
stream.on('finish', function() { | ||
// get a blob you can do whatever you like with | ||
const blob = stream.toBlob('application/pdf'); | ||
# or get a blob URL for display in the browser | ||
url = stream.toBlobURL('application/pdf') | ||
iframe.src = url | ||
// or get a blob URL for display in the browser | ||
const url = stream.toBlobURL('application/pdf'); | ||
iframe.src = url; | ||
}); | ||
``` | ||
@@ -166,5 +167,5 @@ | ||
Note that in order to Browserify a project using PDFKit, you need to install the `brfs` module with npm, | ||
which is used to load built-in font data into the package. It is listed as a `devDependency` in | ||
PDFKit's `package.json`, so it isn't installed by default for Node users. | ||
Note that in order to Browserify a project using PDFKit, you need to install the `brfs` module with npm, | ||
which is used to load built-in font data into the package. It is listed as a `devDependency` in | ||
PDFKit's `package.json`, so it isn't installed by default for Node users. | ||
If you forget to install it, Browserify will print an error message. | ||
@@ -171,0 +172,0 @@ |
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 too big to display
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 too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
2169585
23362
173
6
26
1
+ Addedcrypto-js@^3.1.9-1
+ Addedlinebreak@^0.3.0
+ Addedsaslprep@1.0.1
+ Addedacorn@7.4.1(transitive)
+ Addedbase64-js@0.0.8(transitive)
+ Addedbrfs@1.6.1(transitive)
+ Addedbuffer-equal@0.0.1(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedconvert-source-map@1.9.0(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcrypto-js@3.3.0(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addedduplexer2@0.1.4(transitive)
+ Addedescodegen@1.9.12.1.0(transitive)
+ Addedesprima@3.1.34.0.1(transitive)
+ Addedestraverse@4.3.05.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfalafel@2.2.5(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedhas@1.0.4(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-core-module@2.13.1(transitive)
+ Addedisarray@1.0.02.0.5(transitive)
+ Addedlevn@0.3.0(transitive)
+ Addedlinebreak@0.3.0(transitive)
+ Addedmagic-string@0.22.5(transitive)
+ Addedmerge-source-map@1.0.4(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedobject-inspect@1.4.1(transitive)
+ Addedoptionator@0.8.3(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedprelude-ls@1.1.2(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedquote-stream@1.0.2(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsaslprep@1.0.1(transitive)
+ Addedshallow-copy@0.0.1(transitive)
+ Addedsource-map@0.5.70.6.1(transitive)
+ Addedstatic-eval@2.1.1(transitive)
+ Addedstatic-module@2.2.5(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedthrough2@2.0.5(transitive)
+ Addedtype-check@0.3.2(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedvlq@0.2.3(transitive)
+ Addedword-wrap@1.2.5(transitive)
+ Addedxtend@4.0.2(transitive)