Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.15.0 #1505

Merged
merged 7 commits into from
Mar 24, 2024
Merged

v0.15.0 #1505

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"modules": false,
"targets": {
"node": "6.10"
"node": "18"
}
}
]
Expand All @@ -17,11 +17,11 @@
"@babel/preset-env",
{
"targets": {
"node": "6.10"
"node": "18"
}
}
]
]
}
}
}
}
25 changes: 12 additions & 13 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [18.x, 20.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
- 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

### Unreleased

### [v0.15.0] - 2024-03-23

- Add subset for PDF/UA
- Fix for line breaks in list items (#1486)
- Fix for soft hyphen not being replaced by visible hyphen if necessary (#457)
- Optimize output files by ignoring identity transforms
- Fix for Acroforms - setting an option to false will still apply the flag (#1495)
- Fix for text extraction in PDFium-based viewers due to invalid ToUnicodeMap (#1498)
- Remove deprecated `write` method
- Drop support for Node.js < 18 and for browsers released before 2020

### [v0.14.0] - 2023-11-09

Expand Down
2 changes: 1 addition & 1 deletion examples/kitchen-sink.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var PDFDocument = require('../js/pdfkit');
var PDFDocument = require('../');
var tiger = require('./tiger');
var fs = require('fs');

Expand Down
19 changes: 3 additions & 16 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ By Devon Govett
*/

import stream from 'stream';
import fs from 'fs';
import PDFObject from './object';
import PDFReference from './reference';
import PDFPage from './page';
Expand Down Expand Up @@ -220,7 +219,9 @@ class PDFDocument extends stream.Readable {
addNamedEmbeddedFile(name, ref) {
if (!this._root.data.Names.data.EmbeddedFiles) {
// disabling /Limits for this tree fixes attachments not showing in Adobe Reader
this._root.data.Names.data.EmbeddedFiles = new PDFNameTree({ limits: false });
this._root.data.Names.data.EmbeddedFiles = new PDFNameTree({
limits: false
});
}

// add filespec to EmbeddedFiles
Expand Down Expand Up @@ -270,20 +271,6 @@ class PDFDocument extends stream.Readable {
}
}

write(filename, fn) {
// print a deprecation warning with a stacktrace
const err = new Error(`\
PDFDocument#write is deprecated, and will be removed in a future version of PDFKit. \
Please pipe the document into a Node stream.\
`);

console.warn(err.stack);

this.pipe(fs.createWriteStream(filename));
this.end();
return this.once('end', fn);
}

end() {
this.flushPages();

Expand Down
96 changes: 47 additions & 49 deletions lib/mixins/pdfa.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
import fs from 'fs';

export default {

initPDFA(pSubset) {
if (pSubset.charAt(pSubset.length - 3) === '-') {
this.subset_conformance = pSubset.charAt(pSubset.length - 1).toUpperCase();
this.subset = parseInt(pSubset.charAt(pSubset.length - 2));
} else {
// Default to Basic conformance when user doesn't specify
this.subset_conformance = 'B';
this.subset = parseInt(pSubset.charAt(pSubset.length - 1));
}
},

endSubset() {
this._addPdfaMetadata();
const jsPath = `${__dirname}/data/sRGB_IEC61966_2_1.icc`
const jestPath = `${__dirname}/../color_profiles/sRGB_IEC61966_2_1.icc`
this._addColorOutputIntent(fs.existsSync(jsPath) ? jsPath : jestPath);
},

_addColorOutputIntent(pICCPath) {
const iccProfile = fs.readFileSync(pICCPath);

const colorProfileRef = this.ref({
Length: iccProfile.length,
N: 3
});
colorProfileRef.write(iccProfile);
colorProfileRef.end();

const intentRef = this.ref({
Type: 'OutputIntent',
S: 'GTS_PDFA1',
Info: new String('sRGB IEC61966-2.1'),
OutputConditionIdentifier: new String('sRGB IEC61966-2.1'),
DestOutputProfile: colorProfileRef,
});
intentRef.end();

this._root.data.OutputIntents = [intentRef];
},

_getPdfaid() {
return `
initPDFA(pSubset) {
if (pSubset.charAt(pSubset.length - 3) === '-') {
this.subset_conformance = pSubset
.charAt(pSubset.length - 1)
.toUpperCase();
this.subset = parseInt(pSubset.charAt(pSubset.length - 2));
} else {
// Default to Basic conformance when user doesn't specify
this.subset_conformance = 'B';
this.subset = parseInt(pSubset.charAt(pSubset.length - 1));
}
},

endSubset() {
this._addPdfaMetadata();
this._addColorOutputIntent(`${__dirname}/data/sRGB_IEC61966_2_1.icc`);
},

_addColorOutputIntent(pICCPath) {
const iccProfile = fs.readFileSync(pICCPath);

const colorProfileRef = this.ref({
Length: iccProfile.length,
N: 3
});
colorProfileRef.write(iccProfile);
colorProfileRef.end();

const intentRef = this.ref({
Type: 'OutputIntent',
S: 'GTS_PDFA1',
Info: new String('sRGB IEC61966-2.1'),
OutputConditionIdentifier: new String('sRGB IEC61966-2.1'),
DestOutputProfile: colorProfileRef
});
intentRef.end();

this._root.data.OutputIntents = [intentRef];
},

_getPdfaid() {
return `
<rdf:Description xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/" rdf:about="">
<pdfaid:part>${this.subset}</pdfaid:part>
<pdfaid:conformance>${this.subset_conformance}</pdfaid:conformance>
</rdf:Description>
`;
},

_addPdfaMetadata() {
this.appendXML(this._getPdfaid());
},
},

}
_addPdfaMetadata() {
this.appendXML(this._getPdfaid());
}
};
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"document",
"vector"
],
"version": "0.14.0",
"version": "0.15.0",
"homepage": "http://pdfkit.org/",
"author": {
"name": "Devon Govett",
Expand Down Expand Up @@ -56,7 +56,8 @@
},
"scripts": {
"prepublishOnly": "npm run build",
"build": "rollup -c && browserify --standalone PDFDocument --ignore crypto --ignore iconv-lite js/pdfkit.js > js/pdfkit.standalone.js",
"build": "rollup -c && npm run build-standalone",
"build-standalone": "browserify --standalone PDFDocument --ignore crypto --ignore iconv-lite js/pdfkit.js > js/pdfkit.standalone.js",
"browserify-example": "browserify examples/browserify/browser.js > examples/browserify/bundle.js",
"pdf-guide": "node docs/generate.js",
"website": "node docs/generate_website.js",
Expand All @@ -69,15 +70,14 @@
"test:unit": "jest unit/"
},
"main": "js/pdfkit.js",
"module": "js/pdfkit.es5.js",
"esnext": "js/pdfkit.esnext.js",
"module": "js/pdfkit.es.js",
"browserify": {
"transform": [
"brfs"
]
},
"engine": [
"node >= v6.0.0"
"node >= v18.0.0"
],
"jest": {
"testEnvironment": "jest-environment-jsdom",
Expand All @@ -89,4 +89,4 @@
"<rootDir>/tests/unit/setupTests.js"
]
}
}
}
54 changes: 13 additions & 41 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ const external = [
'png-js',
'crypto-js',
'saslprep',
'jpeg-exif',
'jpeg-exif'
];

const supportedBrowsers = [
'Firefox 102', // ESR from 2022
'iOS 14', // from 2020
'Safari 14' // from 2020
];

export default [
Expand All @@ -36,53 +42,25 @@ export default [
{
modules: false,
targets: {
node: '6.10'
node: '18'
}
}
]
]
}),
copy({
files: ['lib/font/data/*.afm', 'lib/color_profiles/*.icc'],
files: ['lib/font/data/*.afm', 'lib/mixins/data/*.icc'],
dest: 'js/data'
})
]
},
// ES for legacy (IE11) browsers
{
input: 'lib/document.js',
external,
output: {
name: 'pdfkit.es5',
file: pkg.module,
format: 'es',
sourcemap: true
},
plugins: [
babel({
babelrc: false,
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
browsers: ['ie 11']
},
exclude: ['@babel/plugin-transform-typeof-symbol']
}
]
]
})
]
},
// ES for green browsers
{
input: 'lib/document.js',
external,
output: {
name: 'pdfkit.esnext',
file: pkg.esnext,
name: 'pdfkit.es',
file: pkg.module,
format: 'es',
sourcemap: true
},
Expand All @@ -95,13 +73,7 @@ export default [
{
modules: false,
targets: {
browsers: [
'Firefox 57',
'Edge 15',
'Chrome 60',
'iOS 10',
'Safari 10'
]
browsers: supportedBrowsers
}
}
]
Expand All @@ -128,7 +100,7 @@ export default [
loose: true,
modules: false,
targets: {
browsers: ['ie 11']
browsers: supportedBrowsers
}
}
]
Expand Down