question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

page.pdf generating different and unexpected content with chrome print

See original GitHub issue

Steps to reproduce

Tell us about your environment:

What steps will reproduce the problem?

use https://github.com/rawbin-/puppeteer-test-pdf see the data folder, or run the test-from-html.js

or you can do with the ReadMe.md

Please include code that reproduces the issue.

const path = require('path')
const puppeteer = require('puppeteer')

const DEFAULT_ARGS = [
    '--disable-gpu',
    '--disable-dev-shm-usage',
    '--disable-setuid-sandbox',
    '--no-first-run',
    '--no-sandbox',
    '--no-zygote',
    '--disable-extensions',
    '--disable-webgl'];

const htmlPath = './data/test-simple.html'
const format = 'A5' // alt A5 A4
setTimeout(async () => {
    const htmlPathAb = path.resolve(htmlPath)
    const pdfPath = `${htmlPathAb}-${format}.pdf`

    const browser = await puppeteer.launch({
        args: DEFAULT_ARGS,
    });
    const page = await browser.newPage()
    console.log('opening the page')
    await page.goto(`file:///${path.resolve(htmlPath)}`, {
        waitUntil: 'networkidle0',
        timeout: 60000 * 10 // 尝试性加入最大等待时间,可能还不够。。。
    })
    console.log('waiting for the page')
    await page.waitForFunction(() => {
        return window.contentRenderFinished
    });
    console.log('generating pdf')
    await page.pdf({
        htmlPath: htmlPathAb,
        path: pdfPath,
        format: format,
        printBackground: true,
        landscape:true,
        margin: {
            top: '23.13mm',
            bottom: '25mm',
            left: '0mm',
            right: '0mm'
        }
    });
    await page.close();
    await browser.close()
    console.log('finished')
}, 5000)

What is the expected result? chrome print ok chromium print ok puppeteer generate ok no content splited into two pages image

What happens instead? chrome print ok chromium print ok puppeteer generate not one line splited into two pages image

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

1reaction
leigercommented, Apr 13, 2020

The fonts are different.

how did you see that? The font in the left pic might be 宋体? but the right is PingFang font. By the way, to prevent word break inside the paragraph, try the css property break-inside: avoid

1reaction
leigercommented, Apr 11, 2020

The fonts are different.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Printing PDF from web browser gets weird - HP Community
This only happens when printing a pdf file from the web browser (Google Chrome, have not tried other browser): if I download the...
Read more >
90340 - Chrome crashes when printing to PDF - chromium
I have tried printing to a pdf, actually printing the page. Tried printing text urls, pdfs, urls containing flash pages. Chrome dint crash...
Read more >
Chrome is suddenly defaulting to PDF to print. - Google Help
When previewing documents via Chrome PRINTER icon in top right hand corner of window the print is always directed to download the file...
Read more >
Trouble printing adobe .pdf files on google chrome
The current version of Chrome doesn't use the Adobe Reader to display PDF files. When you hover your mouse over the bottom left...
Read more >
Google Chrome Printing Page Breaks - css - Stack Overflow
I've used the following approach successfully in all major browsers including Chrome: <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found