pdf-visual-diff
Advanced tools
| /** | ||
| * Converts a size from millimeters to pixels based on the provided DPI (dots per inch). | ||
| * | ||
| * @param sizeMm - The size in millimeters. | ||
| * @param dpi - The dots per inch (DPI) for the conversion. | ||
| * @returns The size in pixels. | ||
| */ | ||
| export declare function convertFromMmToPx(sizeMm: number, dpi: number): number; | ||
| /** | ||
| * Converts a size from pixels to millimeters based on the provided DPI (dots per inch). | ||
| * | ||
| * @param sizePx - The size in pixels. | ||
| * @param dpi - The dots per inch (DPI) for the conversion. | ||
| * @returns The size in millimeters. | ||
| */ | ||
| export declare function convertFromPxToMm(sizePx: number, dpi: number): number; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.convertFromPxToMm = exports.convertFromMmToPx = void 0; | ||
| /** | ||
| * Converts a size from millimeters to pixels based on the provided DPI (dots per inch). | ||
| * | ||
| * @param sizeMm - The size in millimeters. | ||
| * @param dpi - The dots per inch (DPI) for the conversion. | ||
| * @returns The size in pixels. | ||
| */ | ||
| function convertFromMmToPx(sizeMm, dpi) { | ||
| if (sizeMm <= 0 || dpi <= 0) { | ||
| return 0; | ||
| } | ||
| const sizeInch = sizeMm / 25.4; | ||
| return Math.round(sizeInch * dpi); | ||
| } | ||
| exports.convertFromMmToPx = convertFromMmToPx; | ||
| /** | ||
| * Converts a size from pixels to millimeters based on the provided DPI (dots per inch). | ||
| * | ||
| * @param sizePx - The size in pixels. | ||
| * @param dpi - The dots per inch (DPI) for the conversion. | ||
| * @returns The size in millimeters. | ||
| */ | ||
| function convertFromPxToMm(sizePx, dpi) { | ||
| if (sizePx <= 0 || dpi <= 0) { | ||
| return 0; | ||
| } | ||
| const sizeInch = sizePx / dpi; | ||
| return Math.round(sizeInch * 25.4); | ||
| } | ||
| exports.convertFromPxToMm = convertFromPxToMm; | ||
| //# sourceMappingURL=conversions.js.map |
| {"version":3,"file":"conversions.js","sourceRoot":"","sources":["../../src/conversions/conversions.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAAC,MAAc,EAAE,GAAW;IAC3D,IAAI,MAAM,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE;QAC3B,OAAO,CAAC,CAAA;KACT;IACD,MAAM,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAA;IAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAA;AACnC,CAAC;AAND,8CAMC;AAED;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAAC,MAAc,EAAE,GAAW;IAC3D,IAAI,MAAM,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE;QAC3B,OAAO,CAAC,CAAA;KACT;IACD,MAAM,QAAQ,GAAG,MAAM,GAAG,GAAG,CAAA;IAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAA;AACpC,CAAC;AAND,8CAMC"} |
| export {}; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const chai_1 = require("chai"); | ||
| const conversions_1 = require("./conversions"); | ||
| describe('conversions', () => { | ||
| describe('convertFromMmToPx', () => { | ||
| it('should convert millimeters to pixels correctly', () => { | ||
| (0, chai_1.expect)((0, conversions_1.convertFromMmToPx)(10, 300)).to.equal(118); | ||
| (0, chai_1.expect)((0, conversions_1.convertFromMmToPx)(25.4, 300)).to.equal(300); | ||
| (0, chai_1.expect)((0, conversions_1.convertFromMmToPx)(0, 300)).to.equal(0); | ||
| (0, chai_1.expect)((0, conversions_1.convertFromMmToPx)(10, 0)).to.equal(0); | ||
| (0, chai_1.expect)((0, conversions_1.convertFromMmToPx)(-10, 300)).to.equal(0); | ||
| (0, chai_1.expect)((0, conversions_1.convertFromMmToPx)(10, -300)).to.equal(0); | ||
| }); | ||
| }); | ||
| describe('convertFromPxToMm', () => { | ||
| it('should convert pixels to millimeters correctly', () => { | ||
| (0, chai_1.expect)((0, conversions_1.convertFromPxToMm)(300, 300)).to.equal(25); | ||
| (0, chai_1.expect)((0, conversions_1.convertFromPxToMm)(118, 300)).to.equal(10); | ||
| (0, chai_1.expect)((0, conversions_1.convertFromPxToMm)(0, 300)).to.equal(0); | ||
| (0, chai_1.expect)((0, conversions_1.convertFromPxToMm)(300, 0)).to.equal(0); | ||
| (0, chai_1.expect)((0, conversions_1.convertFromPxToMm)(-300, 300)).to.equal(0); | ||
| (0, chai_1.expect)((0, conversions_1.convertFromPxToMm)(300, -300)).to.equal(0); | ||
| }); | ||
| }); | ||
| }); | ||
| //# sourceMappingURL=conversions.spec.js.map |
| {"version":3,"file":"conversions.spec.js","sourceRoot":"","sources":["../../src/conversions/conversions.spec.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,+CAAoE;AAEpE,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;QACjC,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;YACxD,IAAA,aAAM,EAAC,IAAA,+BAAiB,EAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAChD,IAAA,aAAM,EAAC,IAAA,+BAAiB,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAClD,IAAA,aAAM,EAAC,IAAA,+BAAiB,EAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YAC7C,IAAA,aAAM,EAAC,IAAA,+BAAiB,EAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YAC5C,IAAA,aAAM,EAAC,IAAA,+BAAiB,EAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YAC/C,IAAA,aAAM,EAAC,IAAA,+BAAiB,EAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QACjD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;QACjC,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;YACxD,IAAA,aAAM,EAAC,IAAA,+BAAiB,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;YAChD,IAAA,aAAM,EAAC,IAAA,+BAAiB,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;YAChD,IAAA,aAAM,EAAC,IAAA,+BAAiB,EAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YAC7C,IAAA,aAAM,EAAC,IAAA,+BAAiB,EAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YAC7C,IAAA,aAAM,EAAC,IAAA,+BAAiB,EAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YAChD,IAAA,aAAM,EAAC,IAAA,+BAAiB,EAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAClD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} |
| export { convertFromMmToPx, convertFromPxToMm } from './conversions'; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.convertFromPxToMm = exports.convertFromMmToPx = void 0; | ||
| var conversions_1 = require("./conversions"); | ||
| Object.defineProperty(exports, "convertFromMmToPx", { enumerable: true, get: function () { return conversions_1.convertFromMmToPx; } }); | ||
| Object.defineProperty(exports, "convertFromPxToMm", { enumerable: true, get: function () { return conversions_1.convertFromPxToMm; } }); | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/conversions/index.ts"],"names":[],"mappings":";;;AAAA,6CAAoE;AAA3D,gHAAA,iBAAiB,OAAA;AAAE,gHAAA,iBAAiB,OAAA"} |
| export { mergeImages } from './mergeImages'; | ||
| export { writeImages } from './writeImages'; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.writeImages = exports.mergeImages = void 0; | ||
| var mergeImages_1 = require("./mergeImages"); | ||
| Object.defineProperty(exports, "mergeImages", { enumerable: true, get: function () { return mergeImages_1.mergeImages; } }); | ||
| var writeImages_1 = require("./writeImages"); | ||
| Object.defineProperty(exports, "writeImages", { enumerable: true, get: function () { return writeImages_1.writeImages; } }); | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/imageUtils/index.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAAlC,0GAAA,WAAW,OAAA;AACpB,6CAA2C;AAAlC,0GAAA,WAAW,OAAA"} |
| import Jimp from 'jimp'; | ||
| /** | ||
| * Merges an array of Jimp images into a single image. | ||
| * | ||
| * @param images - An array of Jimp images to be merged. | ||
| * @returns A Jimp image that is the result of merging all input images. | ||
| */ | ||
| export declare function mergeImages(images: ReadonlyArray<Jimp>): Jimp; |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.mergeImages = void 0; | ||
| const jimp_1 = __importDefault(require("jimp")); | ||
| /** | ||
| * Merges an array of Jimp images into a single image. | ||
| * | ||
| * @param images - An array of Jimp images to be merged. | ||
| * @returns A Jimp image that is the result of merging all input images. | ||
| */ | ||
| function mergeImages(images) { | ||
| let imgHeight = 0; | ||
| const imgData = images.map((img) => { | ||
| const res = { img, y: imgHeight }; | ||
| imgHeight += img.bitmap.height; | ||
| return res; | ||
| }); | ||
| const imgWidth = Math.max(...imgData.map(({ img }) => img.bitmap.width)); | ||
| const baseImage = new jimp_1.default(imgWidth, imgHeight, 0x00000000); | ||
| imgData.forEach(({ img, y }) => baseImage.composite(img, 0, y)); | ||
| return baseImage; | ||
| } | ||
| exports.mergeImages = mergeImages; | ||
| //# sourceMappingURL=mergeImages.js.map |
| {"version":3,"file":"mergeImages.js","sourceRoot":"","sources":["../../src/imageUtils/mergeImages.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AAOvB;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,MAA2B;IACrD,IAAI,SAAS,GAAG,CAAC,CAAA;IACjB,MAAM,OAAO,GAAc,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAC5C,MAAM,GAAG,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,SAAS,EAAE,CAAA;QACjC,SAAS,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAA;QAC9B,OAAO,GAAG,CAAA;IACZ,CAAC,CAAC,CAAA;IAEF,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IACxE,MAAM,SAAS,GAAG,IAAI,cAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;IAE3D,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAE/D,OAAO,SAAS,CAAA;AAClB,CAAC;AAdD,kCAcC"} |
| import Jimp from 'jimp'; | ||
| /** | ||
| * Writes images to the specified output path. | ||
| * | ||
| * @returns A function that takes an array of Jimp images and returns a promise that resolves to void. | ||
| */ | ||
| export declare const writeImages: (outputImagePath: string, combinePages?: boolean) => (images: ReadonlyArray<Jimp>) => Promise<void>; |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.writeImages = void 0; | ||
| const path_1 = __importDefault(require("path")); | ||
| const mergeImages_1 = require("./mergeImages"); | ||
| /** | ||
| * Writes images to the specified output path. | ||
| * | ||
| * @returns A function that takes an array of Jimp images and returns a promise that resolves to void. | ||
| */ | ||
| const writeImages = ( | ||
| /** The path where the images will be saved. */ | ||
| outputImagePath, | ||
| /** | ||
| * Whether to combine all images into a single image. | ||
| * @defaultValue true | ||
| */ | ||
| combinePages = true) => (images) => { | ||
| if (combinePages === true) { | ||
| return (0, mergeImages_1.mergeImages)(images) | ||
| .writeAsync(outputImagePath) | ||
| .then(() => undefined); | ||
| } | ||
| const parsedPath = path_1.default.parse(outputImagePath); | ||
| const partialName = path_1.default.join(parsedPath.dir, parsedPath.name); | ||
| const padMaxLen = images.length.toString().length; | ||
| return Promise.all(images.map((img, idx) => img.writeAsync(`${partialName}_${String(idx + 1).padStart(padMaxLen, '0')}.png`))).then(() => undefined); | ||
| }; | ||
| exports.writeImages = writeImages; | ||
| //# sourceMappingURL=writeImages.js.map |
| {"version":3,"file":"writeImages.js","sourceRoot":"","sources":["../../src/imageUtils/writeImages.ts"],"names":[],"mappings":";;;;;;AACA,gDAAuB;AACvB,+CAA2C;AAE3C;;;;GAIG;AACI,MAAM,WAAW,GACtB;AACE,+CAA+C;AAC/C,eAAuB;AACvB;;;GAGG;AACH,YAAY,GAAG,IAAI,EACnB,EAAE,CACJ,CAAC,MAA2B,EAAiB,EAAE;IAC7C,IAAI,YAAY,KAAK,IAAI,EAAE;QACzB,OAAO,IAAA,yBAAW,EAAC,MAAM,CAAC;aACvB,UAAU,CAAC,eAAe,CAAC;aAC3B,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;KACzB;IAED,MAAM,UAAU,GAAG,cAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;IAC9C,MAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,CAAC,CAAA;IAC9D,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAA;IACjD,OAAO,OAAO,CAAC,GAAG,CAChB,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CACtB,GAAG,CAAC,UAAU,CAAC,GAAG,WAAW,IAAI,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,CACjF,CACF,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;AACzB,CAAC,CAAA;AAzBU,QAAA,WAAW,eAyBrB"} |
| export { pdf2png } from './pdf2png'; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.pdf2png = void 0; | ||
| var pdf2png_1 = require("./pdf2png"); | ||
| Object.defineProperty(exports, "pdf2png", { enumerable: true, get: function () { return pdf2png_1.pdf2png; } }); | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pdf2png/index.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AAA1B,kGAAA,OAAO,OAAA"} |
| import * as Canvas from 'canvas'; | ||
| export type CanvasAndContext = { | ||
| canvas: Canvas.Canvas; | ||
| context: Canvas.CanvasRenderingContext2D; | ||
| }; | ||
| export declare class NodeCanvasFactory { | ||
| create(width: number, height: number): CanvasAndContext; | ||
| reset(canvasAndContext: CanvasAndContext, width: number, height: number): void; | ||
| destroy(canvasAndContext: CanvasAndContext): void; | ||
| } |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.NodeCanvasFactory = void 0; | ||
| const Canvas = __importStar(require("canvas")); | ||
| const assert = __importStar(require("assert")); | ||
| class NodeCanvasFactory { | ||
| create(width, height) { | ||
| assert.ok(width > 0 && height > 0, 'Invalid canvas size'); | ||
| const canvas = Canvas.createCanvas(width, height); | ||
| const context = canvas.getContext('2d'); | ||
| return { | ||
| canvas, | ||
| context, | ||
| }; | ||
| } | ||
| reset(canvasAndContext, width, height) { | ||
| assert.ok(canvasAndContext.canvas, 'Canvas is not specified'); | ||
| assert.ok(width > 0 && height > 0, 'Invalid canvas size'); | ||
| canvasAndContext.canvas.width = width; | ||
| canvasAndContext.canvas.height = height; | ||
| } | ||
| destroy(canvasAndContext) { | ||
| assert.ok(canvasAndContext.canvas, 'Canvas is not specified'); | ||
| canvasAndContext.canvas.width = 0; | ||
| canvasAndContext.canvas.height = 0; | ||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore | ||
| canvasAndContext.canvas = null; | ||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore | ||
| canvasAndContext.context = null; | ||
| } | ||
| } | ||
| exports.NodeCanvasFactory = NodeCanvasFactory; | ||
| //# sourceMappingURL=nodeCanvasFactory.js.map |
| {"version":3,"file":"nodeCanvasFactory.js","sourceRoot":"","sources":["../../src/pdf2png/nodeCanvasFactory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,+CAAgC;AAOhC,MAAa,iBAAiB;IAC5B,MAAM,CAAC,KAAa,EAAE,MAAc;QAClC,MAAM,CAAC,EAAE,CAAC,KAAK,GAAG,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,qBAAqB,CAAC,CAAA;QACzD,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QACjD,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QACvC,OAAO;YACL,MAAM;YACN,OAAO;SACR,CAAA;IACH,CAAC;IAED,KAAK,CAAC,gBAAkC,EAAE,KAAa,EAAE,MAAc;QACrE,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAA;QAC7D,MAAM,CAAC,EAAE,CAAC,KAAK,GAAG,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,qBAAqB,CAAC,CAAA;QACzD,gBAAgB,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAA;QACrC,gBAAgB,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAA;IACzC,CAAC;IAED,OAAO,CAAC,gBAAkC;QACxC,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAA;QAC7D,gBAAgB,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAA;QACjC,gBAAgB,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAA;QAClC,6DAA6D;QAC7D,aAAa;QACb,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAA;QAC9B,6DAA6D;QAC7D,aAAa;QACb,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAA;IACjC,CAAC;CACF;AA7BD,8CA6BC"} |
| /// <reference types="node" /> | ||
| import Jimp from 'jimp'; | ||
| import { PdfToPngOptions } from '../types'; | ||
| export declare function pdf2png(pdf: string | Buffer, options?: PdfToPngOptions): Promise<ReadonlyArray<Jimp>>; |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.pdf2png = void 0; | ||
| const fs = __importStar(require("fs")); | ||
| const path = __importStar(require("path")); | ||
| const pdfjsLib = __importStar(require("pdfjs-dist/legacy/build/pdf")); | ||
| const jimp_1 = require("jimp"); | ||
| const types_1 = require("../types"); | ||
| const conversions_1 = require("../conversions"); | ||
| const nodeCanvasFactory_1 = require("./nodeCanvasFactory"); | ||
| // pdfjs location | ||
| const PDFJS_DIR = path.dirname(require.resolve('pdfjs-dist')); | ||
| // Some PDFs need external cmaps. | ||
| const CMAP_URL = path.join(PDFJS_DIR, '../cmaps/'); | ||
| const CMAP_PACKED = true; | ||
| // Where the standard fonts are located. | ||
| const STANDARD_FONT_DATA_URL = path.join(PDFJS_DIR, '../standard_fonts/'); | ||
| const pdf2PngDefOpts = { | ||
| dpi: types_1.Dpi.High, | ||
| }; | ||
| const PDF_DPI = 72; | ||
| function getPageViewPort(page, dpi) { | ||
| const dpiNum = dpi === types_1.Dpi.Low ? PDF_DPI : dpi === types_1.Dpi.High ? 144 : dpi; | ||
| const viewport = page.getViewport({ scale: 1.0 }); | ||
| if (dpiNum === PDF_DPI) { | ||
| return viewport; | ||
| } | ||
| // Increase resolution | ||
| const horizontalMm = (0, conversions_1.convertFromPxToMm)(viewport.width, PDF_DPI); | ||
| const verticalMm = (0, conversions_1.convertFromPxToMm)(viewport.height, PDF_DPI); | ||
| const actualWidth = (0, conversions_1.convertFromMmToPx)(horizontalMm, dpiNum); | ||
| const actualHeight = (0, conversions_1.convertFromMmToPx)(verticalMm, dpiNum); | ||
| const scale = Math.min(actualWidth / viewport.width, actualHeight / viewport.height); | ||
| return page.getViewport({ scale }); | ||
| } | ||
| async function pdf2png(pdf, options = {}) { | ||
| const opts = Object.assign(Object.assign({}, pdf2PngDefOpts), options); | ||
| // Load PDF | ||
| const data = new Uint8Array(Buffer.isBuffer(pdf) ? pdf : fs.readFileSync(pdf)); | ||
| const loadingTask = pdfjsLib.getDocument({ | ||
| data, | ||
| cMapUrl: CMAP_URL, | ||
| cMapPacked: CMAP_PACKED, | ||
| standardFontDataUrl: STANDARD_FONT_DATA_URL, | ||
| }); | ||
| const pdfDocument = await loadingTask.promise; | ||
| const numPages = pdfDocument.numPages; | ||
| const canvasFactory = new nodeCanvasFactory_1.NodeCanvasFactory(); | ||
| const canvasAndContext = canvasFactory.create(1, 1); | ||
| // Generate images | ||
| const images = []; | ||
| for (let idx = 1; idx <= numPages; idx += 1) { | ||
| const page = await pdfDocument.getPage(idx); | ||
| const viewport = getPageViewPort(page, opts.dpi); | ||
| canvasFactory.reset(canvasAndContext, viewport.width, viewport.height); | ||
| // TODO: fix types | ||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore | ||
| await page.render({ canvasContext: canvasAndContext.context, viewport }).promise; | ||
| page.cleanup(); | ||
| const image = canvasAndContext.canvas.toBuffer('image/png'); | ||
| images.push(image); | ||
| } | ||
| return Promise.all(images.map((x) => (0, jimp_1.read)(x))); | ||
| } | ||
| exports.pdf2png = pdf2png; | ||
| //# sourceMappingURL=pdf2png.js.map |
| {"version":3,"file":"pdf2png.js","sourceRoot":"","sources":["../../src/pdf2png/pdf2png.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAwB;AACxB,2CAA4B;AAC5B,sEAAuD;AACvD,+BAAiC;AACjC,oCAA+C;AAC/C,gDAAqE;AACrE,2DAAuD;AAEvD,iBAAiB;AACjB,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAA;AAE7D,iCAAiC;AACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;AAClD,MAAM,WAAW,GAAG,IAAI,CAAA;AAExB,wCAAwC;AACxC,MAAM,sBAAsB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAA;AAEzE,MAAM,cAAc,GAA8B;IAChD,GAAG,EAAE,WAAG,CAAC,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AAC,CAAC,EAAE,EAAE,CAAC,IAAA,WAAI,EAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAChD,CAAC;AAxCD,0BAwCC"} |
| export {}; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const path_1 = require("path"); | ||
| const pdf2png_1 = require("./pdf2png"); | ||
| const compare_images_1 = require("../compare-images"); | ||
| const chai_1 = require("chai"); | ||
| const types_1 = require("../types"); | ||
| const testDataDir = (0, path_1.join)(__dirname, '../test-data'); | ||
| const pdfs = (0, path_1.join)(testDataDir, 'pdfs'); | ||
| const singlePage = (0, path_1.join)(pdfs, 'single-page.pdf'); | ||
| const twoPage = (0, path_1.join)(pdfs, 'two-page.pdf'); | ||
| const cmaps = (0, path_1.join)(pdfs, 'cmaps.pdf'); | ||
| const expectedDir = (0, path_1.join)(testDataDir, 'pdf2png-expected'); | ||
| describe('pdf2png()', () => { | ||
| it('two-page.pdf png per page with scaling', () => { | ||
| const expectedImage1Path = (0, path_1.join)(expectedDir, 'two-page_png_per_page_scaled_1.png'); | ||
| const expectedImage2Path = (0, path_1.join)(expectedDir, 'two-page_png_per_page_scaled_2.png'); | ||
| return (0, pdf2png_1.pdf2png)(twoPage, { dpi: types_1.Dpi.High }) | ||
| .then((imgs) => Promise.all([ | ||
| (0, compare_images_1.compareImages)(expectedImage1Path, [imgs[0]]), | ||
| (0, compare_images_1.compareImages)(expectedImage2Path, [imgs[1]]), | ||
| ])) | ||
| .then((results) => { | ||
| results.forEach((x) => (0, chai_1.expect)(x.equal).to.be.true); | ||
| }); | ||
| }); | ||
| it('two-page.pdf png per page and without scaling', () => { | ||
| const expectedImage1Path = (0, path_1.join)(expectedDir, 'two-page_png_per_page_1.png'); | ||
| const expectedImage2Path = (0, path_1.join)(expectedDir, 'two-page_png_per_page_2.png'); | ||
| return (0, pdf2png_1.pdf2png)(twoPage, { dpi: types_1.Dpi.Low }) | ||
| .then((imgs) => Promise.all([ | ||
| (0, compare_images_1.compareImages)(expectedImage1Path, [imgs[0]]), | ||
| (0, compare_images_1.compareImages)(expectedImage2Path, [imgs[1]]), | ||
| ])) | ||
| .then((results) => { | ||
| results.forEach((x) => (0, chai_1.expect)(x.equal).to.be.true); | ||
| }); | ||
| }); | ||
| it('should scale using custom DPI', () => { | ||
| const expectedImagePath = (0, path_1.join)(expectedDir, 'should_scale_using_custom_DPI.png'); | ||
| return (0, pdf2png_1.pdf2png)(singlePage, { dpi: 200 }) | ||
| .then((imgs) => (0, compare_images_1.compareImages)(expectedImagePath, imgs)) | ||
| .then((result) => (0, chai_1.expect)(result.equal).to.be.true); | ||
| }); | ||
| it('pdf that requires cmaps', () => { | ||
| const expectedImagePath = (0, path_1.join)(expectedDir, 'cmaps.png'); | ||
| return (0, pdf2png_1.pdf2png)(cmaps) | ||
| .then((imgs) => (0, compare_images_1.compareImages)(expectedImagePath, imgs)) | ||
| .then((result) => (0, chai_1.expect)(result.equal).to.be.true); | ||
| }); | ||
| }); | ||
| //# sourceMappingURL=pdf2png.spec.js.map |
| {"version":3,"file":"pdf2png.spec.js","sourceRoot":"","sources":["../../src/pdf2png/pdf2png.spec.ts"],"names":[],"mappings":";;AAAA,+BAA2B;AAC3B,uCAAmC;AACnC,sDAAiD;AACjD,+BAA6B;AAC7B,oCAA8B;AAE9B,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,cAAc,CAAC,CAAA;AACnD,MAAM,IAAI,GAAG,IAAA,WAAI,EAAC,WAAW,EAAE,MAAM,CAAC,CAAA;AACtC,MAAM,UAAU,GAAG,IAAA,WAAI,EAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;AAChD,MAAM,OAAO,GAAG,IAAA,WAAI,EAAC,IAAI,EAAE,cAAc,CAAC,CAAA;AAC1C,MAAM,KAAK,GAAG,IAAA,WAAI,EAAC,IAAI,EAAE,WAAW,CAAC,CAAA;AAErC,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,WAAW,EAAE,kBAAkB,CAAC,C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,CAAC,CAAA;IACtD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} |
| /** | ||
| * Enum representing predefined DPI (Dots Per Inch) values. | ||
| */ | ||
| export declare enum Dpi { | ||
| Low = 72, | ||
| High = 144 | ||
| } | ||
| /** | ||
| * Configuration options for converting a PDF to PNG format. | ||
| */ | ||
| export type PdfToPngOptions = { | ||
| /** | ||
| * The DPI value used to calculate image resolution. | ||
| * | ||
| * @remarks | ||
| * - Use `Dpi.Low` for the default PDF viewport size at 72 DPI. This option generates an image with lower resolution, resulting in lesser quality but faster processing time. At this setting, one PDF point corresponds to one pixel. | ||
| * - Use `Dpi.High` for twice the default PDF viewport size at 144 DPI. This option provides better image quality at the cost of longer processing time. At this setting, one PDF point corresponds to two pixels. | ||
| * - You can also provide a custom DPI value as a number. | ||
| * | ||
| * @defaultValue Dpi.High | ||
| */ | ||
| dpi?: Dpi | number; | ||
| }; |
+12
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Dpi = void 0; | ||
| /** | ||
| * Enum representing predefined DPI (Dots Per Inch) values. | ||
| */ | ||
| var Dpi; | ||
| (function (Dpi) { | ||
| Dpi[Dpi["Low"] = 72] = "Low"; | ||
| Dpi[Dpi["High"] = 144] = "High"; | ||
| })(Dpi = exports.Dpi || (exports.Dpi = {})); | ||
| //# sourceMappingURL=types.js.map |
| {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,GAGX;AAHD,WAAY,GAAG;IACb,4BAAQ,CAAA;IACR,+BAAU,CAAA;AACZ,CAAC,EAHW,GAAG,GAAH,WAAG,KAAH,WAAG,QAGd"} |
| import Jimp from 'jimp'; | ||
| export declare const mkDiffPath: (path: string) => string; | ||
| export type HighlightColor = 'Red' | 'Green' | 'Blue' | 'White' | 'Cyan' | 'Magenta' | 'Yellow' | 'Black' | 'Gray'; | ||
| /** The options type for {@link compareImages}. */ | ||
| export type CompareImagesOpts = { | ||
| tolerance: number; | ||
| tolerance?: number; | ||
| }; | ||
@@ -18,3 +18,3 @@ type CompareOK = { | ||
| type CompareImagesResult = CompareOK | CompareKO; | ||
| export declare const compareImages: (expectedImagePath: string, images: ReadonlyArray<Jimp>, compareImagesOpts?: Partial<CompareImagesOpts>) => Promise<CompareImagesResult>; | ||
| export declare const compareImages: (expectedImagePath: string, images: ReadonlyArray<Jimp>, options?: CompareImagesOpts) => Promise<CompareImagesResult>; | ||
| export {}; |
@@ -28,3 +28,3 @@ "use strict"; | ||
| const jimp_1 = __importStar(require("jimp")); | ||
| const merge_images_1 = require("./merge-images"); | ||
| const imageUtils_1 = require("./imageUtils"); | ||
| const diffToken = '.diff'; | ||
@@ -41,7 +41,7 @@ const mkDiffPath = (path) => { | ||
| }; | ||
| const compareImages = async (expectedImagePath, images, compareImagesOpts = {}) => { | ||
| const { tolerance } = Object.assign(Object.assign({}, defaultOpts), compareImagesOpts); | ||
| const compareImages = async (expectedImagePath, images, options) => { | ||
| const { tolerance } = Object.assign(Object.assign({}, defaultOpts), options); | ||
| const expectedImg = await (0, jimp_1.read)(expectedImagePath); | ||
| // Multi image comparison not implemented! | ||
| const img = (0, merge_images_1.mergeImages)(images); | ||
| const img = (0, imageUtils_1.mergeImages)(images); | ||
| const diff = jimp_1.default.diff(expectedImg, img, tolerance); | ||
@@ -48,0 +48,0 @@ if (diff.percent > 0) { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"compare-images.js","sourceRoot":"","sources":["../src/compare-images.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAiC;AACjC,iDAA4C;AAE5C,MAAM,SAAS,GAAG,OAAO,CAAA;AAClB,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE;IACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IACtC,OAAO,QAAQ,KAAK,CAAC,CAAC;QACpB,CAAC,CAAC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AAQ,KAAK,CAAC,CAAC;QACpB,CAAC,CAAC,IAAI,GAAG,SAAS;QAClB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;AACxE,CAAC,CAAA;AALY,QAAA,UAAU,cAKtB;AAOD,MAAM,WAAW,GAAgC;IAC/C,SAAS,EAAE,CAAC;CACb,CAAA;AAgBM,MAAM,aAAa,GAAG,KAAK,EAChC,iBAAyB,EACzB,MAA2B,EAC3B,OAA2B,EACG,EAAE;IAChC,MAAM,EAAE,SAAS,EAAE,mCACd,WAAW,GACX,OAAO,CACX,CAAA;IACD,MAAM,WAAW,GAAG,MAAM,IAAA,WAAI,EAAC,iBAAiB,CAAC,CAAA;IACjD,0CAA0C;IAC1C,MAAM,GAAG,GAAG,IAAA,wBAAW,EAAC,MAAM,CAAC,CAAA;IAC/B,MAAM,IAAI,GAAG,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,SAAS,CAAC,CAAA;IACnD,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,EAAE;QACpB,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;SACvC,CAAA;KACF;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AACxB,CAAC,CAAA;AArBY,QAAA,aAAa,iBAqBzB"} |
| /// <reference types="node" /> | ||
| import { CompareImagesOpts, HighlightColor } from './compare-images'; | ||
| import { PdfToPngOptions } from './types'; | ||
| /** | ||
| * Represents the available colors for highlighting. | ||
| */ | ||
| export type HighlightColor = 'Red' | 'Green' | 'Blue' | 'White' | 'Cyan' | 'Magenta' | 'Yellow' | 'Black' | 'Gray'; | ||
| /** | ||
| * Represents a rectangular mask applied at the PNG level, i.e., after the | ||
| * conversion of the PDF to an image. | ||
| * | ||
| * @remarks | ||
| * The values provided for `x`, `y`, `width`, and `height` are expected to be in | ||
| * pixels and based on the generated image by the library. | ||
| * The origin (0,0) of the PNG's coordinate system is the top-left corner of the | ||
| * image. | ||
| */ | ||
| export type RectangleMask = Readonly<{ | ||
| type: 'rectangle-mask'; | ||
| /** The x-coordinate of the top-left corner of the rectangle in pixels. */ | ||
| x: number; | ||
| /** The y-coordinate of the top-left corner of the rectangle in pixels. */ | ||
| y: number; | ||
| /** The width of the rectangle in pixels. */ | ||
| width: number; | ||
| /** The height of the rectangle in pixels. */ | ||
| height: number; | ||
| /** The color used for the mask. */ | ||
| color: HighlightColor; | ||
| }>; | ||
| export type RegionMask = RectangleMask; | ||
| /** | ||
| * Defines a function for masking predefined regions per page, useful for | ||
| * parts of the PDF that change between tests. | ||
| * | ||
| * @param page - The page number of the PDF. | ||
| * @returns An array of region masks for the specified page, or undefined if no masks are defined. | ||
| */ | ||
| export type MaskRegions = (page: number) => ReadonlyArray<RegionMask> | undefined; | ||
| export type CompareOptions = CompareImagesOpts & { | ||
| maskRegions: MaskRegions; | ||
| /** | ||
| * The options type for {@link comparePdfToSnapshot}. | ||
| * | ||
| * @privateRemarks | ||
| * Explicitly not using `Partial`. It doesn't play nice with TypeDoc. | ||
| * Instead of showing the type name in the docs a Partial with all the | ||
| * fields is inlined. | ||
| */ | ||
| export type CompareOptions = { | ||
| /** | ||
| * Number value for error tolerance in the range [0, 1]. | ||
| * | ||
| * @defaultValue 0 | ||
| */ | ||
| tolerance?: number; | ||
| /** {@inheritDoc MaskRegions} */ | ||
| maskRegions?: MaskRegions; | ||
| /** {@inheritDoc PdfToPngOptions} */ | ||
| pdf2PngOptions?: PdfToPngOptions; | ||
| }; | ||
| export declare const snapshotsDirName = "__snapshots__"; | ||
| /** | ||
| * Compare pdf to persisted snapshot. If one does not exist it is created | ||
| * @param pdf - path to pdf file or pdf loaded as Buffer | ||
| * @param snapshotDir - path to a directory where __snapshots__ folder is going to be created | ||
| * @param snapshotName - uniq name of a snapshot in the above path | ||
| * @param compareOptions - image comparison options | ||
| * @param compareOptions.tolerance - number value for error tolerance, ranges 0-1 (default: 0) | ||
| * @param compareOptions.maskRegions - `(page: number) => ReadonlyArray<RegionMask> | undefined` mask predefined regions per page, i.e. when there are parts of the pdf that change between tests | ||
| * Compares a PDF to a persisted snapshot. If a snapshot does not exists, one is | ||
| * created. | ||
| * | ||
| * @remarks | ||
| * When the function is executed, it has following **side effects**: | ||
| * - If a previous snapshot file does not exist, the PDF is converted to an | ||
| * image, saved as a snapshot, and the function returns `true`. | ||
| * - If a snapshot exists, the PDF is converted to an image and compared to the | ||
| * snapshot: | ||
| * - If they differ, the function returns `false` and creates two additional | ||
| * images next to the snapshot: one with the suffix `new` (the current view | ||
| * of the PDF as an image) and one with the suffix `diff` (showing the | ||
| * difference between the snapshot and the `new` image). | ||
| * - If they are equal, the function returns `true`. If `new` and `diff` | ||
| * versions are present, they are deleted. | ||
| * | ||
| * @returns | ||
| * A promise that resolves to `true` if the PDF matches the snapshot or | ||
| * if a new snapshot is created, and `false` if the PDF differs from the snapshot. | ||
| */ | ||
| export declare const comparePdfToSnapshot: (pdf: string | Buffer, snapshotDir: string, snapshotName: string, { maskRegions, ...restOpts }?: Partial<CompareOptions>) => Promise<boolean>; | ||
| export declare function comparePdfToSnapshot( | ||
| /** Path to the PDF file or a Buffer containing the PDF. */ | ||
| pdf: string | Buffer, | ||
| /** Path to the directory where `__snapshots__` folder will be created. */ | ||
| snapshotDir: string, | ||
| /** Unique name for the snapshot within the specified path. */ | ||
| snapshotName: string, | ||
| /** Check the type for available options. */ | ||
| options?: CompareOptions): Promise<boolean>; |
@@ -18,7 +18,8 @@ "use strict"; | ||
| exports.comparePdfToSnapshot = exports.snapshotsDirName = void 0; | ||
| const path_1 = require("path"); | ||
| const path_1 = __importDefault(require("path")); | ||
| const fs_1 = require("fs"); | ||
| const pdf2png_1 = require("./pdf2png"); | ||
| const pdf2png_1 = require("./pdf2png/pdf2png"); | ||
| const compare_images_1 = require("./compare-images"); | ||
| const jimp_1 = __importDefault(require("jimp")); | ||
| const imageUtils_1 = require("./imageUtils"); | ||
| const colorToNum = { | ||
@@ -48,27 +49,47 @@ Red: 0xff0000ff, | ||
| /** | ||
| * Compare pdf to persisted snapshot. If one does not exist it is created | ||
| * @param pdf - path to pdf file or pdf loaded as Buffer | ||
| * @param snapshotDir - path to a directory where __snapshots__ folder is going to be created | ||
| * @param snapshotName - uniq name of a snapshot in the above path | ||
| * @param compareOptions - image comparison options | ||
| * @param compareOptions.tolerance - number value for error tolerance, ranges 0-1 (default: 0) | ||
| * @param compareOptions.maskRegions - `(page: number) => ReadonlyArray<RegionMask> | undefined` mask predefined regions per page, i.e. when there are parts of the pdf that change between tests | ||
| * Compares a PDF to a persisted snapshot. If a snapshot does not exists, one is | ||
| * created. | ||
| * | ||
| * @remarks | ||
| * When the function is executed, it has following **side effects**: | ||
| * - If a previous snapshot file does not exist, the PDF is converted to an | ||
| * image, saved as a snapshot, and the function returns `true`. | ||
| * - If a snapshot exists, the PDF is converted to an image and compared to the | ||
| * snapshot: | ||
| * - If they differ, the function returns `false` and creates two additional | ||
| * images next to the snapshot: one with the suffix `new` (the current view | ||
| * of the PDF as an image) and one with the suffix `diff` (showing the | ||
| * difference between the snapshot and the `new` image). | ||
| * - If they are equal, the function returns `true`. If `new` and `diff` | ||
| * versions are present, they are deleted. | ||
| * | ||
| * @returns | ||
| * A promise that resolves to `true` if the PDF matches the snapshot or | ||
| * if a new snapshot is created, and `false` if the PDF differs from the snapshot. | ||
| */ | ||
| const comparePdfToSnapshot = (pdf, snapshotDir, snapshotName, _a = {}) => { | ||
| var { maskRegions = () => [] } = _a, restOpts = __rest(_a, ["maskRegions"]); | ||
| const dir = (0, path_1.join)(snapshotDir, exports.snapshotsDirName); | ||
| function comparePdfToSnapshot( | ||
| /** Path to the PDF file or a Buffer containing the PDF. */ | ||
| pdf, | ||
| /** Path to the directory where `__snapshots__` folder will be created. */ | ||
| snapshotDir, | ||
| /** Unique name for the snapshot within the specified path. */ | ||
| snapshotName, | ||
| /** Check the type for available options. */ | ||
| options) { | ||
| const _a = options || {}, { maskRegions = () => [], pdf2PngOptions } = _a, restOpts = __rest(_a, ["maskRegions", "pdf2PngOptions"]); | ||
| const dir = path_1.default.join(snapshotDir, exports.snapshotsDirName); | ||
| if (!(0, fs_1.existsSync)(dir)) { | ||
| (0, fs_1.mkdirSync)(dir, { recursive: true }); | ||
| } | ||
| const snapshotPath = (0, path_1.join)(dir, snapshotName + '.png'); | ||
| const snapshotPath = path_1.default.join(dir, snapshotName + '.png'); | ||
| if (!(0, fs_1.existsSync)(snapshotPath)) { | ||
| return (0, pdf2png_1.pdf2png)(pdf) | ||
| return (0, pdf2png_1.pdf2png)(pdf, pdf2PngOptions) | ||
| .then(maskImgWithRegions(maskRegions)) | ||
| .then((0, pdf2png_1.writeImages)(snapshotPath)) | ||
| .then((0, imageUtils_1.writeImages)(snapshotPath)) | ||
| .then(() => true); | ||
| } | ||
| return (0, pdf2png_1.pdf2png)(pdf) | ||
| return (0, pdf2png_1.pdf2png)(pdf, pdf2PngOptions) | ||
| .then(maskImgWithRegions(maskRegions)) | ||
| .then((images) => (0, compare_images_1.compareImages)(snapshotPath, images, restOpts).then((result) => { | ||
| const diffSnapshotPath = (0, path_1.join)(dir, snapshotName + '.diff.png'); | ||
| const diffSnapshotPath = path_1.default.join(dir, snapshotName + '.diff.png'); | ||
| if (result.equal) { | ||
@@ -80,9 +101,9 @@ if ((0, fs_1.existsSync)(diffSnapshotPath)) { | ||
| } | ||
| const newSnapshotPath = (0, path_1.join)(dir, snapshotName + '.new.png'); | ||
| return (0, pdf2png_1.writeImages)(newSnapshotPath)(images) | ||
| .then(() => (0, pdf2png_1.writeImages)(diffSnapshotPath)(result.diffs.map((x) => x.diff))) | ||
| const newSnapshotPath = path_1.default.join(dir, snapshotName + '.new.png'); | ||
| return (0, imageUtils_1.writeImages)(newSnapshotPath)(images) | ||
| .then(() => (0, imageUtils_1.writeImages)(diffSnapshotPath)(result.diffs.map((x) => x.diff))) | ||
| .then(() => false); | ||
| })); | ||
| }; | ||
| } | ||
| exports.comparePdfToSnapshot = comparePdfToSnapshot; | ||
| //# sourceMappingURL=compare-pdf-to-snapshot.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"compare-pdf-to-snapshot.js","sourceRoot":"","sources":["../src/compare-pdf-to-snapshot.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAA2B;AAC3B,2BAAsD;AACtD,uCAAgD;AAChD,qDAAmF;AACnF,gDAAuB;AAevB,MAAM,UAAU,GAAmC;IACjD,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,UAAU;IACjB,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,UAAU;IACjB,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,UAAU;IACnB,MAAM,EAAE,UAAU;IAClB,KAAK,EAAE,UAAU;IACjB,IAAI,EAAE,UAAU;CACjB,CAAA;AAED,MAAM,kBAAkB,GACtB,CAAC,WAAwB,EAAE,EAAE,CAC7B,CAAC,MAA2B,EAAuB,EAAE;IACnD,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC1B,CAAC;QAAA,CAAC,WAAW,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE;YAC7E,IAAI,IAAI,KAAK,gBAAgB,EAAE;gBAC7B,GAAG,CAAC,SAAS,CAAC,IAAI,cAAI,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;aAChE;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,C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AI,CAAC,IAAA,wBAAW,EAAC,YAAY,CAAC,CAAC;aAC/B,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;KACpB;IAED,OAAO,IAAA,iBAAO,EAAC,GAAG,EAAE,cAAc,CAAC;SAChC,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;SACrC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CACf,IAAA,8BAAa,EAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QAC5D,MAAM,gBAAgB,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,YAAY,GAAG,WAAW,CAAC,CAAA;QACnE,IAAI,MAAM,CAAC,KAAK,EAAE;YAChB,IAAI,IAAA,eAAU,EAAC,gBAAgB,CAAC,EAAE;gBAChC,IAAA,eAAU,EAAC,gBAAgB,CAAC,CAAA;aAC7B;YACD,OAAO,IAAI,CAAA;SACZ;QAED,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,YAAY,GAAG,UAAU,CAAC,CAAA;QACjE,OAAO,IAAA,wBAAW,EAAC,eAAe,CAAC,CAAC,MAAM,CAAC;aACxC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAA,wBAAW,EAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;aAC1E,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC,CAAC,CACH,CAAA;AACL,CAAC;AA3CD,oDA2CC"} |
+2
-1
@@ -1,1 +0,2 @@ | ||
| export { comparePdfToSnapshot, MaskRegions } from './compare-pdf-to-snapshot'; | ||
| export { comparePdfToSnapshot, MaskRegions, RegionMask, RectangleMask, CompareOptions, HighlightColor, } from './compare-pdf-to-snapshot'; | ||
| export { PdfToPngOptions, Dpi } from './types'; |
+3
-1
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.comparePdfToSnapshot = void 0; | ||
| exports.Dpi = exports.comparePdfToSnapshot = void 0; | ||
| var compare_pdf_to_snapshot_1 = require("./compare-pdf-to-snapshot"); | ||
| Object.defineProperty(exports, "comparePdfToSnapshot", { enumerable: true, get: function () { return compare_pdf_to_snapshot_1.comparePdfToSnapshot; } }); | ||
| var types_1 = require("./types"); | ||
| Object.defineProperty(exports, "Dpi", { enumerable: true, get: function () { return types_1.Dpi; } }); | ||
| //# sourceMappingURL=index.js.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qEAA6E;AAApE,+HAAA,oBAAoB,OAAA"} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qEAOkC;AANhC,+HAAA,oBAAoB,OAAA;AAOtB,iCAA8C;AAApB,4FAAA,GAAG,OAAA"} |
@@ -1,8 +0,8 @@ | ||
| import { CompareImagesOpts } from './compare-images'; | ||
| import { CompareOptions } from './compare-pdf-to-snapshot'; | ||
| declare global { | ||
| namespace jest { | ||
| interface Matchers<R> { | ||
| toMatchPdfSnapshot(opts?: Partial<CompareImagesOpts>): R; | ||
| toMatchPdfSnapshot(options?: CompareOptions): R; | ||
| } | ||
| } | ||
| } |
@@ -11,3 +11,3 @@ "use strict"; | ||
| // TODO: use jest snapshot functionality | ||
| toMatchPdfSnapshot(pdf, opts) { | ||
| toMatchPdfSnapshot(pdf, options) { | ||
| const { isNot, testPath, currentTestName } = this; | ||
@@ -19,3 +19,3 @@ if (isNot) { | ||
| const snapshotName = currentTestName.split(' ').join('_'); | ||
| return (0, compare_pdf_to_snapshot_1.comparePdfToSnapshot)(pdf, currentDirectory, snapshotName, opts).then((pass) => ({ | ||
| return (0, compare_pdf_to_snapshot_1.comparePdfToSnapshot)(pdf, currentDirectory, snapshotName, options).then((pass) => ({ | ||
| pass, | ||
@@ -22,0 +22,0 @@ message: () => 'Does not match with snapshot.', |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"toMatchPdfSnapshot.js","sourceRoot":"","sources":["../src/toMatchPdfSnapshot.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAE9B,uEAAgE;AAYhE,6DAA6D;AAC7D,aAAa;AACb,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAA;AAEhC,IAAI,UAAU,KAAK,SAAS,EAAE;IAC5B,UAAU,CAAC,MAAM,CAAC;QAChB,wCAAwC;QACxC,kBAAkB,CAAC,GAAoB,EAAE,IAAiC;YACxE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,IAAI,CAAA;YACjD,IAAI,KAAK,EAAE;gBACT,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;aAC7E;YAED,MAAM,gBAAgB,GAAG,IAAA,cAAO,EAAC,QAAQ,CAAC,CAAA;YAC1C,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YAEzD,OAAO,IAAA,8CAAoB,EAAC,GAAG,EAAE,gBAAgB,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBACrF,IAAI;gBACJ,OAAO,EAAE,GAAG,EAAE,CAAC,+BAA+B;aAC/C,CAAC,CAAC,CAAA;QACL,CAAC;KACF,CAAC,CAAA;CACH;KAAM;IACL,OAAO,CAAC,KAAK,CACX,sCAAsC;QACpC,wFAAwF,CAC3F,CAAA;CACF"} | ||
| {"version":3,"file":"toMatchPdfSnapshot.js","sourceRoot":"","sources":["../src/toMatchPdfSnapshot.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,uEAAgF;AAYhF,6DAA6D;AAC7D,aAAa;AACb,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAA;AAEhC,IAAI,UAAU,KAAK,SAAS,EAAE;IAC5B,UAAU,CAAC,MAAM,CAAC;QAChB,wCAAwC;QACxC,kBAAkB,CAAC,GAAoB,EAAE,OAAwB;YAC/D,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,IAAI,CAAA;YACjD,IAAI,KAAK,EAAE;gBACT,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;aAC7E;YAED,MAAM,gBAAgB,GAAG,IAAA,cAAO,EAAC,QAAQ,CAAC,CAAA;YAC1C,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YAEzD,OAAO,IAAA,8CAAoB,EAAC,GAAG,EAAE,gBAAgB,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBACxF,IAAI;gBACJ,OAAO,EAAE,GAAG,EAAE,CAAC,+BAA+B;aAC/C,CAAC,CAAC,CAAA;QACL,CAAC;KACF,CAAC,CAAA;CACH;KAAM;IACL,OAAO,CAAC,KAAK,CACX,sCAAsC;QACpC,wFAAwF,CAC3F,CAAA;CACF"} |
+4
-1
| { | ||
| "name": "pdf-visual-diff", | ||
| "version": "0.9.0", | ||
| "version": "0.10.0", | ||
| "description": "Visual Regression Testing for PDFs in JavaScript", | ||
@@ -11,2 +11,3 @@ "bin": "./lib/cli/index.js", | ||
| "build": "npm run clean && npm run lint && npm run test && npm run tsc -- --noEmit false", | ||
| "build:docs": "npx typedoc src/index.ts --treatWarningsAsErrors", | ||
| "tsc": "tsc --noEmit --pretty", | ||
@@ -62,7 +63,9 @@ "tsc:watch": "npm run tsc -- --watch", | ||
| "eslint-plugin-prettier": "^4.2.1", | ||
| "eslint-plugin-tsdoc": "^0.3.0", | ||
| "mocha": "^10.2.0", | ||
| "prettier": "^2.8.7", | ||
| "ts-node": "^10.9.1", | ||
| "typedoc": "^0.26.6", | ||
| "typescript": "^5.0.4" | ||
| } | ||
| } |
+58
-38
@@ -1,2 +0,2 @@ | ||
| # Visual Regression Testing for PDFs in JavaScript | ||
| # Test Visual Regression in PDFs | ||
@@ -7,6 +7,8 @@ [![NPM version][npm-badge-url]][npm-url] | ||
| Library for testing visual regression of PDFs. It uses [pdf.js](https://github.com/mozilla/pdf.js) for conversion of a pdf to png (in node pdf.js depends on [canvas](https://github.com/Automattic/node-canvas)). Than comparison is happening via [jimp](https://github.com/oliver-moran/jimp). | ||
| `pdf-visual-diff` is a library for testing visual regressions in PDFs. It uses [pdf.js](https://github.com/mozilla/pdf.js) to convert PDFs into PNGs and [jimp](https://github.com/oliver-moran/jimp) for image comparisons. | ||
| ## Installation | ||
| This library depends on `canvas` package. Please refer to the [canvas documentation](https://github.com/Automattic/node-canvas) for any additional installation steps. | ||
| ```sh | ||
@@ -23,32 +25,28 @@ npm install -D pdf-visual-diff | ||
| This package exports single function `comparePdfToSnapshot`. With the following signature: | ||
| This package exports a single function, [comparePdfToSnapshot](https://moshensky.github.io/pdf-visual-diff/functions/comparePdfToSnapshot.html), with the following signature: | ||
| ```ts | ||
| /** | ||
| * Compare pdf to persisted snapshot. If one does not exist it is created | ||
| * @param pdf - path to pdf file or pdf loaded as Buffer | ||
| * @param snapshotDir - path to a directory where __snapshots__ folder is going to be created | ||
| * @param snapshotName - uniq name of a snapshot in the above path | ||
| * @param compareOptions - image comparison options | ||
| * @param compareOptions.tolerance - number value for error tolerance, ranges 0-1 (default: 0) | ||
| * @param compareOptions.maskRegions - `(page: number) => ReadonlyArray<RegionMask> | undefined` mask predefined regions per page, i.e. when there are parts of the pdf that change between tests | ||
| */ | ||
| type ComparePdfToSnapshot = ( | ||
| function comparePdfToSnapshot( | ||
| pdf: string | Buffer, | ||
| snapshotDir: string, | ||
| snapshotName: string, | ||
| compareImageOpts: Partial<CompareOptions> = {}, | ||
| ) => Promise<boolean> | ||
| options?: CompareOptions | ||
| ): Promise<boolean> | ||
| ``` | ||
| When function is executed it has following **side** effects: | ||
| It compares a PDF to a persisted snapshot. If a snapshot does not exists, one is created. | ||
| When the function is executed, it has following **side effects**: | ||
| - In absence of a previous snapshot file it converts pdf to an image, saves it as a snapshot and returns `true` | ||
| - If there is a snapshot, then pdf is converted to an image and gets compared to the snapshot: | ||
| - if they differ function returns `false` and creates next to the snapshot image two other versions with suffixes `new` and `diff`. `new` one is the current view of the pdf as an image, where `diff` shows the difference between the snapshot and `new` images | ||
| - if they are equal function returns `true` and in case there are `new` and `diff` versions persisted it deletes them | ||
| - If a previous snapshot file does not exist, the PDF is converted to an image, saved as a snapshot, and the function returns `true`. | ||
| - If a snapshot exists, the PDF is converted to an image and compared to the snapshot: | ||
| - If they differ, the function returns `false` and creates two additional images next to the snapshot: one with the suffix `new` (the current view of the PDF as an image) and one with the suffix `diff` (showing the difference between the snapshot and the `new` image). | ||
| - If they are equal, the function returns `true`. If `new` and `diff` versions are present, they are deleted. | ||
| Returns a promise that resolves to `true` if the PDF matches the snapshot or if a new snapshot is created, and `false` if the PDF differs from the snapshot. | ||
| For further details and configuration options, please refer to the [API Documentation](https://moshensky.github.io/pdf-visual-diff). | ||
| ## Sample usage | ||
| > **NB!** You can find sample projects inside [examples folder](examples). | ||
| > **Note:** You can find sample projects in the [examples](https://github.com/moshensky/pdf-visual-diff/tree/master/examples) folder. | ||
@@ -61,4 +59,4 @@ Write a test file: | ||
| describe('test pdf report visual regression', () => { | ||
| const pathToPdf = 'path to your pdf' // or you might pass in Buffer instead | ||
| describe('test PDF report visual regression', () => { | ||
| const pathToPdf = 'path to your PDF' // or you might pass a Buffer instead | ||
| it('should pass', () => | ||
@@ -70,5 +68,5 @@ comparePdfToSnapshot(pathToPdf, __dirname, 'my-awesome-report').then( | ||
| // Example with masking regions of a two page pdf | ||
| describe('pdf masking', () => { | ||
| it('should mask two page pdf', () => { | ||
| // Example with masking regions of a two-page PDF | ||
| describe('PDF masking', () => { | ||
| it('should mask two-page PDF', () => { | ||
| const blueMask: RegionMask = { | ||
@@ -110,12 +108,33 @@ type: 'rectangle-mask', | ||
| pdf-visual-diff provides scripts for approving all new snapshots or discarding them. Add to your `scripts` section in `package.json` | ||
| `pdf-visual-diff` provides a CLI for approving or discarding new PDF snapshots. The CLI can be used via `npx` or `npm` by updating the `scripts` section of your `package.json`: | ||
| ```json | ||
| "scripts": { | ||
| "test:pdf-approve": "pdf-visual-diff approve", | ||
| "test:pdf-discard": "pdf-visual-diff discard" | ||
| } | ||
| ``` | ||
| To approve new snapshots, run the following command in your terminal: | ||
| ```sh | ||
| "test:pdf-approve": "pdf-visual-diff approve", | ||
| "test:pdf-discard": "pdf-visual-diff discard", | ||
| npm run test:pdf-approve | ||
| ``` | ||
| Paths for the new snapshots will be listed. You will then be prompted to confirm whether you want to replace the old snapshots with the new ones: | ||
| ```sh | ||
| pdf-visual-diff approve | ||
| New snapshots: | ||
| ./__snapshots__/test_doc_1.new.png | ||
| ./__snapshots__/single-page-snapshot.new.png | ||
| Are you sure you want to overwrite current snapshots? [Y/n]: | ||
| ``` | ||
| These commands can be customized by specifying a custom path and snapshots folder name. | ||
| Approve command help: | ||
| ```sh | ||
| npx pdf-visual-diff approve --help | ||
| Approve new snapshots | ||
@@ -130,4 +149,6 @@ | ||
| Discard command help: | ||
| ```sh | ||
| pdf-visual-diff discard | ||
| npx pdf-visual-diff discard --help | ||
@@ -143,6 +164,5 @@ Discard new snapshots and diffs | ||
| ## Usage with Jest | ||
| This packages provides custom jest matcher `toMatchPdfSnapshot` | ||
| This packages provides a custom Jest matcher `toMatchPdfSnapshot`. | ||
@@ -157,11 +177,11 @@ ### Setup | ||
| If you are using **Typescript** add `import('pdf-visual-diff/lib/toMatchPdfSnapshot')` to your typings. | ||
| If you are using **TypeScript** add `import('pdf-visual-diff/lib/toMatchPdfSnapshot')` to your typings. | ||
| ### Usage | ||
| All you have to do in your tests is pass a path to the pdf or pdf content as Buffer. | ||
| In your tests, pass a path to the PDF or PDF content a Buffer. | ||
| ```ts | ||
| const pathToPdf = 'path to your pdf' // or you might pass in Buffer instead | ||
| describe('test pdf report visual regression', () => { | ||
| const pathToPdf = 'path to your PDF' // or you might pass a Buffer instead | ||
| describe('test PDF report visual regression', () => { | ||
| it('should match', () => expect(pathToPdf).toMatchPdfSnapshot()) | ||
@@ -171,2 +191,2 @@ }) | ||
| As you can see no need to fiddle with any dirs nor names. Needed information is extracted from jest context. | ||
| As you can see, there is no need to manage directories or names manually. The necessary information is extracted from the Jest context. |
| const { comparePdfToSnapshot } = require('pdf-visual-diff') | ||
| const { join } = require('path') | ||
| const pathToPdf = join(__dirname, 'single-page.pdf') | ||
| const snapshotDir = join(__dirname) | ||
| const snapshotName = 'single-page-snapshot' | ||
| comparePdfToSnapshot(pathToPdf, snapshotDir, snapshotName).then(isEqual => { | ||
| console.log(`Is pdf equal to it's snapshot? Answer: ${isEqual}`) | ||
| }).catch(console.error) |
| { | ||
| "name": "bare-bones", | ||
| "version": "1.0.0", | ||
| "lockfileVersion": 1, | ||
| "requires": true, | ||
| "dependencies": { | ||
| "array-parallel": { | ||
| "version": "0.1.3", | ||
| "resolved": "https://registry.npmjs.org/array-parallel/-/array-parallel-0.1.3.tgz", | ||
| "integrity": "sha1-j3hTCJJu1apHjEfmTRszS2wMlH0=" | ||
| }, | ||
| "array-series": { | ||
| "version": "0.1.5", | ||
| "resolved": "https://registry.npmjs.org/array-series/-/array-series-0.1.5.tgz", | ||
| "integrity": "sha1-3103v8XC7wdV4qpPkv6ufUtaly8=" | ||
| }, | ||
| "balanced-match": { | ||
| "version": "1.0.0", | ||
| "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", | ||
| "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" | ||
| }, | ||
| "brace-expansion": { | ||
| "version": "1.1.11", | ||
| "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", | ||
| "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", | ||
| "requires": { | ||
| "balanced-match": "^1.0.0", | ||
| "concat-map": "0.0.1" | ||
| } | ||
| }, | ||
| "concat-map": { | ||
| "version": "0.0.1", | ||
| "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", | ||
| "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" | ||
| }, | ||
| "cross-spawn": { | ||
| "version": "4.0.2", | ||
| "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-4.0.2.tgz", | ||
| "integrity": "sha1-e5JHYhwjrf3ThWAEqCPL45dCTUE=", | ||
| "requires": { | ||
| "lru-cache": "^4.0.1", | ||
| "which": "^1.2.9" | ||
| } | ||
| }, | ||
| "debug": { | ||
| "version": "3.2.6", | ||
| "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", | ||
| "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", | ||
| "requires": { | ||
| "ms": "^2.1.1" | ||
| } | ||
| }, | ||
| "fs.realpath": { | ||
| "version": "1.0.0", | ||
| "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", | ||
| "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" | ||
| }, | ||
| "glob": { | ||
| "version": "7.1.6", | ||
| "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", | ||
| "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", | ||
| "requires": { | ||
| "fs.realpath": "^1.0.0", | ||
| "inflight": "^1.0.4", | ||
| "inherits": "2", | ||
| "minimatch": "^3.0.4", | ||
| "once": "^1.3.0", | ||
| "path-is-absolute": "^1.0.0" | ||
| } | ||
| }, | ||
| "gm": { | ||
| "version": "1.23.1", | ||
| "resolved": "https://registry.npmjs.org/gm/-/gm-1.23.1.tgz", | ||
| "integrity": "sha1-Lt7rlYCE0PjqeYjl2ZWxx9/BR3c=", | ||
| "requires": { | ||
| "array-parallel": "~0.1.3", | ||
| "array-series": "~0.1.5", | ||
| "cross-spawn": "^4.0.0", | ||
| "debug": "^3.1.0" | ||
| } | ||
| }, | ||
| "inflight": { | ||
| "version": "1.0.6", | ||
| "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", | ||
| "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", | ||
| "requires": { | ||
| "once": "^1.3.0", | ||
| "wrappy": "1" | ||
| } | ||
| }, | ||
| "inherits": { | ||
| "version": "2.0.4", | ||
| "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", | ||
| "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" | ||
| }, | ||
| "isexe": { | ||
| "version": "2.0.0", | ||
| "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", | ||
| "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" | ||
| }, | ||
| "lru-cache": { | ||
| "version": "4.1.5", | ||
| "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", | ||
| "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", | ||
| "requires": { | ||
| "pseudomap": "^1.0.2", | ||
| "yallist": "^2.1.2" | ||
| } | ||
| }, | ||
| "minimatch": { | ||
| "version": "3.0.4", | ||
| "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", | ||
| "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", | ||
| "requires": { | ||
| "brace-expansion": "^1.1.7" | ||
| } | ||
| }, | ||
| "ms": { | ||
| "version": "2.1.2", | ||
| "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", | ||
| "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" | ||
| }, | ||
| "once": { | ||
| "version": "1.4.0", | ||
| "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", | ||
| "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", | ||
| "requires": { | ||
| "wrappy": "1" | ||
| } | ||
| }, | ||
| "path-is-absolute": { | ||
| "version": "1.0.1", | ||
| "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", | ||
| "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" | ||
| }, | ||
| "pdf-visual-diff": { | ||
| "version": "0.5.0", | ||
| "resolved": "https://registry.npmjs.org/pdf-visual-diff/-/pdf-visual-diff-0.5.0.tgz", | ||
| "integrity": "sha512-g+YRO5IlMve6Kudv7bMiVuKejSSNCPBDoWt0CE0zR1HnR99T1dGPmwwW7noYDMBRO4U3iR6qrr/2N7cESD2r/w==", | ||
| "requires": { | ||
| "glob": "^7.1.6", | ||
| "gm": "^1.23.1" | ||
| } | ||
| }, | ||
| "pseudomap": { | ||
| "version": "1.0.2", | ||
| "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", | ||
| "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=" | ||
| }, | ||
| "which": { | ||
| "version": "1.3.1", | ||
| "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", | ||
| "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", | ||
| "requires": { | ||
| "isexe": "^2.0.0" | ||
| } | ||
| }, | ||
| "wrappy": { | ||
| "version": "1.0.2", | ||
| "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", | ||
| "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" | ||
| }, | ||
| "yallist": { | ||
| "version": "2.1.2", | ||
| "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", | ||
| "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" | ||
| } | ||
| } | ||
| } |
| { | ||
| "name": "bare-bones", | ||
| "version": "1.0.0", | ||
| "description": "bare-bones example how to use pdf-visual-diff lib", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| }, | ||
| "author": "", | ||
| "license": "ISC", | ||
| "dependencies": { | ||
| "pdf-visual-diff": "^0.5.0" | ||
| } | ||
| } |
| # bare-bones example how to use pdf-visual-diff lib | ||
| This is a bare-bones example how `comparePdfToSnapshot` could be used. It does not exercise any of the options that could be passed in for the sake of simplicity. | ||
| ## How to run | ||
| In terminal go into the folder where this README is located. | ||
| Observe that directory `__snapshots__` should not exists. | ||
| Run in terminal: | ||
| ```sh | ||
| node index.js | ||
| ``` | ||
| Please note that I test run it under node v10.9.0 | ||
| After the first run a `__snaphosts__` directory should be created with a snapshot `png` file inside it of the pdf. | ||
| Now run it for the second time: | ||
| ```sh | ||
| node index.js | ||
| ``` | ||
| Because the snapshot already exists, the pdf will be compared to it. The program output should equal to `Is pdf equal to it's snapshot? Answer: true`. | ||
| You could try replacing the snapshot file `single-page-snapshot.png` inside `__snapshots__` dir and run the program again (the filen name should stay the same). If you replace it with some random image you should see in the terminal `Answer: false`. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
| { | ||
| "name": "typescript-sample-sing-pdf-visual-diff", | ||
| "version": "0.5.0", | ||
| "description": "Visual Regression Testing for PDFs in JavaScript", | ||
| "scripts": { | ||
| "tsc": "tsc --noEmit --pretty", | ||
| "tsc:watch": "npm run tsc -- --watch", | ||
| "lint": "eslint ./src --ext .js,.jsx,.ts,.tsx", | ||
| "lint:fix": "npm run lint -- --fix", | ||
| "format": "prettier --write .eslintrc.js .prettierrc.json tsconfig.json .mocharc.json", | ||
| "test": "mocha", | ||
| "test:watch": "npm test -- --watch" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/moshensky/pdf-visual-diff.git" | ||
| }, | ||
| "keywords": [ | ||
| "pdf visual regression testing", | ||
| "pdf compare", | ||
| "pdf comparison", | ||
| "javascript", | ||
| "visual diff", | ||
| "typescript", | ||
| "diff testing", | ||
| "js" | ||
| ], | ||
| "author": "Nikita Moshensky", | ||
| "license": "MIT", | ||
| "bugs": { | ||
| "url": "https://github.com/moshensky/pdf-visual-diff/issues" | ||
| }, | ||
| "homepage": "https://github.com/moshensky/pdf-visual-diff#readme", | ||
| "dependencies": { | ||
| "glob": "^7.1.6", | ||
| "gm": "^1.23.1", | ||
| "pdfmake": "^0.1.68" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/chai": "^4.2.12", | ||
| "@types/gm": "^1.18.9", | ||
| "@types/mocha": "^8.0.3", | ||
| "@types/node": "^12.12.57", | ||
| "@types/pdfmake": "^0.1.16", | ||
| "@typescript-eslint/eslint-plugin": "^4.1.0", | ||
| "@typescript-eslint/parser": "^4.1.0", | ||
| "assert": "^2.0.0", | ||
| "chai": "^4.2.0", | ||
| "eslint": "^7.8.1", | ||
| "eslint-config-prettier": "^6.11.0", | ||
| "eslint-plugin-prettier": "^3.1.4", | ||
| "mocha": "^8.1.3", | ||
| "pdf-visual-diff": "^0.5.0", | ||
| "prettier": "^2.1.1", | ||
| "ts-node": "^9.0.0", | ||
| "typescript": "^4.0.2" | ||
| } | ||
| } |
| # Typescript sample | ||
| `mkSamplePdf` is a function that uses pdfmake to dynamically create pdfs. | ||
| It has two tests that are using pdf-visual-diff. One test passes, because it's snapshot will match, the other fails. |
| import Jimp from 'jimp'; | ||
| export declare const mergeImages: (imgs: ReadonlyArray<Jimp>) => Jimp; |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.mergeImages = void 0; | ||
| const jimp_1 = __importDefault(require("jimp")); | ||
| const mergeImages = (imgs) => { | ||
| let imgHeight = 0; | ||
| const imgData = imgs.map((img) => { | ||
| const res = { img, y: imgHeight }; | ||
| imgHeight += img.bitmap.height; | ||
| return res; | ||
| }); | ||
| const imgWidth = Math.max(...imgData.map(({ img }) => img.bitmap.width)); | ||
| const baseImage = new jimp_1.default(imgWidth, imgHeight, 0x00000000); | ||
| imgData.forEach(({ img, y }) => baseImage.composite(img, 0, y)); | ||
| return baseImage; | ||
| }; | ||
| exports.mergeImages = mergeImages; | ||
| //# sourceMappingURL=merge-images.js.map |
| {"version":3,"file":"merge-images.js","sourceRoot":"","sources":["../src/merge-images.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AAOhB,MAAM,WAAW,GAAG,CAAC,IAAyB,EAAQ,EAAE;IAC7D,IAAI,SAAS,GAAG,CAAC,CAAA;IACjB,MAAM,OAAO,GAAc,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAC1C,MAAM,GAAG,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,SAAS,EAAE,CAAA;QACjC,SAAS,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAA;QAC9B,OAAO,GAAG,CAAA;IACZ,CAAC,CAAC,CAAA;IAEF,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IACxE,MAAM,SAAS,GAAG,IAAI,cAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;IAE3D,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAE/D,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAdY,QAAA,WAAW,eAcvB"} |
| /// <reference types="node" /> | ||
| import Jimp from 'jimp'; | ||
| export type Pdf2PngOpts = Readonly<{ | ||
| scaleImage: boolean; | ||
| }>; | ||
| export declare function pdf2png(pdf: string | Buffer, options?: Partial<Pdf2PngOpts>): Promise<ReadonlyArray<Jimp>>; | ||
| export declare const writeImages: (outputImagePath: string, combinePages?: boolean) => (images: ReadonlyArray<Jimp>) => Promise<ReadonlyArray<Jimp>>; |
-142
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.writeImages = exports.pdf2png = void 0; | ||
| const Canvas = __importStar(require("canvas")); | ||
| const assert = __importStar(require("assert")); | ||
| const fs = __importStar(require("fs")); | ||
| const path = __importStar(require("path")); | ||
| const pdfjsLib = __importStar(require("pdfjs-dist/legacy/build/pdf")); | ||
| const jimp_1 = require("jimp"); | ||
| const merge_images_1 = require("./merge-images"); | ||
| function convertFromMmToPx(sizeMm, dpi) { | ||
| if (sizeMm <= 0 || dpi <= 0) { | ||
| return 0; | ||
| } | ||
| const sizeInch = sizeMm / 25.4; | ||
| return Math.round(sizeInch * dpi); | ||
| } | ||
| function convertFromPxToMm(sizePx, dpi) { | ||
| if (sizePx <= 0 || dpi <= 0) { | ||
| return 0; | ||
| } | ||
| const sizeInch = sizePx / dpi; | ||
| return Math.round(sizeInch * 25.4); | ||
| } | ||
| class NodeCanvasFactory { | ||
| create(width, height) { | ||
| assert.ok(width > 0 && height > 0, 'Invalid canvas size'); | ||
| const canvas = Canvas.createCanvas(width, height); | ||
| const context = canvas.getContext('2d'); | ||
| return { | ||
| canvas, | ||
| context, | ||
| }; | ||
| } | ||
| reset(canvasAndContext, width, height) { | ||
| assert.ok(canvasAndContext.canvas, 'Canvas is not specified'); | ||
| assert.ok(width > 0 && height > 0, 'Invalid canvas size'); | ||
| canvasAndContext.canvas.width = width; | ||
| canvasAndContext.canvas.height = height; | ||
| } | ||
| destroy(canvasAndContext) { | ||
| assert.ok(canvasAndContext.canvas, 'Canvas is not specified'); | ||
| canvasAndContext.canvas.width = 0; | ||
| canvasAndContext.canvas.height = 0; | ||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore | ||
| canvasAndContext.canvas = null; | ||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore | ||
| canvasAndContext.context = null; | ||
| } | ||
| } | ||
| // pdfjs location | ||
| const PDFJS_DIR = path.dirname(require.resolve('pdfjs-dist')); | ||
| // Some PDFs need external cmaps. | ||
| const CMAP_URL = path.join(PDFJS_DIR, '../cmaps/'); | ||
| const CMAP_PACKED = true; | ||
| // Where the standard fonts are located. | ||
| const STANDARD_FONT_DATA_URL = path.join(PDFJS_DIR, '../standard_fonts/'); | ||
| const pdf2PngDefOpts = { | ||
| scaleImage: true, | ||
| }; | ||
| function getPageViewPort(page, scaleImage) { | ||
| const viewport = page.getViewport({ scale: 1.0 }); | ||
| if (scaleImage === false) { | ||
| return viewport; | ||
| } | ||
| // Increase resolution | ||
| const horizontalMm = convertFromPxToMm(viewport.width, 72); | ||
| const verticalMm = convertFromPxToMm(viewport.height, 72); | ||
| const actualWidth = convertFromMmToPx(horizontalMm, 144); | ||
| const actualHeight = convertFromMmToPx(verticalMm, 144); | ||
| const scale = Math.min(actualWidth / viewport.width, actualHeight / viewport.height); | ||
| return page.getViewport({ scale }); | ||
| } | ||
| async function pdf2png(pdf, options = {}) { | ||
| const opts = Object.assign(Object.assign({}, pdf2PngDefOpts), options); | ||
| // Load PDF | ||
| const data = new Uint8Array(Buffer.isBuffer(pdf) ? pdf : fs.readFileSync(pdf)); | ||
| const loadingTask = pdfjsLib.getDocument({ | ||
| data, | ||
| cMapUrl: CMAP_URL, | ||
| cMapPacked: CMAP_PACKED, | ||
| standardFontDataUrl: STANDARD_FONT_DATA_URL, | ||
| }); | ||
| const pdfDocument = await loadingTask.promise; | ||
| const numPages = pdfDocument.numPages; | ||
| const canvasFactory = new NodeCanvasFactory(); | ||
| const canvasAndContext = canvasFactory.create(1, 1); | ||
| // Generate images | ||
| const images = []; | ||
| for (let idx = 1; idx <= numPages; idx += 1) { | ||
| const page = await pdfDocument.getPage(idx); | ||
| const viewport = getPageViewPort(page, opts.scaleImage); | ||
| canvasFactory.reset(canvasAndContext, viewport.width, viewport.height); | ||
| // TODO: fix types | ||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore | ||
| await page.render({ canvasContext: canvasAndContext.context, viewport }).promise; | ||
| page.cleanup(); | ||
| const image = canvasAndContext.canvas.toBuffer('image/png'); | ||
| images.push(image); | ||
| } | ||
| return Promise.all(images.map((x) => (0, jimp_1.read)(x))); | ||
| } | ||
| exports.pdf2png = pdf2png; | ||
| const writeImages = (outputImagePath, combinePages = true) => (images) => { | ||
| if (combinePages === true) { | ||
| return (0, merge_images_1.mergeImages)(images) | ||
| .writeAsync(outputImagePath) | ||
| .then(() => images); | ||
| } | ||
| const parsedPath = path.parse(outputImagePath); | ||
| const partialName = path.join(parsedPath.dir, parsedPath.name); | ||
| const padMaxLen = images.length.toString().length; | ||
| return Promise.all(images.map((img, idx) => img.writeAsync(`${partialName}_${String(idx + 1).padStart(padMaxLen, '0')}.png`))).then(() => images); | ||
| }; | ||
| exports.writeImages = writeImages; | ||
| //# sourceMappingURL=pdf2png.js.map |
| {"version":3,"file":"pdf2png.js","sourceRoot":"","sources":["../src/pdf2png.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,+CAAgC;AAChC,uCAAwB;AACxB,2CAA4B;AAC5B,sEAAuD;AACvD,+BAAiC;AACjC,iDAA4C;AAE5C,SAAS,iBAAiB,CAAC,MAAc,EAAE,GAAW;IACpD,IAAI,MAAM,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE;QAC3B,OAAO,CAAC,CAAA;KACT;IACD,MAAM,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAA;IAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAA;AACnC,CAAC;AACD,SAAS,iBAAiB,CAAC,MAAc,EAAE,GAAW;IACpD,IAAI,MAAM,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE;QAC3B,OAAO,CAAC,CAAA;KACT;IACD,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C3D,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;KACnB;IAED,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,WAAI,EAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAChD,CAAC;AAxCD,0BAwCC;AAEM,MAAM,WAAW,GACtB,CAAC,eAAuB,EAAE,YAAY,GAAG,IAAI,EAAE,EAAE,CACjD,CAAC,MAA2B,EAAgC,EAAE;IAC5D,IAAI,YAAY,KAAK,IAAI,EAAE;QACzB,OAAO,IAAA,0BAAW,EAAC,MAAM,CAAC;aACvB,UAAU,CAAC,eAAe,CAAC;aAC3B,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAA;KACtB;IAED,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;IAC9C,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,CAAC,CAAA;IAC9D,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAA;IACjD,OAAO,OAAO,CAAC,GAAG,CAChB,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CACtB,GAAG,CAAC,UAAU,CAAC,GAAG,WAAW,IAAI,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,CACjF,CACF,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAA;AACtB,CAAC,CAAA;AAjBU,QAAA,WAAW,eAiBrB"} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Mixed license
LicensePackage contains multiple licenses.
Found 1 instance in 1 package
65
41.3%0
-100%184
12.2%72806
-61.5%18
12.5%920
-76.2%1
Infinity%