当用户单击GridView(表)中的按钮时,我想在客户端生成PDF。我有一个HTML文件,它将用作PDF的模板,我想用绑定到表的数据中的数据填充HTML中的一些文本。
我已经尝试过jsPDF,但是我不知道如何从现成的HTML文件中创建PDF,以及如何传递数据。
Warnings.aspx
<asp:GridView ID="rmdGV1" runat="server"
DataKeyNames="PROJ_RMLTR_ID"
OnRowDataBound="rmdGV1_RowDataBound"
OnSelectedIndexChanged="rmdGV1_SelectedIndexChanged"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="No.">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PROJ_RMLTR_TITLE" HeaderText="Reminder Letter Title" />
<asp:BoundField DataField="PROJ_RMLTR_TYPE" HeaderText="Letter Type" />
<asp:BoundField DataField="PROJ_RMLTR_REASON" HeaderText="Reason" />
<asp:BoundField DataField="PROJ_RMLTR_ISUDATE" DataFormatString="{0:d}" HeaderText="Date Issued" />
<asp:BoundField DataField="PROJ_RMLTR_ISUBY" HeaderText="Issued By" />
<asp:BoundField DataField="PROJ_RMLTR_REPLY" HeaderText="Replied" />
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Button ID="btnDownloadDoc" runat="server" CommandArgument='<%# Bind("PROJ_RMLTR_ID") %>' Text="Download" OnClientClick="generatePDF();"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Warning.aspx中的脚本
<script type="text/javascript">
function generatePDF() {
var doc = new jsPDF();
doc.text('Hello world!', 10, 10)
doc.save('a4.pdf')
}
</script>
Template.html
<!DOCTYPE html>
<html>
<title>Sample Letter</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
<body>
<div id="content">
<h2 id="title">Subject: PROJ_RMLTR_TITLE</h2>
<p id="detail">You have been issued a warning letter for PROJ_RMLTR_REASON on PROJ_RMLTR_ISUDATE</p>
</div>
</body>
</html>
我希望HTML文件中的PROJ_RMLTR_TITLE将基于Gridview中具有相同字段名称且其他字段也相同的列。