Search code examples
google-chromecommand-linemicrosoft-edge

Chrome Print to PDF via Windows Command Prompt


I'm trying to print a webpage to a PDF and it's not working as of this week. I'm using Chrome, but it's also not working with Edge.

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --print-to-pdf="new_file.pdf" "https://google.com"

Can anyone help please?


Solution

  • Try using --headless=old

    My reasoning: As of 9/2/2024, the chromium/new-headless page contains these three statements:

    To use new Headless mode, pass the --headless=new command-line flag: chrome --headless=new

    For now, the old Headless mode is still available with: chrome --headless=old

    Passing the --headless command-line flag without an explicit value still activates the old Headless mode, but we intend to change this default.

    Based on problems that we had last week, and on other people reporting recent headless issues, I suspect that the Chromium team recently changed that default. In particular, I see Issue 362301064: Headless print-to-pdf is no longer functional unless headless=old, which seems to match the issue we're all having. I haven't had a chance to try it yet in our code, but I expect this to fix it.