Skip to content

Commit fb5273d

Browse files
authored
feat: pass creation and modification dates (#2539)
1 parent cfd050c commit fb5273d

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

.changeset/cool-roses-teach.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@react-pdf/render': minor
3+
'@react-pdf/types': minor
4+
---
5+
6+
feat: add creation and modification dates

packages/render/src/operations/addMetadata.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ const addMetadata = (ctx, doc) => {
2020
const keywords = props.keywords || null;
2121
const creator = props.creator ?? 'react-pdf';
2222
const producer = props.producer ?? 'react-pdf';
23+
const creationDate = props.creationDate || new Date();
24+
const modificationDate = props.modificationDate || null;
2325

2426
setProp('Title', title);
2527
setProp('Author', author);
2628
setProp('Subject', subject);
2729
setProp('Keywords', keywords);
2830
setProp('Creator', creator);
2931
setProp('Producer', producer);
32+
setProp('CreationDate', creationDate);
33+
setProp('ModificationDate', modificationDate);
3034
};
3135

3236
export default addMetadata;

packages/render/tests/operations/addMetadata.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,31 @@ describe('operations addMetadata', () => {
111111

112112
expect(ctx.info.Producer).toBe('test');
113113
});
114+
115+
test('should add creationDate metadata if provided', () => {
116+
const ctx = createCTX();
117+
const doc = { type: P.Document, props: { creationDate: 'test' } };
118+
119+
addMetadata(ctx, doc);
120+
121+
expect(ctx.info.CreationDate).toBe('test');
122+
});
123+
124+
test('should not add modificationDate metadata if none provided', () => {
125+
const ctx = createCTX();
126+
const doc = { type: P.Document };
127+
128+
addMetadata(ctx, doc);
129+
130+
expect(ctx.info.ModificationDate).toBeUndefined();
131+
});
132+
133+
test('should add modificationDate metadata if provided', () => {
134+
const ctx = createCTX();
135+
const doc = { type: P.Document, props: { modificationDate: 'test' } };
136+
137+
addMetadata(ctx, doc);
138+
139+
expect(ctx.info.ModificationDate).toBe('test');
140+
});
114141
});

packages/types/node.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ interface DocumentProps {
6161
keywords?: string;
6262
creator?: string;
6363
producer?: string;
64+
creationDate?: Date;
65+
modificationDate?: Date;
6466
pageLayout?: PageLayout;
6567
pageMode?: PageMode;
6668
}

0 commit comments

Comments
 (0)