Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
Render MUI components to string client side?

I am using the Material UI (MUI) library as a basis for my React app and I am trying to render some of the components to PDF in the browser.

The strategy is:

  1. Create a React element
  2. Render the React element to an HTML string
  3. Render the HTML string as a PDF

My code currently:

import React from "react";
import ReactDOMServer from 'react-dom/server';
import { ThemeProvider, createTheme } from "@mui/material/styles";
import { jsPDF } from "jspdf";

// ...

const el = (
  <ThemeProvider theme={myTheme}>
    <CssBaseline />
    <App />
  </ThemeProvider>
);

const html = ReactDOMServer.renderToString(el);

const doc = new jsPDF({
  orientation: "portrait",
  unit: "px",
});

const callback = () => {
  doc.save("test.pdf");
};

doc.html(html, { callback });

However, this does not render the theme correctly (fonts, background colors, etc). I believe this is an issue with step (2).

MUI uses Emotion for CSS styling, but the SSR packages for Emotion only seem to work on Node.

import { renderStylesToString } from '@emotion/server';

How can I render the styles into a complete HTML string in the browser?


Some versions:

"react": "^17.0.2",
"@mui/material": "^5.0.0",
"@emotion/css": "^11.7.1",
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!