0

I'm using (or trying to use) react-pdf/renderer to generated formatted PDF output for a React project. I can get the output; but it's not formatted.

I assume I'm doing something wrong, but I'm creating my PDF like this:

export function PDFOutput() {
 return (
 <Document>
 <Page>
 <Text style={{
 fontFamily: "Courier",
 fontSize: "12pt"
 }}>
 Testing
 </Text>
 </Page>
 </Document>
 )
}

and rendering/display it like this:

 const PdfRoot = () => (
 <PDFViewer>
 <PDFOutput/>
 </PDFViewer>
 );
 
 const container = document.getElementById('pdf-root');
 if (pdfRoot == null)
 pdfRoot = createRoot(container);
 pdfRoot.render(<PdfRoot/>)

but the result I get is this:

enter image description here

In other words, the Text's style formatting is ignored. ("Courier" is a built-in supported font, so does not have to be otherwise registered.) Doing almost exactly the same thing in the project website's Repl playground works, however, so I'm not sure what the difference is.

asked Jun 4, 2024 at 2:30
0

1 Answer 1

0

This is a known issue in the new versions of @react-pdf/renderer. There is a temporary fix to this until it's resolved in the new release.

If you are using npm, Add an overrides property in your package.json :

"overrides": {
 "@react-pdf/layout": "3.11.5"
},

Yarn has a similar feature with the resolutions property :

"resolutions": {
 "@react-pdf/layout": "3.11.5"
},
answered Jul 15, 2024 at 1:51
Sign up to request clarification or add additional context in comments.

1 Comment

Doesn't seem to make a difference (in my case), but thanks all the same!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.