mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
* pdf/a1b support initial commit Added mixin for support pdf/a1b and a few of the things it requires (xmp metadata, colour profile). Currently, the CIDSet stream is the only error it comes back with the test case I'm using, will try sorting it out next. * Adding CIDSet when generating PDF/A PDF/A1 b/a requires a CIDSet. This is not checked by a validator and other converters seem to add a CIDSet with a value of FF FF FF FF 0C, so this commit does the same. When extending support for PDF/A 2/3/4, we may not add a CIDSet (I think for PDF/A3 it's not required?) or we will look for a proper way to generate the CIDSet. At this point, PDFKit should be able to generate PDF/A1b which can pass veraPDF validation and PDF/A1a if tagged is enabled. All you have to do is set pdfa: '1a' or pdfa: '1b' in the options passed to new PDFDocument. * pdf/a intro docs * generalising subsets, reimplementing pdfa1 and added control over metadata added a generalised subsets mixin which can pull in a subset at runtime. reimplemented pdfa1 mixin as some features should be standardised across all subsets, such as storing /Info as xmp metadata for pdf >1.3 added a metadata class and mixing to control and write the metadata to a pdf * added tests for pdfa1 and metadata and moved joinTokens in helpers Addeds tests for pdfa1 subset and metadata. Moved joinTokens into helpers.js as it's now used in at least two places. Added tests for document to when metadata should be added (pdf version 1.4 or newer) and when it shouldn't (pdf version 1.3) * updated pdf/a docs to reflect latest changes * store color profile as icc file * Updated changelog to include PDF/A support in Unreleased section
72 lines
1.7 KiB
JavaScript
72 lines
1.7 KiB
JavaScript
import PDFDocument from '../../lib/document';
|
|
import { logData } from './helpers';
|
|
|
|
describe('PDFDocument', () => {
|
|
describe('font option', () => {
|
|
let fontSpy;
|
|
|
|
beforeEach(() => {
|
|
fontSpy = jest.spyOn(PDFDocument.prototype, 'font').mockReturnThis();
|
|
});
|
|
|
|
afterEach(() => {
|
|
fontSpy.mockRestore();
|
|
});
|
|
|
|
test('not defined', () => {
|
|
new PDFDocument();
|
|
|
|
expect(fontSpy).toBeCalledWith('Helvetica');
|
|
});
|
|
|
|
test('a string value', () => {
|
|
new PDFDocument({ font: 'Roboto' });
|
|
|
|
expect(fontSpy).toBeCalledWith('Roboto');
|
|
});
|
|
|
|
test('a falsy value', () => {
|
|
new PDFDocument({ font: null });
|
|
new PDFDocument({ font: false });
|
|
new PDFDocument({ font: '' });
|
|
|
|
expect(fontSpy).not.toBeCalled();
|
|
});
|
|
});
|
|
|
|
describe('document info', () => {
|
|
test('accepts properties with value undefined', () => {
|
|
expect(() => new PDFDocument({ info: { Title: undefined } })).not.toThrow(
|
|
new TypeError("Cannot read property 'toString' of undefined")
|
|
);
|
|
});
|
|
|
|
test('accepts properties with value null', () => {
|
|
expect(() => new PDFDocument({ info: { Title: null } })).not.toThrow(
|
|
new TypeError("Cannot read property 'toString' of null")
|
|
);
|
|
});
|
|
});
|
|
|
|
test('metadata is present for PDF 1.4', () => {
|
|
let doc = new PDFDocument({pdfVersion: '1.4'});
|
|
const data = logData(doc);
|
|
doc.end();
|
|
|
|
let catalog = data[data.length-28];
|
|
|
|
expect(catalog).toContain('/Metadata');
|
|
});
|
|
|
|
test('metadata is NOT present for PDF 1.3', () => {
|
|
let doc = new PDFDocument({pdfVersion: '1.3'});
|
|
const data = logData(doc);
|
|
doc.end();
|
|
|
|
let catalog = data[data.length-27];
|
|
|
|
expect(catalog).not.toContain('/Metadata');
|
|
});
|
|
|
|
});
|