Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
How to export react components as pdf, but without converting it to an image?

I have a rather complex react page, with both canvas elements, svg's, draftjs (WISIYG editor), and regular MUI components. I want to export this page as a pdf. The window.print option is too rigid and creates problems when the user goes beyond one page in the pdf with their WYSIWYG content. I do not want to convert the WYSIWYG content to an image and then put it into the pdf, as it is impossible to create a pleasing UI in the pdf with this option. Is there an "easy" way to export such a page? Alternatively, if anyone knows how to export the content as an HTML file this would also be great.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You'll want to render the html as PDF. In node, the best way to go about this is to use a headless browser to render the html and use those tools to export as PDF.

Puppeteer is a headless chrome you can use https://github.com/puppeteer/puppeteer. You'll want to render your react page as HTML and pass it to puppeteer:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://news.ycombinator.com', {
    waitUntil: 'networkidle2',
  });
  await page.pdf({ path: 'hn.pdf', format: 'a4' });

  await browser.close();
})();

There's some libraries that wrap this functionality https://www.npmjs.com/package/html-pdf-node.

I've used PhantomJS based PDF rendering in the past, and I'd recommend you use Puppeteer.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda