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

644
Visualizações
PDF font size issue using HTML with Puppeteer

I am trying to generate a PDF in browser(chrome v8) using HTML by sending it to puppeteer. The html is getting generated using ejs since there is dynamic content for some of the sections of the PDF. The dynamic content includes images,html tables(number of rows and columns are dynamic) and text.

In the HTML I have defined css within the style tag to format the content.

While the font-size seems to be coming from the style tag - the entire content seems to be getting compressed/contracted for some combinations of content. It looks like one PDF content was generated at a 100% zoom (normal sized) and the other at 80% zoom (where everything looks smaller).

I tried removing the img tags (no extra CSS Styling is given) - that solved the problem for combination of data.

Also the content on the right is getting cut in some cases - I have tried giving the body tag in the html a width of 100% but that has not solved the problem.

Viewing the HTML generated by EJS in the browser as a pure HTML file - shows no difference between the cases where the PDF shows a change in size.

Any pointers in solving this would be appreciated.

Font-size is set as

* {
    Font-size: 16px;
}

Puppeteer code snippets are given below:

const browser = await puppeteer.launch({
           args: ['--no-sandbox'],
           headless: true
       });


await page.setContent(bodyHtml, {
           waitUntil: 'networkidle0'
       });

var options = {
           headerTemplate: headerHtmlWithStyles,
           footerTemplate: footerHtmlWithStyles,
           displayHeaderFooter: true,
                    margin: {
               top: "195px",
               right: "64px",
               bottom: "100px",
               left: "64px"
           },
           
           printBackground: false,
           path: pdfPath,
           format: 'A4',
           preferCSSPageSize: false
       }


await page.emulateMediaType("screen");
       await page.pdf(options);

over 4 years ago · Santiago Trujillo
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