UNPKG

@pdfme/pdf-lib

Version:

Create and modify PDF files with JavaScript

44 lines β€’ 2.37 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = __importDefault(require("fs")); const index_1 = require("../../../src/index"); const catRidingUnicornJpg = fs_1.default.readFileSync('assets/images/cat_riding_unicorn.jpg'); const usConstitutionPdf = fs_1.default.readFileSync('assets/pdfs/us_constitution.pdf'); describe(`FileEmbedder`, () => { it(`can be constructed with FileEmbedder.for(...)`, () => { const embedder = index_1.FileEmbedder.for(catRidingUnicornJpg, 'cat.jpg'); expect(embedder).toBeInstanceOf(index_1.FileEmbedder); }); it(`can embed files into PDFContexts without a predefined ref`, async () => { const context = index_1.PDFContext.create(); const embedder = index_1.FileEmbedder.for(catRidingUnicornJpg, 'cat_riding_unicorn.jpg', { mimeType: 'image/jpeg', description: 'Cool cat riding a unicorn! πŸ¦„πŸˆπŸ•ΆοΈ', creationDate: new Date('2019/12/01'), modificationDate: new Date('2020/04/19'), }); expect(context.enumerateIndirectObjects().length).toBe(0); const ref = await embedder.embedIntoContext(context); expect(context.enumerateIndirectObjects().length).toBe(2); expect(context.lookup(ref)).toBeInstanceOf(index_1.PDFDict); }); it(`can embed files into PDFContexts with a predefined ref`, async () => { const context = index_1.PDFContext.create(); const predefinedRef = index_1.PDFRef.of(9999); const embedder = index_1.FileEmbedder.for(usConstitutionPdf, 'us_constitution.pdf', { mimeType: 'application/pdf', description: 'Constitution of the United States πŸ‡ΊπŸ‡ΈπŸ¦…', creationDate: new Date('1787/09/17'), modificationDate: new Date('1992/05/07'), }); expect(context.enumerateIndirectObjects().length).toBe(0); const ref = await embedder.embedIntoContext(context, predefinedRef); expect(context.enumerateIndirectObjects().length).toBe(2); expect(context.lookup(predefinedRef)).toBeInstanceOf(index_1.PDFDict); expect(ref).toBe(predefinedRef); }); }); //# sourceMappingURL=FileEmbedder.spec.js.map