OpenXMl倒出word、PDF
OpenXMl倒出word、PDF
@using MarkdownSharp
@{
ViewBag.Title = "预览";
Layout = "~/Views/Shared/_Layout.cshtml";
var lineText = ViewBag.StrContent;
}
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/Index.css" rel="stylesheet" />
<script src="~/Content/marked.js"></script>
<body>
<ul>
<li><a href="#" onclick="ExportWord()">导出Word</a></li>
<li><a href="#" onclick="ExportPdf()">导出PDF</a></li>
</ul>
<div class="row home-div-list">
<div id="content">@Html.Raw(HttpUtility.HtmlDecode(lineText))</div>
</div>
</body>
<script>
function ExportPdf() {
html2canvas($('#contentId'), {
height: 5000,
onrendered: function (canvas) {
var imgData = canvas.toDataURL('img/notice/png');
var doc = new jsPDF('p', 'px', 'a3');
//第一列 左右边距 第二列上下边距 第三列是图片左右拉伸 第四列 图片上下拉伸
doc.addImage(imgData, 'PNG', -9, 0, 650, 1500);
doc.addPage();
doc.addImage(imgData, 'PNG', -9, -900, 650, 1500);
doc.save('test.pdf');
}
});
}
//$(document).ready(function () {
// var regularImages = $('#contentId').find("img");
// var canvas = document.createElement('canvas');
// var ctx = canvas.getContext('2d');
// regularImages.each(function () {
// // preparing canvas for drawing
// var imgElement = this;
// ctx.clearRect(0, 0, canvas.width, canvas.height);
// canvas.width = imgElement.naturalWidth;
// canvas.height = imgElement.naturalHeight;
// ctx.drawImage(imgElement, 0, 0);
// var dataURL = canvas.toDataURL();
// $(imgElement).attr('src', dataURL);
// });
// canvas.remove();
//});
//function ExportWord() {
// var content = $('#contentId').html();
// var converted = htmlDocx.asBlob(content);
// saveAs(converted, 'aa.docx');
//}
</script>
滴水能把石穿透,成事功到自然成