Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ coverage
package-lock.json
/examples/browserify/bundle.js
index.html
/.yarn/install-state.gz
942 changes: 942 additions & 0 deletions .yarn/releases/yarn-4.10.3.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
yarnPath: .yarn/releases/yarn-4.10.3.cjs

nodeLinker: node-modules
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ 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.
Use [npm](http://npmjs.org/) or [yarn](https://yarnpkg.com/) package manager. Just type the following command:

npm install pdfkit
```bash
# with npm
npm install pdfkit

# with yarn
yarn add pdfkit
```

## Features

Expand All @@ -40,6 +46,7 @@ Installation uses the [npm](http://npmjs.org/) package manager. Just type the fo
- 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)
- Tables
- Annotations
- Links
- Notes
Expand All @@ -56,7 +63,7 @@ Installation uses the [npm](http://npmjs.org/) package manager. Just type the fo
## Coming soon!

- Patterns fills
- Higher level APIs for creating tables and laying out content
- Higher level APIs for laying out content
- More performance optimizations
- Even more awesomeness, perhaps written by you! Please fork this repository and send me pull requests.

Expand Down Expand Up @@ -168,7 +175,7 @@ stream.on('finish', function() {

You can see an interactive in-browser demo of PDFKit [here](http://pdfkit.org/demo/browser.html).

Note that in order to Browserify a project using PDFKit, you need to install the `brfs` module with npm,
Note that in order to Browserify a project using PDFKit, you need to install the `brfs` module,
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.
Expand Down
20 changes: 20 additions & 0 deletions examples/png.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const PDFDocument = require('..');
const fs = require('fs');

const doc = new PDFDocument();

doc.pipe(fs.createWriteStream('png.pdf'));

// Set the background color to highlight the transparency
doc.fillColor('lightblue');
doc.rect(0, 0, doc.page.width, doc.page.height).fill();

doc.fillColor('black');

doc.text('PNG with transparency (palette 8bit):', 60, 50);
doc.image('../tests/images/pngsuite-palette-transparent-white.png', 60, 64);

doc.text('PNG with transparency (palette 1bit):', 60, 100);
doc.image('../tests/images/pallete-transparent-white-1bit.png', 60, 114);

doc.end();
Binary file added examples/png.pdf
Binary file not shown.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"brace": "^0.11.1",
"brfs": "~2.0.2",
"browserify": "^17.0.1",
"canvas": "^3.1.0",
"canvas": "^3.2.0",
"codemirror": "~5.65.18",
"eslint": "^9.17.0",
"gh-pages": "^6.2.0",
Expand Down Expand Up @@ -88,5 +88,6 @@
"setupFilesAfterEnv": [
"<rootDir>/tests/unit/setupTests.js"
]
}
},
"packageManager": "yarn@4.10.3"
}
Binary file added tests/images/pallete-transparent-white-1bit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 49 additions & 1 deletion tests/unit/png.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ describe('PNGImage', () => {
});
});

test('Pallete indexed transparency', () => {
test('Pallete indexed transparency 8bit', () => {
// ImageWidth = 32
// ImageHeight = 32
// BitDepth = 8
Expand Down Expand Up @@ -260,6 +260,54 @@ describe('PNGImage', () => {
});
});

test('Pallete indexed transparency 1bit', () => {
// ImageWidth = 290
// ImageHeight = 50
// BitDepth = 1
// ColorType = 3
// Compression = 0
// Filter = 0
// Interlace = 0

const img = createImage(
'./tests/images/pallete-transparent-white-1bit.png',
);

expect(img.finalize).toBeCalledTimes(1);

expect(img.obj.data).toMatchObject({
BitsPerComponent: 1,
ColorSpace: ['Indexed', 'DeviceRGB', 1, expect.any(PDFReference)],
Filter: 'FlateDecode',
Height: 50,
Length: 64,
Subtype: 'Image',
Type: 'XObject',
Width: 290,
DecodeParms: expect.any(PDFReference),
SMask: expect.any(PDFReference),
});

expect(img.obj.data.DecodeParms.data).toMatchObject({
BitsPerComponent: 1,
Colors: 1,
Columns: 290,
Predictor: 15,
});

expect(img.obj.data.SMask.data).toMatchObject({
BitsPerComponent: 8, // ????
ColorSpace: 'DeviceGray',
Decode: [0, 1],
Filter: 'FlateDecode',
Height: 50,
Length: 16,
Subtype: 'Image',
Type: 'XObject',
Width: 290,
});
});

test('Grayscale', () => {
// ImageWidth = 428
// ImageHeight = 320
Expand Down
Loading
Loading