Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document: creationDate and modificationDate #2536

Closed
satelllte opened this issue Jan 21, 2024 · 6 comments · Fixed by #2539
Closed

Document: creationDate and modificationDate #2536

satelllte opened this issue Jan 21, 2024 · 6 comments · Fixed by #2539

Comments

@satelllte
Copy link
Contributor

Is your feature request related to a problem? Please describe.

  1. The output of PDF document render is not deterministic, because "creation date" metadata is being set based on system date
  2. There's no way to set "modification date" metadata

Describe the solution you'd like

It would be great to have an ability to manipulate with "creation date" and "modification date" settings in a flexible way, so each consumer can decide on their own how to handle those. For example, I'd really like to have an ability to set some specific "creation date" at a point I started to work on my document, and then change the "modification date" every time I update it.

Describe alternatives you've considered

At this point, the only way I found to "lock" the "creation date" is to lock my system date:

import ReactPDF from '@react-pdf/renderer';
import FakeTimers from '@sinonjs/fake-timers';
import {MyDocument} from './MyDocument';

const rootDir = process.cwd();

// There's no way to set "creation date" metadata in React PDF at this point,
// so we need to mock it on the clock level to get the same output every time.
const clock = FakeTimers.install();
clock.now = new Date('2024-01-03T12:00:00.000Z').getTime();

await ReactPDF.render(<MyDocument />, `${rootDir}/my-document.pdf`);

clock.uninstall();

Additional context

Here's how I see it could be solved API-wise, without any breaking changes.

Introduce two new optional props to Document:

  • creationDate
  • modificationDate

When creationDate is not set, "creation date" metadata will be taken based on current system date. If set, it'll be used.
When modificationDate is not set, "modification date" metadata won't be handled (as it is now). If set, it'll be used.

Should be straightforward.

@satelllte
Copy link
Contributor Author

Related issue: #1375

@satelllte
Copy link
Contributor Author

@diegomura Thank you so much 🚀

@satelllte
Copy link
Contributor Author

@diegomura Unfortunately, this still doesn't work.

  1. renderer/DocumentProps misses some props from types/DocumentProps: fix: creationDate and modificationDate types #2544
  2. As far as I understand, the renderer itself still misses these props passing to the underlying render engine

@diegomura
Copy link
Owner

Thanks! Merged. It shuold work, just types are broken :) Will publish soon

@satelllte
Copy link
Contributor Author

@diegomura It actually didn't work when I passed those props into <Document /> regardless of TS type errors, so I'm not sure my fix does something. I've just opened a working branch as draft, but didn't expect it to be merged

@kimoshigoikuze
Copy link

Still doesn't work, if you add modificationDate to Document you get a customMetada field with value true, but no modificationDate
Screenshot 2024-07-08 at 15 16 59
Screenshot 2024-07-08 at 15 17 42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants