0

I am trying to download a web page as pdf using edgewebdriver and selenium. Now, the edge is configured to a OneNote(Desktop) as seen in the image Edge print dialog

I want to change the dropdown value in the dialog before clicking on the print button. This is the constructor code where I am initializing the driver

public Driver(bool headLess = true)
{
    var driverPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Driver");
    var chromeDriverService = EdgeDriverService.CreateChromiumService(driverPath);
    chromeDriverService.HideCommandPromptWindow = true;
    var edgeOptions = new EdgeOptions();
    edgeOptions.UseChromium = true;
    var appState = new AppState()
    {
        recentDestinations = new List<RecentDestination>()
        {
            new RecentDestination(){ id = "Save as PDF", origin ="local", account = ""}
        },
        selectedDestinationId = "Save as PDF",
        version = 2
    };
    edgeOptions.AddUserProfilePreference("printing.print_preview_sticky_settings", appState);
    edgeOptions.AddArguments("kiosk-printing");
    if (headLess)
    {
        edgeOptions.AddArgument("headless");
    }
    this._driver = new EdgeDriver(chromeDriverService, edgeOptions);
}

I have referred the following link Chrome prefs list

I am totally stuck and can't find any solution to the problem. Every time "Print" dialog comes but the it tries to save to OneNode(Desktop).

Saurav
  • 592
  • 4
  • 21

1 Answers1

0

No guarantee, but with One Note uninstalled my Edge Save as is PDF (not any of several PDF printers Inc MS) HOWEVER see my additional OneNote settings below.

Who added One Note is not really material but if this for controlling other users just beware fixing it for you alone, will not necessarily fix it for those others. (However user preference here, should not be allowed to override other users.)

Windows printing has a reliance on fall back defaults, and if Your default Printer is One Note then many Windows Apps will be told its THE Printer and its CURRENT DEFAULT page size is paramount.

  • If you have no other printers then One Note is the only one
  • You share your computer with someone else and they set it!
  • You share your computer With Windows 10 and it sets it for you!!

Just to compound insult to injury Windows 10 can be set to keep changing the default behind your back. So For stability hunt down Let Windows Manage Me and ensure that is off. enter image description here enter image description here

Then ensure the default printer is Say Microsoft Print to PDF

AND not essential but ensure default page layout is your preferred portrait or landscape for future use, ideally reboot the machine to ensure those defaults pervade through the system. For greater control on a use by use basis you need to use PrintUI.dll commands to store variable sets of preferences.

OneNote is a bundled MS component of Office and you have 3 suggested options:-

1. Just uninstall OneNote Printer (my GoTo solution, along with 2 as I already used up 3)

When you install Microsoft Office, OneNote is set as the default printer for most print jobs.

Use Win Key + X then N (for settiNgs) then pick devices or key in PR Enter Pick Printers and Scanners, Select OneNote (It should expand) then Select Remove device OR

2. Remove OneNote from Start-up (also a favourite)

Use Win Key + X then T (for Task Manager) Enter and Pick middle start-Up tab If you see One note Enabled set it to Disabled and reboot. If that does not work use option 1

This "Disables" OneNote hogging resources at Start-up. IF you want to run OneNote, you must pick it manually in Start, or use a shortcut.

3. Remove OneNote Permanently (Not so easy as it can repeatedly reinstall)

Use Control Panel\All Control Panel Items\Programs and Features Find Office and CHANGE (or in my case uninstall) Features should include Microsoft Office OneNote which you can select and SWITCH to Not Available

K J
  • 8,045
  • 3
  • 14
  • 36
  • still not working. Print dialog is opening but default to the last printer value and not the value that I am sending – Saurav Jul 23 '21 at 04:22
  • yes..now everytime i manually ctrl+p, printer option is microsoft print to pdf, however when running the web driver it is trying to open one note – Saurav Jul 23 '21 at 14:36