Class CoreWebView2PrintSettings
Settings used by the PrintToPdfAsync(string, CoreWebView2PrintSettings) method.
public class CoreWebView2PrintSettings
- Inheritance
-
CoreWebView2PrintSettings
- Inherited Members
Properties
Collation
Printer collation.
public CoreWebView2PrintCollation Collation { get; set; }
Property Value
Remarks
See CoreWebView2PrintCollation for descriptions of collation. The default value is Default.
Printing uses default value of printer's collation if an invalid value is provided for the specific printer.
This value is ignored in PrintToPdfStreamAsync(CoreWebView2PrintSettings) method.
ColorMode
Printer color mode.
public CoreWebView2PrintColorMode ColorMode { get; set; }
Property Value
Remarks
See CoreWebView2PrintColorMode for descriptions of color modes. The default value is Default.
Printing uses default value of printer supported color if an invalid value is provided for the specific printer.
Copies
Number of copies to print. Minimum value is 1
and the maximum copies count is 999
.
public int Copies { get; set; }
Property Value
Remarks
The default value is 1.
Duplex
Printer duplex settings.
public CoreWebView2PrintDuplex Duplex { get; set; }
Property Value
Remarks
See CoreWebView2PrintDuplex for descriptions of duplex. The default value is Default.
Printing uses default value of printer's duplex if an invalid value is provided for the specific printer.
This value is ignored in PrintToPdfStreamAsync(CoreWebView2PrintSettings) method.
FooterUri
The URI in the footer if ShouldPrintHeaderAndFooter is true
.
public string FooterUri { get; set; }
Property Value
Remarks
The default value is the current URI. If an empty string or null value is provided, no URI is shown in the footer.
HeaderTitle
The title in the header if ShouldPrintHeaderAndFooter is true
.
public string HeaderTitle { get; set; }
Property Value
Remarks
The default value is the title of the current document. If an empty string or null value is provided, no title is shown in the header.
MarginBottom
The bottom margin in inches.
public double MarginBottom { get; set; }
Property Value
Remarks
The default is 1 cm, or ~0.4 inches. A margin cannot be less than zero. If an invalid value is provided, the current value is not changed and an ArgumentException is thrown.
MarginLeft
The left margin in inches.
public double MarginLeft { get; set; }
Property Value
Remarks
The default is 1 cm, or ~0.4 inches. A margin cannot be less than zero. If an invalid value is provided, the current value is not changed and an ArgumentException is thrown.
MarginRight
The right margin in inches.
public double MarginRight { get; set; }
Property Value
Remarks
The default is 1 cm, or ~0.4 inches. A margin cannot be less than zero. If an invalid value is provided, the current value is not changed and an ArgumentException is thrown.
MarginTop
The top margin in inches.
public double MarginTop { get; set; }
Property Value
Remarks
The default is 1 cm, or ~0.4 inches. A margin cannot be less than zero. If an invalid value is provided, the current value is not changed and an ArgumentException is thrown.
MediaSize
Printer media size.
public CoreWebView2PrintMediaSize MediaSize { get; set; }
Property Value
Remarks
See CoreWebView2PrintMediaSize for descriptions of media size. The default value is Default.
If media size is Custom, you should set the PageWidth and PageHeight.
Printing uses default value of printer supported media size if an invalid value is provided for the specific printer.
This value is ignored in PrintToPdfStreamAsync(CoreWebView2PrintSettings) method.
Orientation
The orientation can be portrait or landscape.
public CoreWebView2PrintOrientation Orientation { get; set; }
Property Value
Remarks
The default orientation is portrait. See CoreWebView2PrintOrientation.
PageHeight
The page height in inches.
public double PageHeight { get; set; }
Property Value
Remarks
The default height is 11 inches. If the provided page height is less than or equal to zero, the current value is not changed and an ArgumentException is thrown.
PageRanges
Page range to print. Defaults to empty string, which means print all pages.
public string PageRanges { get; set; }
Property Value
Remarks
The PageRanges property is a list of page ranges specifying one or more pages that should be printed separated by commas. Any whitespace between page ranges is ignored.
A valid page range is either a single integer identifying the page to print, or a range in the form [start page]-[last page]
where start page
and last page
are integers identifying the first and last inclusive pages respectively to print.
Every page identifier is an integer greater than 0 unless wildcards are used (see below examples).
The first page is 1.
In a page range of the form [start page]-[last page]
the start page number must be larger than 0 and less than or equal to the document's total page count.
If the start page
is not present, then 1 is used as the start page
.
The last page
must be larger than the start page
.
If the last page
is not present, then the document total page count is used as the last page
.
Repeating a page does not print it multiple times. To print multiple times, use the Copies property.
The pages are always printed in ascending order, even if specified in non-ascending order.
If page range is not valid or if a page is greater than document total page count, ArgumentException is thrown.
The following examples assume a document with 20 total pages.
Example | Result | Notes |
---|---|---|
"2" | Page 2 | |
"1-4, 9, 3-6, 10, 11" | Pages 1-6, 9-11 | |
"1-4, -6" | Pages 1-6 | The "-6" is interpreted as "1-6". |
"2-" | Pages 2-20 | The "2-" is interpreted as "pages 2 to the end of the document". |
"4-2, 11, -6" | Invalid | "4-2" is an invalid range. |
"-" | Pages 1-20 | The "-" is interpreted as "page 1 to the end of the document". |
"1-4dsf, 11" | Invalid | |
"2-2" | Page 2 |
PageWidth
The page width in inches.
public double PageWidth { get; set; }
Property Value
Remarks
The default width is 8.5 inches. If the provided page width is less than or equal to zero, the current value is not changed and an ArgumentException is thrown.
PagesPerSide
Prints multiple pages of a document on a single piece of paper. Choose from 1, 2, 4, 6, 9 or 16.
public int PagesPerSide { get; set; }
Property Value
Remarks
The default value is 1.
If an invalid value is provided, ArgumentException is thrown.
Below examples shows print output for PagesPerSide and Duplex.
PagesPerSide | Total pages | Two-sided printing | Result |
---|---|---|---|
1 | 1 | - | 1 page on the front side. |
2 | 1 | Yes | 1 page on the front side. |
2 | 4 | - | 2 pages on the first paper and 2 pages on the next paper. |
2 | 4 | Yes | 2 pages on the front side and 2 pages on back side. |
4 | 4 | Yes | 4 pages on the front side. |
4 | 8 | Yes | 4 pages on the front side and 4 pages on the back side. |
PrinterName
The name of the printer to use.
public string PrinterName { get; set; }
Property Value
Remarks
Defaults to empty string. If the printer name is empty string or null, then it prints to the default printer on the user OS.
If provided printer name doesn't match with the name of any installed printers on the user OS, the method returns with PrinterUnavailable.
Use PrintCapabilities class to enumerate available printers.
This value is ignored in PrintToPdfStreamAsync(CoreWebView2PrintSettings) method.
ScaleFactor
The scale factor is a value between 0.1 and 2.0.
public double ScaleFactor { get; set; }
Property Value
Remarks
The default is 1.0. If an invalid value is provided, the current value is not changed and an ArgumentException is thrown.
ShouldPrintBackgrounds
true
if background colors and images should be printed.
public bool ShouldPrintBackgrounds { get; set; }
Property Value
Remarks
The default value is false
.
ShouldPrintHeaderAndFooter
true
if header and footer should be printed.
public bool ShouldPrintHeaderAndFooter { get; set; }
Property Value
Remarks
The default value is false
. The header consists of the date and time of printing, and the title of the page. The footer consists of the URI and page number. The height of the header and footer is 0.5 cm, or ~0.2 inches.
ShouldPrintSelectionOnly
true
if only the current end user's selection of HTML in the document should be printed.
public bool ShouldPrintSelectionOnly { get; set; }
Property Value
Remarks
The default value is false
.