msedge.exe does not save html file as pdf in command line headless mode anymore

Guimberteau, Thierry (T.) 0 Reputation points
2025-10-09T08:30:46.5433333+00:00

I am trying to use Edge to save a html file as a pdf file from the command line without opening the Edge browser window.

I have defined the following code in my .bashrc (Cygwin shell)

msedge_path="$cdrive/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
# Use cygpath to get the Windows path to your Desktop for the output.
# This is more portable than hardcoding it.
pdf_output_dir=$(cygpath -w "C:/Users/USER_ID/Documents")
function pp() {
  # --- Input Validation ---
  if [ -z "$1" ]; then
    echo "Error: You must provide a base filename."
    echo "Usage: pp <filename_without_extension>"
    return 1 # Exit the function with an error status
  fi
  # --- Variable Setup ---
  # Use $1 to safely get the first argument.
  local input_path_without_extension="$1"
  # Extract only the base filename
  local output_base_filename=$(basename "$input_path_without_extension")
  local html_file_posix="$(pwd)/${input_path_without_extension}.html"
  # Use output_base_filename for the PDF name
  local pdf_file_windows="${pdf_output_dir}\\${output_base_filename}.pdf"
  local html_file_windows=$(cygpath -w "$html_file_posix")
  # --- Pre-flight Check ---
  if [ ! -f "$html_file_posix" ]; then
    echo "Error: Input file not found at: $html_file_posix"
    return 1
  fi
  
  echo "Printing '$html_file_posix' to '$pdf_file_windows'..."
  # --- The Command ---
  # Note the correct string concatenation for the flags.
  "$msedge_path" \
    --headless=new \
    --disable-gpu \
    --smartscreen-disable \
    --print-to-pdf="$pdf_file_windows" \
    --virtual-time-budget=5000 \
    "file://$html_file_windows" \
    &> /dev/null &
  # The '&' runs the command in the background, so your shell is immediately available.
}

Back in July 2025, I could execute in a Cygwin shell the following command

pp myfile

and that would save myfile.html as myfile.pdf in C:/Users/USER_ID/Documents.

Now (October 2025) with latest Edge build (Version 141.0.3537.57 (Official build) (64-bit)) it doesn't work anymore. No error is reported but no pdf file is generated.

Microsoft Edge | Other | Windows 11
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emmanuel Santana 32,020 Reputation points Independent Advisor
    2025-10-09T12:55:34.7733333+00:00

    Hello. This issue has been reported by multiple users since the October 2025 update (Edge 141.0.3537.57). The --print-to-pdf flag no longer works in headless mode due to changes in Chromium’s headless implementation that Edge inherits.

    It’s a confirmed regression tracked here (you won't be able to access the issue tho, it's internal): Chromium Issue 381548416 – Headless print-to-pdf broken

    For now, the following workarounds have been successful for others: • Add --user-data-dir="C:\Temp\EdgeProfile" to your command. • Use forward slashes in paths, e.g. C:/Users/.../file.pdf. • Try --headless=old instead of --headless=new.

    There’s no official fix in the current stable channel yet, but the Chromium issue above is actively tracked and expected to be resolved in a later build.

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.