Add this CSS to the page your creating into a PDF to remove Chrome Headless's implemented Header and Footer.
CSS:
@media print {
@page { margin: 0; }
body { margin: 1.6cm; }
}
You should format your command like below to create the PDF:
"C:PATHTOCHROMEEXECUTABLEFILE", "--headless","--disable-gpu","--print-to-pdf=" + directory path to where you want the file to go followed by the desired file name/fileName.pdf,"--no-margins", "the path to the file you want turned into a pdf"
Example 1:
C:chrome-win/chrome --headless --disable-gpu --print-to-pdf=C:userfileName.pdf --no-margins C:Projectsindex.html
Example 2:
You can also test this functionality by navigating in your command line to the folder containing Chrome executable file, and running this command:
chrome --headless --disable-gpu --print-to-pdf https://www.chromestatus.com/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…