1- using OpenQA . Selenium . BiDi . Communication ;
1+ using OpenQA . Selenium . BiDi . Communication ;
2+ using System ;
23using System . Collections . Generic ;
34
45namespace OpenQA . Selenium . BiDi . Modules . BrowsingContext ;
@@ -9,14 +10,13 @@ internal record PrintCommandParameters(BrowsingContext Context) : CommandParamet
910{
1011 public bool ? Background { get ; set ; }
1112
12- public Margin ? Margin { get ; set ; }
13+ public PrintMargin ? Margin { get ; set ; }
1314
14- public Orientation ? Orientation { get ; set ; }
15+ public PrintOrientation ? Orientation { get ; set ; }
1516
16- public Page ? Page { get ; set ; }
17+ public PrintPage ? Page { get ; set ; }
1718
18- // TODO: It also supports strings
19- public IEnumerable < long > ? PageRanges { get ; set ; }
19+ public IEnumerable < PrintPageRange > ? PageRanges { get ; set ; }
2020
2121 public double ? Scale { get ; set ; }
2222
@@ -27,21 +27,20 @@ public record PrintOptions : CommandOptions
2727{
2828 public bool ? Background { get ; set ; }
2929
30- public Margin ? Margin { get ; set ; }
30+ public PrintMargin ? Margin { get ; set ; }
3131
32- public Orientation ? Orientation { get ; set ; }
32+ public PrintOrientation ? Orientation { get ; set ; }
3333
34- public Page ? Page { get ; set ; }
34+ public PrintPage ? Page { get ; set ; }
3535
36- // TODO: It also supports strings
37- public IEnumerable < long > ? PageRanges { get ; set ; }
36+ public IEnumerable < PrintPageRange > ? PageRanges { get ; set ; }
3837
3938 public double ? Scale { get ; set ; }
4039
4140 public bool ? ShrinkToFit { get ; set ; }
4241}
4342
44- public struct Margin
43+ public struct PrintMargin
4544{
4645 public double ? Bottom { get ; set ; }
4746
@@ -52,17 +51,63 @@ public struct Margin
5251 public double ? Top { get ; set ; }
5352}
5453
55- public enum Orientation
54+ public enum PrintOrientation
5655{
5756 Portrait ,
5857 Landscape
5958}
6059
61- public struct Page
60+ public struct PrintPage
6261{
6362 public double ? Height { get ; set ; }
6463
6564 public double ? Width { get ; set ; }
6665}
6766
68- public record PrintResult ( string Data ) ;
67+ public readonly record struct PrintPageRange ( int ? Start , int ? End )
68+ {
69+ public static implicit operator PrintPageRange ( int index ) { return new PrintPageRange ( index , index ) ; }
70+
71+ #if NET8_0_OR_GREATER
72+ public static implicit operator PrintPageRange ( Range range )
73+ {
74+ int ? start ;
75+ int ? end ;
76+
77+ if ( range . Start . IsFromEnd && range . Start . Value == 0 )
78+ {
79+ start = null ;
80+ }
81+ else
82+ {
83+ if ( range . Start . IsFromEnd )
84+ {
85+ throw new NotSupportedException ( $ "Page index from end ({ range . Start } ) is not supported in page range for printing.") ;
86+ }
87+
88+ start = range . Start . Value ;
89+ }
90+
91+ if ( range . End . IsFromEnd && range . End . Value == 0 )
92+ {
93+ end = null ;
94+ }
95+ else
96+ {
97+ if ( range . End . IsFromEnd )
98+ {
99+ throw new NotSupportedException ( $ "Page index from end ({ range . End } ) is not supported in page range for printing.") ;
100+ }
101+
102+ end = range . End . Value ;
103+ }
104+
105+ return new PrintPageRange ( start , end ) ;
106+ }
107+ #endif
108+ }
109+
110+ public record PrintResult ( string Data )
111+ {
112+ public byte [ ] ToByteArray ( ) => Convert . FromBase64String ( Data ) ;
113+ }
0 commit comments