-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIndex.cshtml
73 lines (65 loc) · 2.71 KB
/
Index.cshtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@model ReportingAspNetCorePrintWithoutPreview.Models.ExportModel
<script src="~/js/FileSaver.js"></script>
<script type="text/javascript">
var selectedFormat = "PDF";
function onChange(val) {
selectedFormat = val;
}
function PrintInNewWindow() {
var frameElement = window.open("api/Export/Print", "_blank");
frameElement.addEventListener("load", function (e) {
if (frameElement.document.contentType !== "text/html")
frameElement.print();
});
}
function PrintInIframe() {
var iframe = document.getElementById('printFrame');
if (iframe.contentDocument.contentType !== "text/html")
iframe.contentWindow.print();
}
function DownloadFile() {
fetch("api/Export/Export?format=" + selectedFormat)
.then(response => response.blob())
.then(data => {
saveAs(data, 'TestReport.' + selectedFormat.toLowerCase());
});
}
</script>
<table style="text-align: center; border-collapse: collapse">
<tr style="border-bottom: 1pt solid black">
<td style="width: 150px">
PDF-based Printing
</td>
<td style="width: 150px" colspan="2">
Exporting
</td>
</tr>
<tr>
<td width="500px">
<input type="button" value="Print in iFrame" onclick="PrintInIframe()" /> <br />
<b>Note:</b>Printing with an invisible iFrame element is not recommended because not all browsers support this method. <br />
<br />
<input type="button" value="Print in New Window" onclick="PrintInNewWindow()" /> <br />
<b>Note:</b>Invokes a new window that contains a PDF file and prints the window content. This is the recommended method.
<iframe id="printFrame" name="printFrameName" src="api/Export/Print" title="Print" frameorder="0" width="1" height="1" style={{ position: "absolute", top: "-100px" }}>
</iframe>
</td>
<td style="vertical-align: top">
<select name="exportFormat" onChange=onChange(this.value)>
<option>PDF</option>
<option>DOCX</option>
<option>XLS</option>
<option>XLSX</option>
<option>RTF</option>
<option>MHT</option>
<option>HTML</option>
<option>TXT</option>
<option>CSV</option>
<option>PNG</option>
</select>
</td>
<td style="vertical-align: top">
<input type="button" value="Export" onclick="DownloadFile()" />
</td>
</tr>
</table>