无法加载由itextsharp生成的pdf文件

时间:2016-09-09 17:29:09

标签: c# asp.net itext

我在生成正确的PDF文档时遇到错误。我有的代码,可以生成一个pdf文件,它可以下载文件,但问题是我无法查看文件的视图。这是我试图导出为pdf的页面。

Image

到目前为止,这是我的代码:

ASPX:

<asp:Button ID="btnDownload" CssClass="btn" runat="server" Text="Download Invoice" OnClick="btnDownload_Click" />
<asp:Panel ID="pnl" runat="server">
    <div id="page-wrap">

        <textarea id="header" style="height: 30px">PAYMENT DETAILS</textarea>
        <div id="identity">
            <textarea style="background-color: #F7F7F7;" readonly="readonly" id="address">My Name
My Street Address

Phone: 111-111-111</textarea>
            <div id="logo">
                <div id="logoctr">

                </div>

                <div id="logohelp">
                    <input id="imageloc" readonly="readonly" type="text" size="50" value="" /><br />
                    (max width: 540px, max height: 100px)

                </div>
                <img id="image" src="images/logo.png" alt="logo" />
            </div>

        </div>

        <div style="clear: both"></div>

        <div id="customer">

            <textarea id="tbCustomer" readonly="readonly" runat="server"></textarea>

            <table id="meta">
                <tr>
                    <td class="meta-head">Payment ID</td>
                    <td>
                        <textarea readonly="readonly" runat="server" id="tbPID"></textarea></td>
                </tr>
                <tr>

                    <td class="meta-head">Date</td>
                    <td>
                        <textarea id="date" readonly="readonly" runat="server"></textarea></td>
                </tr>
                <tr>
                    <td class="meta-head">Amount Due</td>
                    <td>
                        <div class="due">
                            $
                        <asp:Label ID="lblTotal" runat="server" Text="Total"></asp:Label>
                        </div>
                    </td>
                </tr>

            </table>

        </div>

        <table id="items">

            <tr>
                <th>Property Title</th>
                <th>Description</th>
                <th>Status</th>
                <th>Invoiced By</th>
                <th>Total Payment</th>
            </tr>

            <tr class="item-row">
                <td class="item-name">
                    <div class="delete-wpr">
                        <textarea readonly="readonly" id="tbTitle" runat="server"></textarea>
                    </div>
                </td>
                <td class="description">

                    <div contenteditable="true" id="tbDetail" class="blank" runat="server">
                    </div>
                </td>
                <td>
                    <textarea id="tbStatus" runat="server" readonly="readonly">PAID</textarea></td>
                <td>
                    <textarea class="qty" readonly="readonly" id="tbInvoicedBy" runat="server"></textarea></td>
                <td><span class="price">$
                <asp:Label ID="tbTotal1" runat="server" Text="Total"></asp:Label></span></td>
            </tr>


            <tr>
                <td colspan="2" class="blank"></td>
                <td colspan="2" class="total-line">Vaccant</td>
                <td class="total-value">
                    <div id="subtotal">$<asp:Label ID="lblVaccant" runat="server" Text=""></asp:Label></div>
                </td>
            </tr>
            <tr>

                <td colspan="2" class="blank"></td>
                <td colspan="2" class="total-line">Maintainance</td>
                <td class="total-value">
                    <div id="total">$<asp:Label ID="lblMaintainance" runat="server" Text=""></asp:Label></div>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="blank"></td>
                <td colspan="2" class="total-line">Property Insurance</td>

                <td class="total-value">
                    <div id="Insurance">$<asp:Label ID="lblInsurance" runat="server" Text=""></asp:Label></div>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="blank"></td>
                <td colspan="2" class="total-line">Dewa Bill</td>

                <td class="total-value">
                    <div id="dewa">$<asp:Label ID="lblDewa" runat="server" Text=""></asp:Label></div>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="blank"></td>
                <td colspan="2" class="total-line">Furnishing Cost</td>

                <td class="total-value">
                    <div id="FurnishingCost">$<asp:Label ID="lblFurnishing" runat="server" Text=""></asp:Label></div>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="blank"></td>
                <td colspan="2" class="total-line">Cleaning Fees</td>

                <td class="total-value">
                    <div id="CleaningFees">$<asp:Label ID="lblCleaning" runat="server" Text=""></asp:Label></div>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="blank"></td>
                <td colspan="2" class="total-line">House Keeping</td>

                <td class="total-value">
                    <div id="HouseKeeping">$<asp:Label ID="lblHouseKeeping" runat="server" Text=""></asp:Label></div>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="blank"></td>
                <td colspan="2" class="total-line">Next Rent Due</td>

                <td class="total-value">
                    <div id="paid">$<asp:Label ID="lblNextRent" runat="server" Text=""></asp:Label></div>
                </td>
            </tr>


            <tr>
                <td colspan="2" class="blank"></td>
                <td colspan="2" class="total-line">Rental Comission</td>

                <td class="total-value">
                    <div id="RentalComission">$<asp:Label ID="lblRentalComission" runat="server" Text=""></asp:Label></div>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="blank"></td>
                <td colspan="2" class="total-line">Credit Card Fees</td>

                <td class="total-value">
                    <div id="CreditCardFees">$<asp:Label ID="lblCreditCardFees" runat="server" Text=""></asp:Label></div>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="blank"></td>
                <td colspan="2" class="total-line">Pest Control</td>

                <td class="total-value">
                    <div id="PestControl">$<asp:Label ID="lblPestControl" runat="server" Text=""></asp:Label></div>
                </td>
            </tr>


            <tr>
                <td colspan="2" class="blank"></td>
                <td colspan="2" class="total-line">Chillar Utilities</td>

                <td class="total-value">
                    <div id="ChillarUtilities">$<asp:Label ID="lblChillarUtilities" runat="server" Text=""></asp:Label></div>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="blank"></td>
                <td colspan="2" class="total-line">Du, etisilate wifi</td>

                <td class="total-value">
                    <div id="DuEtisilatewifi">$<asp:Label ID="lblDuEtisilateWifi" runat="server" Text=""></asp:Label></div>
                </td>
            </tr>


            <tr>
                <td colspan="2" class="blank"></td>
                <td colspan="2" class="total-line balance">Total Payment</td>
                <td class="total-value balance">
                    <div class="due">$<asp:Label ID="lblTotal2" runat="server" Text=""></asp:Label></div>
                </td>
            </tr>

        </table>

        <div id="terms">
            <h5>Terms</h5>
            <textarea readonly="readonly">These payment details are final and non negotiable.</textarea>
        </div>

    </div>
</asp:Panel>

ASPX.CS

public void ExportToPDF()
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        pnl.RenderControl(hw);
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        sw.Close();
        htmlparser.Close();
        Response.Write(pdfDoc);
        Response.End();
    }

它也说HTMLWorker类已经过时了。

0 个答案:

没有答案