| 182 | } |
| 183 | |
| 184 | private static printContentInNewWindow( |
| 185 | content: string, |
| 186 | options: PrintOptions |
| 187 | ): Promise<void> { |
| 188 | return new Promise((resolve, reject) => { |
| 189 | const printWindow = window.open("", "_blank") |
| 190 | if (!printWindow) { |
| 191 | reject(new Error("Unable to open print window")) |
| 192 | return |
| 193 | } |
| 194 | |
| 195 | printWindow.document.open() |
| 196 | printWindow.document.write(options.doctype + content) |
| 197 | printWindow.document.close() |
| 198 | |
| 199 | printWindow.onload = () => { |
| 200 | try { |
| 201 | printWindow.focus() |
| 202 | printWindow.print() |
| 203 | printWindow.close() |
| 204 | resolve() |
| 205 | } catch (error) { |
| 206 | reject(error) |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | setTimeout(() => { |
| 211 | printWindow.print() |
| 212 | printWindow.close() |
| 213 | resolve() |
| 214 | }, options.timeout) |
| 215 | }) |
| 216 | } |
| 217 | } |