Skip to content

Commit

Permalink
Merge branch 'master' into features/node-section
Browse files Browse the repository at this point in the history
  • Loading branch information
liborm85 committed Jan 3, 2025
2 parents ebf51db + feb4afe commit db47d61
Show file tree
Hide file tree
Showing 45 changed files with 41,586 additions and 48,593 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

## Unreleased

- Fixed URL resolving for same URL in browser
- Fixed sharing URL resolver for not available URLs

## 0.3.0-beta.15 - 2025-01-01

- Reverted to the original `pdfkit` package, moving away from `@foliojs-fork`
- Update pdfkit to 0.16.0
- Fixed a potential issue in the minimized library when detecting the orientation of JPEG images

## 0.3.0-beta.14 - 2024-12-23

- Fixed big size pdfmake bundle for browser

## 0.3.0-beta.13 - 2024-12-15

- Update pdfkit to 0.15.2
- Fixed speed in Node.js if is fetching URL for image or font redirected
- Fixed aspect ratio for image with exif orientation tag
- Fixed font size calculation for watermark if is page orientation is changed
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The MIT License (MIT)

Copyright (c) 2014-2015 bpampuch
2016-2024 liborm85
2016-2025 liborm85

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
89,996 changes: 41,491 additions & 48,505 deletions build/pdfmake.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/pdfmake.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/pdfmake.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/pdfmake.min.js.map

Large diffs are not rendered by default.

Binary file modified examples/pdfs/absolute.pdf
Binary file not shown.
Binary file modified examples/pdfs/attachments.pdf
Binary file not shown.
Binary file modified examples/pdfs/background.pdf
Binary file not shown.
Binary file modified examples/pdfs/basics.pdf
Binary file not shown.
Binary file modified examples/pdfs/columns_simple.pdf
Binary file not shown.
Binary file modified examples/pdfs/images.pdf
Binary file not shown.
Binary file modified examples/pdfs/links.pdf
Binary file not shown.
Binary file modified examples/pdfs/lists.pdf
Binary file not shown.
Binary file modified examples/pdfs/margins.pdf
Binary file not shown.
Binary file modified examples/pdfs/named_styles.pdf
Binary file not shown.
Binary file modified examples/pdfs/named_styles_with_overrides.pdf
Binary file not shown.
Binary file modified examples/pdfs/pageReference.pdf
Binary file not shown.
Binary file modified examples/pdfs/pdfa.pdf
Binary file not shown.
Binary file modified examples/pdfs/qrCode.pdf
Binary file not shown.
Binary file modified examples/pdfs/relative.pdf
Binary file not shown.
Binary file modified examples/pdfs/security.pdf
Binary file not shown.
Binary file modified examples/pdfs/standardfonts.pdf
Binary file not shown.
Binary file modified examples/pdfs/styling_inlines.pdf
Binary file not shown.
Binary file modified examples/pdfs/styling_properties.pdf
Binary file not shown.
Binary file modified examples/pdfs/svgs.pdf
Binary file not shown.
Binary file modified examples/pdfs/tables.pdf
Binary file not shown.
Binary file modified examples/pdfs/textDecorations.pdf
Binary file not shown.
Binary file modified examples/pdfs/toc.pdf
Binary file not shown.
Binary file modified examples/pdfs/vectors.pdf
Binary file not shown.
Binary file modified examples/pdfs/watermark.pdf
Binary file not shown.
29 changes: 14 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pdfmake",
"version": "0.3.0-beta.12",
"version": "0.3.0-beta.15",
"description": "Client/server side PDF printing in pure JavaScript",
"main": "js/index.js",
"esnext": "src/index.js",
Expand All @@ -9,29 +9,28 @@
"test": "tests"
},
"dependencies": {
"@foliojs-fork/linebreak": "^1.1.2",
"@foliojs-fork/pdfkit": "^0.15.1",
"iconv-lite": "^0.6.3",
"linebreak": "^1.1.0",
"pdfkit": "^0.16.0",
"xmldoc": "^1.3.0"
},
"devDependencies": {
"@babel/cli": "^7.25.9",
"@babel/cli": "^7.26.4",
"@babel/core": "^7.26.0",
"@babel/plugin-transform-modules-commonjs": "^7.25.9",
"@babel/plugin-transform-modules-commonjs": "^7.26.3",
"@babel/preset-env": "^7.26.0",
"@eslint/js": "^9.14.0",
"@eslint/js": "^9.17.0",
"assert": "^2.1.0",
"babel-loader": "^9.2.1",
"brfs": "^2.0.2",
"browserify-zlib": "^0.2.0",
"buffer": "6.0.3",
"core-js": "3.19.0",
"eslint": "^9.14.0",
"eslint-plugin-jsdoc": "^50.4.3",
"core-js": "3.39.0",
"eslint": "^9.17.0",
"eslint-plugin-jsdoc": "^50.6.1",
"expose-loader": "^5.0.0",
"file-saver": "^2.0.5",
"globals": "^15.11.0",
"mocha": "^10.8.2",
"globals": "^15.14.0",
"mocha": "^11.0.1",
"npm-run-all": "^4.1.5",
"process": "^0.11.10",
"rewire": "^7.0.0",
Expand All @@ -41,11 +40,11 @@
"stream-browserify": "^3.0.0",
"string-replace-webpack-plugin": "^0.1.3",
"svg-to-pdfkit": "^0.1.8",
"terser-webpack-plugin": "^5.3.10",
"terser-webpack-plugin": "^5.3.11",
"transform-loader": "^0.2.4",
"util": "^0.12.5",
"webpack": "^5.96.1",
"webpack-cli": "^5.1.4"
"webpack": "^5.97.1",
"webpack-cli": "^6.0.1"
},
"engines": {
"node": ">=18"
Expand Down
8 changes: 3 additions & 5 deletions src/DocMeasure.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,9 @@ class DocMeasure {

let imageSize = { width: image.width, height: image.height };

if (image.constructor.name === 'JPEG') {
// If EXIF orientation calls for it, swap width and height
if (image.orientation > 4) {
imageSize = { width: image.height, height: image.width };
}
// If EXIF orientation calls for it, swap width and height
if (image.orientation > 4) {
imageSize = { width: image.height, height: image.width };
}

this.measureImageWithDimensions(node, imageSize);
Expand Down
2 changes: 1 addition & 1 deletion src/PDFDocument.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PDFKit from '@foliojs-fork/pdfkit';
import PDFKit from 'pdfkit';

const typeName = (bold, italics) => {
let type = 'normal';
Expand Down
2 changes: 1 addition & 1 deletion src/TextBreaker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import LineBreaker from '@foliojs-fork/linebreak';
import LineBreaker from 'linebreak';
import { isObject } from './helpers/variableType';
import StyleContextStack from './StyleContextStack';

Expand Down
2 changes: 1 addition & 1 deletion src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class pdfmake {
options.progressCallback = this.progressCallback;
options.tableLayouts = this.tableLayouts;

let printer = new Printer(this.fonts, this.virtualfs, this.urlResolver);
let printer = new Printer(this.fonts, this.virtualfs, this.urlResolver());
const pdfDocumentPromise = printer.createPdfKitDocument(docDefinition, options);

return this._transformToDocument(pdfDocumentPromise);
Expand Down
15 changes: 10 additions & 5 deletions src/browser-extensions/URLBrowserResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,17 @@ class URLBrowserResolver {
if (!this.resolving[url]) {
this.resolving[url] = new Promise((resolve, reject) => {
if (url.toLowerCase().indexOf('https://') === 0 || url.toLowerCase().indexOf('http://') === 0) {
fetchUrl(url, headers).then(buffer => {
this.fs.writeFileSync(url, buffer);
if (this.fs.existsSync(url)) {
// url was downloaded earlier
resolve();
}, result => {
reject(result);
});
} else {
fetchUrl(url, headers).then(buffer => {
this.fs.writeFileSync(url, buffer);
resolve();
}, result => {
reject(result);
});
}
} else {
// cannot be resolved
resolve();
Expand Down
2 changes: 1 addition & 1 deletion src/browser-extensions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let defaultClientFonts = {
class pdfmake extends pdfmakeBase {
constructor() {
super();
this.urlResolver = new URLBrowserResolver(this.virtualfs);
this.urlResolver = () => new URLBrowserResolver(this.virtualfs);
this.fonts = defaultClientFonts;
}

Expand Down
8 changes: 4 additions & 4 deletions src/browser-extensions/standard-fonts/Courier.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ var fs = require('fs');

var fontContainer = {
vfs: {
'data/Courier.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Courier.afm', 'utf8'), encoding: 'utf8' },
'data/Courier-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Courier-Bold.afm', 'utf8'), encoding: 'utf8' },
'data/Courier-Oblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Courier-Oblique.afm', 'utf8'), encoding: 'utf8' },
'data/Courier-BoldOblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Courier-BoldOblique.afm', 'utf8'), encoding: 'utf8' }
'data/Courier.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier.afm', 'utf8'), encoding: 'utf8' },
'data/Courier-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier-Bold.afm', 'utf8'), encoding: 'utf8' },
'data/Courier-Oblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier-Oblique.afm', 'utf8'), encoding: 'utf8' },
'data/Courier-BoldOblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier-BoldOblique.afm', 'utf8'), encoding: 'utf8' }
},
fonts: {
Courier: {
Expand Down
8 changes: 4 additions & 4 deletions src/browser-extensions/standard-fonts/Helvetica.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ var fs = require('fs');

var fontContainer = {
vfs: {
'data/Helvetica.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Helvetica.afm', 'utf8'), encoding: 'utf8' },
'data/Helvetica-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Helvetica-Bold.afm', 'utf8'), encoding: 'utf8' },
'data/Helvetica-Oblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Helvetica-Oblique.afm', 'utf8'), encoding: 'utf8' },
'data/Helvetica-BoldOblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Helvetica-BoldOblique.afm', 'utf8'), encoding: 'utf8' }
'data/Helvetica.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica.afm', 'utf8'), encoding: 'utf8' },
'data/Helvetica-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica-Bold.afm', 'utf8'), encoding: 'utf8' },
'data/Helvetica-Oblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica-Oblique.afm', 'utf8'), encoding: 'utf8' },
'data/Helvetica-BoldOblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica-BoldOblique.afm', 'utf8'), encoding: 'utf8' }
},
fonts: {
Helvetica: {
Expand Down
2 changes: 1 addition & 1 deletion src/browser-extensions/standard-fonts/Symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var fs = require('fs');

var fontContainer = {
vfs: {
'data/Symbol.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Symbol.afm', 'utf8'), encoding: 'utf8' }
'data/Symbol.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Symbol.afm', 'utf8'), encoding: 'utf8' }
},
fonts: {
Symbol: {
Expand Down
8 changes: 4 additions & 4 deletions src/browser-extensions/standard-fonts/Times.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ var fs = require('fs');

var fontContainer = {
vfs: {
'data/Times-Roman.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Times-Roman.afm', 'utf8'), encoding: 'utf8' },
'data/Times-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Times-Bold.afm', 'utf8'), encoding: 'utf8' },
'data/Times-Italic.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Times-Italic.afm', 'utf8'), encoding: 'utf8' },
'data/Times-BoldItalic.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Times-BoldItalic.afm', 'utf8'), encoding: 'utf8' }
'data/Times-Roman.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Times-Roman.afm', 'utf8'), encoding: 'utf8' },
'data/Times-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Times-Bold.afm', 'utf8'), encoding: 'utf8' },
'data/Times-Italic.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Times-Italic.afm', 'utf8'), encoding: 'utf8' },
'data/Times-BoldItalic.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Times-BoldItalic.afm', 'utf8'), encoding: 'utf8' }
},
fonts: {
Times: {
Expand Down
2 changes: 1 addition & 1 deletion src/browser-extensions/standard-fonts/ZapfDingbats.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var fs = require('fs');

var fontContainer = {
vfs: {
'data/ZapfDingbats.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/ZapfDingbats.afm', 'utf8'), encoding: 'utf8' }
'data/ZapfDingbats.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/ZapfDingbats.afm', 'utf8'), encoding: 'utf8' }
},
fonts: {
ZapfDingbats: {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const URLResolver = require('./URLResolver').default;
class pdfmake extends pdfmakeBase {
constructor() {
super();
this.urlResolver = new URLResolver(this.virtualfs);
this.urlResolver = () => new URLResolver(this.virtualfs);
}

_transformToDocument(doc) {
Expand Down
67 changes: 28 additions & 39 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
var path = require('path');
var fs = require('fs');
var TerserPlugin = require('terser-webpack-plugin');
var StringReplacePlugin = require("string-replace-webpack-plugin");
var webpack = require('webpack');
var pkg = require('./package.json');

var banner = '/*! ' + pkg.name + ' v' + pkg.version + ', @license ' + pkg.license + ', @link ' + pkg.homepage + ' */';

var supportedBrowsers = {
"chrome": "109",
"edge": "109",
"firefox": "102",
"safari": "14"
};

module.exports = {
mode: 'production',
entry: {
Expand All @@ -19,7 +27,6 @@ module.exports = {
// Workaround https://github.com/webpack/webpack/issues/6642 until https://github.com/webpack/webpack/issues/6525 lands.
globalObject: `typeof self !== 'undefined' ? self : this`
},
target: ['web', 'es5'], // For Internet Explorer 11 support
resolve: {
alias: {
fs: path.join(__dirname, './src/browser-extensions/virtual-fs-cjs.js')
Expand All @@ -46,12 +53,7 @@ module.exports = {
[
"@babel/preset-env",
{
targets: {
"chrome": "109",
"edge": "109",
"firefox": "102",
"safari": "14"
},
targets: supportedBrowsers,
modules: false,
useBuiltIns: 'usage',
// TODO: after fix in babel remove corejs version and remove core-js dependency in package.json
Expand Down Expand Up @@ -80,6 +82,24 @@ module.exports = {
})
}
},
// transpile to inline only required file
{
enforce: 'pre',
test: /pdfkit[/\\]js[/\\]/,
use: {
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: "fs.readFileSync(`${__dirname}/data/sRGB_IEC61966_2_1.icc`)",
replacement: function () {
const data = fs.readFileSync('node_modules/pdfkit/js/data/sRGB_IEC61966_2_1.icc');
return `Buffer("` + data.toString('base64') + `","base64");`;
}
}
]
})
}
},
{
enforce: "pre",
test: /\.(cjs|js)$/,
Expand All @@ -95,9 +115,7 @@ module.exports = {
[
"@babel/preset-env",
{
targets: {
"ie": "11"
},
targets: supportedBrowsers,
modules: false,
useBuiltIns: 'usage',
// TODO: after fix in babel remove corejs version and remove core-js dependency in package.json
Expand Down Expand Up @@ -137,35 +155,6 @@ module.exports = {
})
}
},

{
enforce: 'post',
test: /pdfkit[/\\]js[/\\]pdfkit.es.js$/,
use: {
loader: "transform-loader?brfs"
}
},
{
enforce: 'post',
test: /fontkit[/\\]index.js$/,
use: {
loader: "transform-loader?brfs"
}
},
{
enforce: 'post',
test: /unicode-properties[/\\]index.js$/,
use: {
loader: "transform-loader?brfs"
}
},
{
enforce: 'post',
test: /linebreak[/\\]src[/\\]linebreaker.js/,
use: {
loader: "transform-loader?brfs"
}
}
]
},
optimization: {
Expand Down

0 comments on commit db47d61

Please sign in to comment.