我在此处关注此链接,了解如何在 asp.net 中将 html 表创建为 pdf
我按照示例代码将其连接到我的按钮事件处理程序,当我单击它时,会在相应的文件目录中自动生成 pdf 文件。但是当我第二次点击它时,它说我的文件名 pdf 已被使用。我检查了文件目录,确实有一个 pdf 文件正在生成。当我第二次单击按钮时,如何停止复制 pdf 文件。我正在尝试将我的 html 表格数据转换为 pdf 格式。我想知道我是否遵循正确的来源。
尝试的示例代码:
protected void Button1_Click(object sender, EventArgs e)
{
var document = new Document(PageSize.A4, 50, 50, 25, 25);
var output = new FileStream(Server.MapPath("MyFirstTestPDF.pdf"), FileMode.Create);
var writer = PdfWriter.GetInstance(document, output);
document.Open();
var welcomeParagraph = new Paragraph("Hello, World!");
document.Add(welcomeParagraph);
document.Close();
}
我在 asp.net 中的 html 表
<ul id="Report">
Case ID :
<asp:DropDownList ID="DDLCase" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DDLCase_SelectedIndexChanged"
AppendDataBoundItems="true" >
<asp:ListItem Value="-1">Select Member Report ID</asp:ListItem>
</asp:DropDownList>
<table style="width: 100%; height: 576px;">
<tr>
<th style="width: 98px; height: 49px;">Full Name :</th>
<td style="width: 351px; height: 49px; text-align: left;">
<asp:Label ID="lblFullName" runat="server" Text=""></asp:Label>
</td>
<th style="height: 49px; width: 76px">Contact :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblContact" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 98px">Location :</th>
<td style="width: 351px; height: 49px; text-align: left;">
<asp:Label ID="lblLocation" runat="server" Text=""></asp:Label>
</td>
<th style="width: 76px">Type of Crime :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblTOC" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 98px">Picture : </th>
<td style="width: 351px; height: 49px; text-align: left;">
<asp:Label ID="lblPicture" runat="server" Text=""></asp:Label>
</td>
<th style="width: 76px">Citizen Report Date & Time :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblCRDT" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 98px">AssignTo :</th>
<td style="width: 351px; height: 49px; text-align: left;">
<asp:Label ID="lblAssign" runat="server" Text=""></asp:Label>
</td>
<th style="width: 76px">Police Report Date & Time :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblPRDT" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 98px; height: 100px;">Citizen Report :</th>
<td colspan="4" style="height: 100px" text-align:"left">
<asp:Label ID="lblCR" runat="server" Text="" style="display: block; text-align: left;"></asp:Label>
</td>
</tr>
<tr>
<th style="width: 98px; height: 135px;">Police Report :</th>
<td colspan="4" style="height: 135px" text-align: "left">
<asp:Label ID="lblPR" runat="server" Text="" style="display: block; text-align: left;"></asp:Label>
</td>
</tr>
<tr>
<th style="width: 98px; height: 135px;">Official Report :</th>
<td colspan="4" style="height: 135px" text-align: "left">
<asp:Label ID="lblOR" runat="server" Text="" style="display: block; text-align: left;"></asp:Label>
</td>
</tr>
</table>