|
| 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