-
Notifications
You must be signed in to change notification settings - Fork 1
/
Index.cshtml
73 lines (72 loc) · 3.43 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
@{
Layout = null;
}
@model T569785.Models.ExportModel
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script type="text/javascript">
function PrintWithiFrame() {
window.open('@Url.Action("Print", "Home")', "PrintingFrame");
var frameElement = document.getElementById("FrameToPrint");
frameElement.addEventListener("load", function (e) {
if (frameElement.contentDocument.contentType !== "text/html")
frameElement.contentWindow.print();
});
}
function PrintInNewWindow() {
var frameElement = window.open('@Url.Action("Print", "Home")', "_blank");
frameElement.addEventListener("load", function (e) {
if (frameElement.document.contentType !== "text/html")
frameElement.print();
});
}
</script>
</head>
<body>
<div>
@using (Html.BeginForm("Export", "Home"))
{
<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 With iFrame" onclick="PrintWithiFrame(); return false;" /> <br />
<b>Note:</b> Printing with an invisible iFrame element is not recommended. Although this solution provides more desktop-like experience, it's not guaranteed to work reliably across all browsers. For example, it won't work in the Edge or Safari browser. <br />
<br />
<input type="button" value="Print New Window" onclick="PrintInNewWindow(); return false;" /> <br />
<b>Note:</b> clicking this button will open a separate tab in the browser. This is the recommented approach.
<iframe id="FrameToPrint" name="PrintingFrame" style="position:absolute; left: -10000px; top: -10000px;"></iframe>
</td>
<td style="vertical-align: top">
@Html.DropDownListFor(m => m.Format, new SelectListItem[] {
new SelectListItem() { Value = "pdf", Text= "Pdf" },
new SelectListItem() { Value = "docx", Text= "Docx" },
new SelectListItem() { Value = "xls", Text= "Xls" },
new SelectListItem() { Value = "xlsx", Text= "Xlsx" },
new SelectListItem() { Value = "rtf", Text= "Rtf" },
new SelectListItem() { Value = "mht", Text= "Mht" },
new SelectListItem() { Value = "html", Text= "Html" },
new SelectListItem() { Value = "txt", Text= "Text" },
new SelectListItem() { Value = "csv", Text= "Csv" },
new SelectListItem() { Value = "png", Text= "Image" }
})
</td>
<td style="vertical-align: top">
<input type="submit" value="Export" />
</td>
</tr>
</table>
}
</div>
</body>
</html>