Skip to content

Commit 272186a

Browse files
shbenzerharsha509
andauthored
Added PrintOptions to Documentation (#1987)[deploy site]
* Added PrintOptions to Documentation * Made intro more technical * Update print_page.ja.md * Update print_page.pt-br.md * Update print_page.zh-cn.md --------- Co-authored-by: Sri Harsha <[email protected]>
1 parent d8617ee commit 272186a

File tree

5 files changed

+825
-0
lines changed

5 files changed

+825
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package dev.selenium.interactions;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.openqa.selenium.print.PageMargin;
5+
import org.openqa.selenium.print.PrintOptions;
6+
7+
import dev.selenium.BaseChromeTest;
8+
9+
public class PrintOptionsTest extends BaseChromeTest {
10+
11+
@Test
12+
public void TestOrientation()
13+
{
14+
driver.get("https://www.selenium.dev/");
15+
PrintOptions printOptions = new PrintOptions();
16+
printOptions.setOrientation(PrintOptions.Orientation.LANDSCAPE);
17+
PrintOptions.Orientation current_orientation = printOptions.getOrientation();
18+
}
19+
20+
@Test
21+
public void TestRange()
22+
{
23+
driver.get("https://www.selenium.dev/");
24+
PrintOptions printOptions = new PrintOptions();
25+
printOptions.setPageRanges("1-2");
26+
String[] current_range = printOptions.getPageRanges();
27+
}
28+
29+
@Test
30+
public void TestSize()
31+
{
32+
driver.get("https://www.selenium.dev/");
33+
PrintOptions printOptions = new PrintOptions();
34+
printOptions.setScale(.50);
35+
double current_scale = printOptions.getScale();
36+
}
37+
38+
@Test
39+
public void TestMargins()
40+
{
41+
driver.get("https://www.selenium.dev/");
42+
PrintOptions printOptions = new PrintOptions();
43+
PageMargin margins = new PageMargin(1.0,1.0,1.0,1.0);
44+
printOptions.setPageMargin(margins);
45+
double topMargin = margins.getTop();
46+
double bottomMargin = margins.getBottom();
47+
double leftMargin = margins.getLeft();
48+
double rightMargin = margins.getRight();
49+
}
50+
51+
@Test
52+
public void TestScale()
53+
{
54+
driver.get("https://www.selenium.dev/");
55+
PrintOptions printOptions = new PrintOptions();
56+
printOptions.setScale(.50);
57+
double current_scale = printOptions.getScale();
58+
}
59+
60+
@Test
61+
public void TestBackground()
62+
{
63+
driver.get("https://www.selenium.dev/");
64+
PrintOptions printOptions = new PrintOptions();
65+
printOptions.setBackground(true);
66+
boolean current_background = printOptions.getBackground();
67+
}
68+
69+
@Test
70+
public void TestShrinkToFit()
71+
{
72+
driver.get("https://www.selenium.dev/");
73+
PrintOptions printOptions = new PrintOptions();
74+
printOptions.setShrinkToFit(true);
75+
boolean current_shrink_to_fit = printOptions.getShrinkToFit();
76+
}
77+
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
---
2+
title: "Print Page"
3+
linkTitle: "Print Page"
4+
weight: 7
5+
aliases: [
6+
"/documentation/en/support_packages/print_page/",
7+
]
8+
---
9+
10+
Printing a website is a common requirement, whether for sharing information or archiving records.
11+
Selenium offers a straightforward way to automate this process through the `PrintOptions()` class.
12+
This class provides an intuitive and multifaceted way of printing webpages.
13+
14+
## Orientation
15+
Using the `getOrientation()` and `setOrientation()` methods, you can get/set the page orientation --- either `PORTRAIT` or `LANDSCAPE`.
16+
17+
{{< tabpane text=true >}}
18+
{{< tab header="Java" >}}
19+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java#L14-L20" >}}
20+
{{< /tab >}}
21+
{{< tab header="CSharp" >}}
22+
{{< badge-code >}}
23+
{{< /tab >}}
24+
{{< tab header="Ruby" >}}
25+
{{< badge-code >}}
26+
{{< badge-code >}}
27+
{{< /tab >}}
28+
{{< tab header="Python" >}}
29+
{{< badge-code >}}
30+
{{< /tab >}}
31+
{{< tab header="JavaScript" >}}
32+
{{< badge-code >}}
33+
{{< /tab >}}
34+
{{< tab header="Kotlin" >}}
35+
{{< badge-code >}}
36+
{{< /tab >}}
37+
{{< /tabpane >}}
38+
39+
## Range
40+
Using the `getPageRanges()` and `setPageRanges()` methods, you can get/set the range of pages to print --- e.g. "2-4".
41+
42+
{{< tabpane text=true >}}
43+
{{< tab header="Java" >}}
44+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java#L23-L29" >}}
45+
{{< /tab >}}
46+
{{< tab header="CSharp" >}}
47+
{{< badge-code >}}
48+
{{< /tab >}}
49+
{{< tab header="Ruby" >}}
50+
{{< badge-code >}}
51+
{{< badge-code >}}
52+
{{< /tab >}}
53+
{{< tab header="Python" >}}
54+
{{< badge-code >}}
55+
{{< /tab >}}
56+
{{< tab header="JavaScript" >}}
57+
{{< badge-code >}}
58+
{{< /tab >}}
59+
{{< tab header="Kotlin" >}}
60+
{{< badge-code >}}
61+
{{< /tab >}}
62+
{{< /tabpane >}}
63+
64+
## Size
65+
Using the `getPaperSize()` and `setPaperSize()` methods, you can get/set the paper size to print --- e.g. "A0", "A6", "Legal", "Tabloid", etc.
66+
67+
{{< tabpane text=true >}}
68+
{{< tab header="Java" >}}
69+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java#L32-L38" >}}
70+
{{< /tab >}}
71+
{{< tab header="CSharp" >}}
72+
{{< badge-code >}}
73+
{{< /tab >}}
74+
{{< tab header="Ruby" >}}
75+
{{< badge-code >}}
76+
{{< badge-code >}}
77+
{{< /tab >}}
78+
{{< tab header="Python" >}}
79+
{{< badge-code >}}
80+
{{< /tab >}}
81+
{{< tab header="JavaScript" >}}
82+
{{< badge-code >}}
83+
{{< /tab >}}
84+
{{< tab header="Kotlin" >}}
85+
{{< badge-code >}}
86+
{{< /tab >}}
87+
{{< /tabpane >}}
88+
89+
## Margins
90+
Using the `getPageMargin()` and `setPageMargin()` methods, you can set the margin sizes of the page you wish to print --- i.e. top, bottom, left, and right margins.
91+
92+
{{< tabpane text=true >}}
93+
{{< tab header="Java" >}}
94+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java#L41-L51" >}}
95+
{{< /tab >}}
96+
{{< tab header="CSharp" >}}
97+
{{< badge-code >}}
98+
{{< /tab >}}
99+
{{< tab header="Ruby" >}}
100+
{{< badge-code >}}
101+
{{< badge-code >}}
102+
{{< /tab >}}
103+
{{< tab header="Python" >}}
104+
{{< badge-code >}}
105+
{{< /tab >}}
106+
{{< tab header="JavaScript" >}}
107+
{{< badge-code >}}
108+
{{< /tab >}}
109+
{{< tab header="Kotlin" >}}
110+
{{< badge-code >}}
111+
{{< /tab >}}
112+
{{< /tabpane >}}
113+
114+
## Scale
115+
Using `getScale()` and `setScale()` methods, you can get/set the scale of the page you wish to print --- e.g. 1.0 is 100% or default, 0.25 is 25%, etc.
116+
117+
{{< tabpane text=true >}}
118+
{{< tab header="Java" >}}
119+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java#L54-L60" >}}
120+
{{< /tab >}}
121+
{{< tab header="CSharp" >}}
122+
{{< badge-code >}}
123+
{{< /tab >}}
124+
{{< tab header="Ruby" >}}
125+
{{< badge-code >}}
126+
{{< badge-code >}}
127+
{{< /tab >}}
128+
{{< tab header="Python" >}}
129+
{{< badge-code >}}
130+
{{< /tab >}}
131+
{{< tab header="JavaScript" >}}
132+
{{< badge-code >}}
133+
{{< /tab >}}
134+
{{< tab header="Kotlin" >}}
135+
{{< badge-code >}}
136+
{{< /tab >}}
137+
{{< /tabpane >}}
138+
139+
## Background
140+
Using `getBackground()` and `setBackground()` methods, you can get/set whether background colors and images appear --- boolean `true` or `false`.
141+
142+
{{< tabpane text=true >}}
143+
{{< tab header="Java" >}}
144+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java#L63-L69" >}}
145+
{{< /tab >}}
146+
{{< tab header="CSharp" >}}
147+
{{< badge-code >}}
148+
{{< /tab >}}
149+
{{< tab header="Ruby" >}}
150+
{{< badge-code >}}
151+
{{< badge-code >}}
152+
{{< /tab >}}
153+
{{< tab header="Python" >}}
154+
{{< badge-code >}}
155+
{{< /tab >}}
156+
{{< tab header="JavaScript" >}}
157+
{{< badge-code >}}
158+
{{< /tab >}}
159+
{{< tab header="Kotlin" >}}
160+
{{< badge-code >}}
161+
{{< /tab >}}
162+
{{< /tabpane >}}
163+
164+
## ShrinkToFit
165+
Using `getBackground()` and `setBackground()` methods, you can get/set whether the page will shrink-to-fit content on the page --- boolean `true` or `false`.
166+
167+
{{< tabpane text=true >}}
168+
{{< tab header="Java" >}}
169+
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/PrintOptionsTest.java#L72-L78" >}}
170+
{{< /tab >}}
171+
{{< tab header="CSharp" >}}
172+
{{< badge-code >}}
173+
{{< /tab >}}
174+
{{< tab header="Ruby" >}}
175+
{{< badge-code >}}
176+
{{< badge-code >}}
177+
{{< /tab >}}
178+
{{< tab header="Python" >}}
179+
{{< badge-code >}}
180+
{{< /tab >}}
181+
{{< tab header="JavaScript" >}}
182+
{{< badge-code >}}
183+
{{< /tab >}}
184+
{{< tab header="Kotlin" >}}
185+
{{< badge-code >}}
186+
{{< /tab >}}
187+
{{< /tabpane >}}

0 commit comments

Comments
 (0)