feat: allow customization of print page header and footer (#19688)
* feat: allow customization of more print settings * address feedback from @jkleinsc * header and footer are optional
This commit is contained in:
parent
84cbc1d6c0
commit
7861e9f728
2 changed files with 21 additions and 4 deletions
|
@ -1264,6 +1264,8 @@ Returns [`PrinterInfo[]`](structures/printer-info.md).
|
|||
* `dpi` Object (optional)
|
||||
* `horizontal` Number (optional) - The horizontal dpi.
|
||||
* `vertical` Number (optional) - The vertical dpi.
|
||||
* `header` String (optional) - String to be printed as page header.
|
||||
* `footer` String (optional) - String to be printed as page footer.
|
||||
* `callback` Function (optional)
|
||||
* `success` Boolean - Indicates success of the print call.
|
||||
* `failureReason` String - Called back if the print fails; can be `cancelled` or `failed`.
|
||||
|
|
|
@ -1637,20 +1637,20 @@ void WebContents::Print(mate::Arguments* args) {
|
|||
printing::DEFAULT_MARGINS);
|
||||
}
|
||||
|
||||
settings.SetBoolean(printing::kSettingHeaderFooterEnabled, false);
|
||||
|
||||
// Set whether to print color or greyscale
|
||||
bool print_color = true;
|
||||
options.Get("color", &print_color);
|
||||
int color_setting = print_color ? printing::COLOR : printing::GRAY;
|
||||
settings.SetInteger(printing::kSettingColor, color_setting);
|
||||
|
||||
// Is the orientation landscape or portrait.
|
||||
bool landscape = false;
|
||||
options.Get("landscape", &landscape);
|
||||
settings.SetBoolean(printing::kSettingLandscape, landscape);
|
||||
|
||||
// We set the default to empty string here and only update
|
||||
// if at the Chromium level if it's non-empty
|
||||
// Printer device name as opened by the OS.
|
||||
base::string16 device_name;
|
||||
options.Get("deviceName", &device_name);
|
||||
settings.SetString(printing::kSettingDeviceName, device_name);
|
||||
|
@ -1663,15 +1663,30 @@ void WebContents::Print(mate::Arguments* args) {
|
|||
options.Get("pagesPerSheet", &pages_per_sheet);
|
||||
settings.SetInteger(printing::kSettingPagesPerSheet, pages_per_sheet);
|
||||
|
||||
// True if the user wants to print with collate.
|
||||
bool collate = true;
|
||||
options.Get("collate", &collate);
|
||||
settings.SetBoolean(printing::kSettingCollate, collate);
|
||||
|
||||
// The number of individual copies to print
|
||||
int copies = 1;
|
||||
options.Get("copies", &copies);
|
||||
settings.SetInteger(printing::kSettingCopies, copies);
|
||||
|
||||
// For now we don't want to allow the user to enable these settings
|
||||
// Strings to be printed as headers and footers if requested by the user.
|
||||
std::string header;
|
||||
options.Get("header", &header);
|
||||
std::string footer;
|
||||
options.Get("footer", &footer);
|
||||
|
||||
if (!(header.empty() && footer.empty())) {
|
||||
settings.SetBoolean(printing::kSettingHeaderFooterEnabled, true);
|
||||
|
||||
settings.SetString(printing::kSettingHeaderFooterTitle, header);
|
||||
settings.SetString(printing::kSettingHeaderFooterURL, footer);
|
||||
}
|
||||
|
||||
// We don't want to allow the user to enable these settings
|
||||
// but we need to set them or a CHECK is hit.
|
||||
settings.SetBoolean(printing::kSettingPrintToPDF, false);
|
||||
settings.SetBoolean(printing::kSettingCloudPrintDialog, false);
|
||||
|
@ -1700,7 +1715,7 @@ void WebContents::Print(mate::Arguments* args) {
|
|||
settings.SetList(printing::kSettingPageRange, std::move(page_range_list));
|
||||
}
|
||||
|
||||
// Set custom duplex mode
|
||||
// Duplex type user wants to use.
|
||||
printing::DuplexMode duplex_mode;
|
||||
options.Get("duplexMode", &duplex_mode);
|
||||
settings.SetInteger(printing::kSettingDuplexMode, duplex_mode);
|
||||
|
|
Loading…
Reference in a new issue