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.