Skip to content

Commit

Permalink
Merge tag 'v0.12.1'
Browse files Browse the repository at this point in the history
* tag 'v0.12.1': (100 commits)
  Remove package-lock.json
  Reorganize and cleanup examples
  Add interactive browser demo files to publish website script
  update ignored files in npm
  update lock files
  add 0.12.1 from npm release
  Fix for PDF accessibility check. (foliojs#1265)
  Add option to define AcroForm fontSize. Fixes foliojs#1088
  Allow applying 'underline' and 'strike' text styling together on a text (foliojs#1253)
  fix(demo): debounces the preview to avoid window crash
  Update CHANGELOG.md
  Improve website publish script
  Add script to automate publishing website into gh-pages branch
  v0.12
  Fix source code link in website template
  Handle headers with inline code in generate_website script
  Fix/add forms to docs (foliojs#1173)
  Use crypto-js instead of crypto in attachments
  rename fileAttachmentAnnotation to fileAnnotation
  add support for embedded files and file attachment annotations
  ...
  • Loading branch information
moses committed Jul 13, 2021
2 parents 39dcb2e + 8f70c33 commit 4ddd507
Show file tree
Hide file tree
Showing 191 changed files with 99,102 additions and 2,721 deletions.
20 changes: 19 additions & 1 deletion .eslintrc
@@ -1,3 +1,21 @@
{
"extends": "eslint:recommended"
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 11,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true
},
"overrides": [
{
"files": [
"tests/**/*.js"
],
"env": {
"jest": true
}
}
]
}
29 changes: 29 additions & 0 deletions .github/workflows/lint-test.yml
@@ -0,0 +1,29 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Lint and Test

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Run ESLint
run: npm run lint
- name: Run tests
run: npm test
6 changes: 1 addition & 5 deletions .gitignore
Expand Up @@ -6,10 +6,6 @@ src/
playground/
build/
js/
demo/bundle.js
*.html
!demo/browser.html
.vscode
coverage
tests/integration/__pdfs__
tests/integration/pdfmake/__pdfs__
package-lock.json
3 changes: 2 additions & 1 deletion .npmignore
@@ -1,5 +1,6 @@
.github/
.prettierrc
.prettierignore
.babelrc
node-zlib/
node-modules/
Expand All @@ -16,4 +17,4 @@ index.js
index.html
yarn.lock
rollup.config.js
.eslintrc
.eslintrc
1 change: 1 addition & 0 deletions .prettierignore
@@ -0,0 +1 @@
demo/bundle.js
34 changes: 31 additions & 3 deletions CHANGELOG.md
@@ -1,8 +1,36 @@
## pdfkit changelog

### Unreleased
- Fix infinite loop when text is positioned after page right margin
- Allow links in continued text to be stopped by setting link to null

- Allow applying 'underline' and 'strike' text styling together on a text
- Allow to specify the AcroForm text fontSize

### [v0.12.1] - 2021-04-10

- Update crypto-js to v3.3 (fix security issue)
- Update fontkit to 1.8.1

### [v0.12.0] - 2021-04-04

- Add support for Embedded Files and File Attachment Annotations
- Accessibility support
- Replace integration tests by visual regression tests
- Fix access permissions in PDF version 1.7ext3
- Fix Buffer() is deprecation warning
- Add `forms.md` to generate documentation files
- Fix "@" in FontName

### [v0.11.0] - 2019-12-03

- Fix infinite loop when an individual character is bigger than the width of the text.
- Fix infinite loop when text is positioned after page right margin
- Allow links in continued text to be stopped by setting link to null
- Add support to interlaced PNG files
- Do not emit \_interopDefault helper in commonjs build
- Fix gradient with multiple stops (#1045)
- Set link annotation flag to print by default
- Add support for AcroForms
- Drop support for (uncommon) cid less fonts on standalone build (reduces bundle size)

### [v0.10.0] - 2019-06-06

Expand All @@ -21,7 +49,7 @@
- Add standalone virtual file system implementation
- Add option (fontLayoutCache) to disable font layout cache

### [v0.9.0] - 2019-1-28
### [v0.9.0] - 2019-01-28

- Convert to code base from coffescript to ES6+
- Fix loading grayscale / transparent PNG files
Expand Down
27 changes: 18 additions & 9 deletions CONTRIBUTING.md
Expand Up @@ -19,7 +19,7 @@ pdfkit is organized in the following folders:
- `docs`: Code and artifacts to generate documentation.
- `demo`: Node and browser demos.
- `tests/unit`: Tests behavior of specific classes / methods.
- `tests/integration`: Compare the pdf output against a reference.
- `tests/visual`: Compare the pdf output against a reference.

**Working on your first Pull Request?** You can learn how from this _free_ series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github)

Expand All @@ -40,7 +40,7 @@ To install the project you need to have `node`
2. `npm install` to install dependencies
3. `npm run build` to build the library
4. `npm run demo` to run the demo (check demo/out.pdf)
5. `npm run demo-browser` to run the browser demo (check demo/browser.html)
5. `npm run browser-demo` to run the browser demo (check demo/browser.html)

> Tip: Keep your `master` branch pointing at the original repository and make
> pull requests from branches on your fork. To do this, run:
Expand All @@ -60,24 +60,33 @@ To install the project you need to have `node`
## Running and writing tests

Tests are run using [Jest](http://jestjs.io/) and are categorized as integration and unit tests.
Tests are run using [Jest](http://jestjs.io/) and are categorized as unit and visual tests.

Integration tests check the pdf output against a reference stored as snapshots. While is served well to avoid regressions it has some disadvantages like small (correct) changes requiring to update all snapshots
Visual tests check the pdf image screenshot against a reference stored as snapshots.

Unit tests checks behavior os specific classes / methods isolatedly. It covers relatively small portion of code but is preferred way of writing new tests going forward
Unit tests check behavior of specific classes / methods isolatedly.

Tests commands
Test commands
* `npm run test`: Run all tests
* `npm run test:unit`: Run unit tests
* `npm run test:integration`: Run integration tests
* `npm run test:visual`: Run visual tests
* `npm run lint`: Run linter

To write new tests, look for the *.spec.js files at `test/unit` and `test/integration` as examples
To write new tests, look for the *.spec.js files at `test/unit` and `test/visual` as examples

> Visual tests should use an embedded font, instead of system fonts, to ensure uniform rendering between different environments
## Documentation

See `README.md` in the `docs` subdirectory for more information.

## Submitting a Pull Request

Please go through existing issues and pull requests to check if somebody else is already working on it.

Also, make sure to run the tests and lint the code before you commit your changes.

**Preferentially, tests should be added to check the changed behavior even if is a bug fix. Unit tests are preferred over integration ones**
> Tests should be added to check the changed behavior even if is a bug fix.
If the proposed change affects document structure a unit test should be added, if affects rendering, add a visual test

139 changes: 73 additions & 66 deletions README.md
Expand Up @@ -4,9 +4,9 @@ A JavaScript PDF generation library for Node and the browser.

## Description

PDFKit is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable
documents easy. 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
PDFKit is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable
documents easy. 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.

Check out some of the [documentation and examples](http://pdfkit.org/docs/getting_started.html) to see for yourself!
Expand All @@ -18,45 +18,47 @@ You can also try out an interactive in-browser demo of PDFKit [here](http://pdfk

## Installation

Installation uses the [npm](http://npmjs.org/) package manager. Just type the following command after installing npm.
Installation uses the [npm](http://npmjs.org/) package manager. Just type the following command after installing npm.

npm install pdfkit

## Features

* Vector graphics
* HTML5 canvas-like API
* Path operations
* SVG path parser for easy path creation
* Transformations
* Linear and radial gradients
* Text
* Line wrapping
* Text alignments
* Bulleted lists
* Font embedding
* Supports TrueType (.ttf), OpenType (.otf), WOFF, WOFF2, TrueType Collections (.ttc), and Datafork TrueType (.dfont) fonts
* Font subsetting
* See [fontkit](http://github.com/foliojs/fontkit) for more details on advanced glyph layout support.
* Image embedding
* Supports JPEG and PNG files (including indexed PNGs, and PNGs with transparency)
* Annotations
* Links
* Notes
* Highlights
* Underlines
* etc.
* Outlines
* PDF security
* Encryption
* Access privileges (printing, copying, modifying, annotating, form filling, content accessibility, document assembly)
- Vector graphics
- HTML5 canvas-like API
- Path operations
- SVG path parser for easy path creation
- Transformations
- Linear and radial gradients
- Text
- Line wrapping
- Text alignments
- Bulleted lists
- Font embedding
- Supports TrueType (.ttf), OpenType (.otf), WOFF, WOFF2, TrueType Collections (.ttc), and Datafork TrueType (.dfont) fonts
- Font subsetting
- See [fontkit](http://github.com/foliojs/fontkit) for more details on advanced glyph layout support.
- Image embedding
- Supports JPEG and PNG files (including indexed PNGs, and PNGs with transparency)
- Annotations
- Links
- Notes
- Highlights
- Underlines
- etc.
- AcroForms
- Outlines
- PDF security
- Encryption
- Access privileges (printing, copying, modifying, annotating, form filling, content accessibility, document assembly)
- Accessibility support (marked content, logical structure, Tagged PDF, PDF/UA)

## Coming soon!

* Patterns fills
* 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.
- Patterns fills
- 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

Expand All @@ -72,72 +74,77 @@ const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('output.pdf'));

// 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);
doc
.font('fonts/PalatinoBold.ttf')
.fontSize(25)
.text('Some text with an embedded font!', 100, 100);

// Add an image, constrain it to a given size, and center it vertically and horizontally
doc.image('path/to/image.png', {
fit: [250, 300],
align: 'center',
valign: 'center'
fit: [250, 300],
align: 'center',
valign: 'center'
});

// Add another page
doc.addPage()
.fontSize(25)
.text('Here is some vector graphics...', 100, 100);
doc
.addPage()
.fontSize(25)
.text('Here is some vector graphics...', 100, 100);

// Draw a triangle
doc.save()
.moveTo(100, 150)
.lineTo(100, 250)
.lineTo(200, 250)
.fill("#FF3300");
doc
.save()
.moveTo(100, 150)
.lineTo(100, 250)
.lineTo(200, 250)
.fill('#FF3300');

// Apply some transforms and render an SVG path with the 'even-odd' fill rule
doc.scale(0.6)
.translate(470, -380)
.path('M 250,75 L 323,301 131,161 369,161 177,301 z')
.fill('red', 'even-odd')
.restore();
doc
.scale(0.6)
.translate(470, -380)
.path('M 250,75 L 323,301 131,161 369,161 177,301 z')
.fill('red', 'even-odd')
.restore();

// 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/');
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/');

// 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
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).

## Browser Usage

There are three ways to use PDFKit in the browser:
- Use [Browserify](http://browserify.org/). See demo [source code](demo/browser.js) and [build script](https://github.com/foliojs/pdfkit/blob/master/package.json#L56)
- Use [webpack](https://webpack.js.org/). See [complete example](https://github.com/blikblum/pdfkit-webpack-example).
- Use prebuilt version. Distributed as `pdfkit.standalone.js` file in the [releases](https://github.com/foliojs/pdfkit/releases) or in the package `js` folder.

- Use [Browserify](http://browserify.org/). See demo [source code](demo/browser.js) and [build script](https://github.com/foliojs/pdfkit/blob/master/package.json#L56)
- Use [webpack](https://webpack.js.org/). See [complete example](https://github.com/blikblum/pdfkit-webpack-example).
- Use prebuilt version. Distributed as `pdfkit.standalone.js` file in the [releases](https://github.com/foliojs/pdfkit/releases) or in the package `js` folder.

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 or webpack to load `PDFKit` and `blob-stream`. See [here](https://codepen.io/blikblum/pen/gJNWMg?editors=1010) and [here](https://codepen.io/blikblum/pen/YboVNq?editors=1010) for examples
of prebuilt version usage.
of prebuilt version usage.

```javascript
// require dependencies
const PDFDocument = require('pdfkit');
const blobStream = require('blob-stream');
const blobStream = require('blob-stream');

// create a document the same way as above
const doc = new PDFDocument();
Expand Down

0 comments on commit 4ddd507

Please sign in to comment.