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

Add "prefix" to PDF exporter #1328

Open
1 task done
blwsk opened this issue Dec 16, 2024 · 1 comment
Open
1 task done

Add "prefix" to PDF exporter #1328

blwsk opened this issue Dec 16, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@blwsk
Copy link

blwsk commented Dec 16, 2024

Is your feature request related to a problem? Please describe.
Status quo of the PDF exporter class supports optional header and footer parameters that are applied to each exported page. It would be useful to include an additional parameter, prefix, that adds the specified context only to the beginning of the exported document.

Describe the solution you'd like
It would be useful to include an additional parameter, prefer, that adds the specified context only to the beginning of the exported document. I.e.:

import { Text } from "@react-pdf/renderer";
const pdfDocument = await exporter.toReactPDFDocument(editor.document, {
  prefix: <Text>Prefix. Only appearing at the top of the first page, below the header.</Text>,
});

Describe alternatives you've considered
A current workaround is to hand write one or several blocks that don't exist in the editor's document and concatenate them at the beginning of editor.document. A big drawback to this approach is that any content you want to prefix your document with needs to be part of your editor schema. Ideally, any React PDF-compatible markup would be supported.

Additional context

Happy to submit a PR but first I wanted to verify this matches the intent of the PDF export package.

Bonus

  • I'm a sponsor and would appreciate if you could look into this sooner than later 💖

(https://github.com/poggiolabs is a sponsor)

@blwsk blwsk added the enhancement New feature or request label Dec 16, 2024
@YousefED
Copy link
Collaborator

Hi!

Thanks for the feedback. A currently possible alternative is to subclass PDFExporter and override transformBlocks to first return a prefix <View> and then call super.transformBlocks().

Let me know how this goes! I agree this might not be very clear, so happy to accept a PR with a clearer API and / or documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants