Skip to content

Commit

Permalink
fix: document metadata setters (#2949)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomura authored Nov 16, 2024
1 parent 03322a7 commit fb848a7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 183 deletions.
3 changes: 0 additions & 3 deletions packages/render/src/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import renderNode from './primitives/renderNode';
import addMetadata from './operations/addMetadata';
import addBookmarks from './operations/addBookmarks';

const render = (ctx, doc) => {
const pages = doc.children || [];
const options = { imageCache: new Map() };

addMetadata(ctx, doc);

pages.forEach((page) => renderNode(ctx, page, options));

addBookmarks(ctx, doc);
Expand Down
36 changes: 0 additions & 36 deletions packages/render/src/operations/addMetadata.js

This file was deleted.

143 changes: 0 additions & 143 deletions packages/render/tests/operations/addMetadata.test.js

This file was deleted.

26 changes: 25 additions & 1 deletion packages/renderer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import layoutDocument from '@react-pdf/layout';

import createRenderer from './renderer';
import packageJson from '../package.json';
import { omitNils } from './utils';

const { version } = packageJson;

Expand Down Expand Up @@ -35,7 +36,20 @@ const pdf = (initialValue) => {

const render = async (compress = true) => {
const props = container.document.props || {};
const { pdfVersion, language, pageLayout, pageMode } = props;
const {
pdfVersion,
language,
pageLayout,
pageMode,
title,
author,
subject,
keyboards,
creator = 'react-pdf',
producer = 'react-pdf',
creationDate = new Date(),
modificationDate,
} = props;

const ctx = new PDFDocument({
compress,
Expand All @@ -45,6 +59,16 @@ const pdf = (initialValue) => {
autoFirstPage: false,
pageLayout,
pageMode,
info: omitNils({
Title: title,
Author: author,
Subject: subject,
Keywords: keyboards,
Creator: creator,
Producer: producer,
CreationDate: creationDate,
ModificationDate: modificationDate,
}),
});

const layout = await layoutDocument(container.document, fontStore);
Expand Down
6 changes: 6 additions & 0 deletions packages/renderer/src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/prefer-default-export */

export const omitNils = (object) =>
Object.fromEntries(
Object.entries(object).filter(([, value]) => value !== undefined),
);

0 comments on commit fb848a7

Please sign in to comment.