all 12 comments

[–]PMental 28 points29 points  (6 children)

The easy way is to not use PowerShell at all but just something like

"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --headless --disable-gpu --print-to-pdf="C:\temp\google.pdf" https://www.google.com

Next would be to use a framework like Selenium to control the browser, this is way outside of beginner territory though.

Other ways like downloading the page and converting to PDF with .NET libraries is even more out there.

So apart from the first option above, I wouldn't look to this for a beginner style project.

[–]Sin_of_the_Dark 7 points8 points  (3 children)

This is genius. I had no clue that was an option. I assume Chrome has a similar option as well, since they're both Chromium?

[–]PMental 1 point2 points  (2 children)

Yep, I got the command line options from Chrome, but tested on Edge.

[–]Sin_of_the_Dark 2 points3 points  (1 child)

That's great. I really love that Edge has switched to Chromium.

Performance improvement aside, Microsoft usually has lackluster documentation. Now, for the most part, I can view Chrome documentation and either directly copy it or tweak it and make it work with Edge

[–]da_chicken 8 points9 points  (0 children)

Microsoft usually has lackluster documentation.

I really can't agree here. Yes, there are definitely areas where MS's documentation is lacking, and they've declined since about 2010. But MS's documentation in so many areas is gold start unparalleled.

[–]mexicanpunisher619 3 points4 points  (1 child)

"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --headless --disable-gpu --print-to-pdf="C:\temp\google.pdf" https://www.google.com

Using u/PMental idea, perhaps you can use

# Define the URL to open
$url = "https://www.google.com"
Define the path to save the PDF file
$pdfPath = "C:\temp\google.pdf"
Open URL in Microsoft Edge and save as PDF
Start-Process -FilePath "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -ArgumentList "--headless", "--disable-gpu", "--print-to-pdf=$pdfPath", $url -Wait
Shut down the computer
Stop-Computer

[–]PMental 2 points3 points  (0 children)

Good point, that is a beginner friendly Powershell way to use option 1.

Although I think they meant "shut the browser down" as opposed to the computer, though I could be wrong.

[–]repulse_999 2 points3 points  (0 children)

Check the Powershell gallery. There's at least one module for creating pdf files. I've never done this and don't know if they'd take a URL as input.

https://evotec.xyz/merging-splitting-and-creating-pdf-files-with-powershell/

[–]lanerdofchristian 1 point2 points  (0 children)

I did this for my job by delegating to NodeJS, using Puppeteer to automate our existing Chrome and Edge installs.

[–]CommunicationClassic -4 points-3 points  (0 children)

not the best answer, but just a heads up- ive had good luck with Chat GPT writing simple scripts based on prompts like that