Hi I am automating printing feature using selenium Java I have to deal with printing preview of chrome. I use chromeOptions to set some settings for printing like Save as PDF select landscape I have one question I need to change paper size to A4 instead of letter that is the default but I don’t know the attribute to set, do you have an idea or have the documentation for print_preview_sticky_settings.appState ? I don’t know where to ask this question I will be happy if you could help.
My chrome options as following: chromeOptions.setExperimentalOption("prefs", new java.util.HashMap() {{ put("plugins.plugins_disabled", new String[]{"Chrome PDF Viewer"}); put("printing.default_destination_selection_rules", "{\"kind\": \"local\", \"namePattern\": \"Save as PDF\"}"); }],\"version\":2,\"isGcpPromoDismissed\":false,\"selectedDestinationId\":\"Save as PDF\"}"); put("printing.print_preview_sticky_settings.appState", "{\"recentDestinations\": [{\"id\": \"Save as PDF\", \"origin\": \"local\", \"account\": \"\" }],\"version\":2,\"isHeaderFooterEnabled\": true,\"paperSize\": 'A4',\"isGcpPromoDismissed\":false,\"selectedDestinationId\":\"Save as PDF\"}"); }});
Raghad The `print_preview_sticky_settings.appState` Chrome option is used to control the sticky settings of the print preview dialog. The `appState` property is a JSON object that contains the following settings: ``` "appState": { "recentDestinations": [{ "id": "Save as PDF", "origin": "local", "account": "" }], "version": 2, "isHeaderFooterEnabled": true, "isGcpPromoDismissed": false, "selectedDestinationId": "Save as PDF" } ``` To change the paper size to A4, you can set the `paperSize` property to `A4`. For example: ``` "appState": { "recentDestinations": [{ "id": "Save as PDF", "origin": "local", "account": "" }], "version": 2, "isHeaderFooterEnabled": true, "isGcpPromoDismissed": false, "selectedDestinationId": "Save as PDF", "paperSize": "A4" } ``` Here is an example of how to set the chromeOptions to print to A4 PDF: ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("--kiosk-printing"); chromeOptions.setExperimentalOption("prefs", new java.util.HashMap() {{ put("plugins.plugins_disabled", new String[]{"Chrome PDF Viewer"}); put("printing.default_destination_selection_rules", "{\"kind\": \"local\", \"namePattern\": \"Save as PDF\"}"); put("printing.print_preview_sticky_settings.appState", "{\"recentDestinations\": [{\"id\": \"Save as PDF\", \"origin\": \"local\", \"account\": \"\" }],\"version\":2,\"isHeaderFooterEnabled\": true,\"paperSize\": 'A4',\"isGcpPromoDismissed\":false,\"selectedDestinationId\":\"Save as PDF\"}"); }}); Once you have set the chromeOptions, you can use them to create a new ChromeDriver instance: ``` ChromeDriver driver = new ChromeDriver(chromeOptions); ``` You can then use the driver to automate the printing process.
@@RaghavPal Hi thanks for replaying, I take it copy paste but unfortunately still not take paper size, still shown with Letter default value, any suggestions?...
@@RaghavPal I found another way by using "mediaSize": {"height_microns": 355600, "width_microns": 215900} to set the dimensions and convert to microns, or inspect the dropdown that allows you to choose the paper-size, and then search for your desired size in the options, and copy/paste the values. But still not work :(
Thanks sir. Apki help ke liye bahut bahut sukriya
You're welcome Rahul
this is a very good video why you have so many less views. VERY VERY GOOD VIDEO!
Thanks Ali, looks like it needs to be discovered yet by many people.:)
Hi please share the video for how to generate testng test result for headless browser testing
Hi Ram, I will check and plan on this
@@RaghavPalthank you.. in my local jenkins mail report send properly but in Linux jenkins server it's failed..
Okay, will need to check, the settings, path, software on linux
I liked earlier audio with continuous transmission better, but still very informative video and whole course
Thanks August
Hi I am automating printing feature using selenium Java I have to deal with printing preview of chrome. I use chromeOptions to set some settings for printing like Save as PDF select landscape
I have one question I need to change paper size to A4 instead of letter that is the default but I don’t know the attribute to set, do you have an idea or have the documentation for print_preview_sticky_settings.appState ?
I don’t know where to ask this question I will be happy if you could help.
My chrome options as following:
chromeOptions.setExperimentalOption("prefs", new java.util.HashMap() {{
put("plugins.plugins_disabled", new String[]{"Chrome PDF Viewer"});
put("printing.default_destination_selection_rules", "{\"kind\": \"local\", \"namePattern\": \"Save as PDF\"}");
}],\"version\":2,\"isGcpPromoDismissed\":false,\"selectedDestinationId\":\"Save as PDF\"}");
put("printing.print_preview_sticky_settings.appState", "{\"recentDestinations\": [{\"id\": \"Save as PDF\", \"origin\": \"local\", \"account\": \"\" }],\"version\":2,\"isHeaderFooterEnabled\": true,\"paperSize\": 'A4',\"isGcpPromoDismissed\":false,\"selectedDestinationId\":\"Save as PDF\"}");
}});
Raghad
The `print_preview_sticky_settings.appState` Chrome option is used to control the sticky settings of the print preview dialog. The `appState` property is a JSON object that contains the following settings:
```
"appState": {
"recentDestinations": [{
"id": "Save as PDF",
"origin": "local",
"account": ""
}],
"version": 2,
"isHeaderFooterEnabled": true,
"isGcpPromoDismissed": false,
"selectedDestinationId": "Save as PDF"
}
```
To change the paper size to A4, you can set the `paperSize` property to `A4`. For example:
```
"appState": {
"recentDestinations": [{
"id": "Save as PDF",
"origin": "local",
"account": ""
}],
"version": 2,
"isHeaderFooterEnabled": true,
"isGcpPromoDismissed": false,
"selectedDestinationId": "Save as PDF",
"paperSize": "A4"
}
```
Here is an example of how to set the chromeOptions to print to A4 PDF:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--kiosk-printing");
chromeOptions.setExperimentalOption("prefs", new java.util.HashMap() {{
put("plugins.plugins_disabled", new String[]{"Chrome PDF Viewer"});
put("printing.default_destination_selection_rules", "{\"kind\": \"local\", \"namePattern\": \"Save as PDF\"}");
put("printing.print_preview_sticky_settings.appState", "{\"recentDestinations\": [{\"id\": \"Save as PDF\", \"origin\": \"local\", \"account\": \"\" }],\"version\":2,\"isHeaderFooterEnabled\": true,\"paperSize\": 'A4',\"isGcpPromoDismissed\":false,\"selectedDestinationId\":\"Save as PDF\"}");
}});
Once you have set the chromeOptions, you can use them to create a new ChromeDriver instance:
```
ChromeDriver driver = new ChromeDriver(chromeOptions);
```
You can then use the driver to automate the printing process.
@@RaghavPal Hi thanks for replaying, I take it copy paste but unfortunately still not take paper size, still shown with Letter default value, any suggestions?...
@@RaghavPal Does it need a default selection_rules like destination?
@@RaghavPal I found another way by using "mediaSize": {"height_microns": 355600, "width_microns": 215900} to set the dimensions and convert to microns, or inspect the dropdown that allows you to choose the paper-size, and then search for your desired size in the options, and copy/paste the values.
But still not work :(
:)