我在这里关注如何在asp.net
中创建hf表到pdf的link我按照示例代码将其连接到我的按钮事件处理程序,当我单击它时,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>
答案 0 :(得分:2)
你关闭了文件吗?
// Close the Document - this saves the document contents to the output stream
document.Close();