0

asp.netでhtmlテーブルをpdfに作成する方法については、こちらのリンクをたどりました

サンプル コードに従って、ボタン イベント ハンドラーに接続しました。クリックすると、それぞれのファイル ディレクトリに pdf ファイルが自動的に生成されます。しかし、もう一度クリックすると、ファイル名 pdf が使用されたと表示されます。ファイルディレクトリを確認したところ、実際に生成されているpdfファイルがあります。ボタンを 2 回目にクリックしたときに、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 &amp; 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 &amp; 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&nbsp; 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&nbsp; 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>
4

1 に答える 1

2

ドキュメントを閉じましたか?

// Close the Document - this saves the document contents to the output stream
document.Close(); 
于 2013-06-03T02:20:05.197 に答える