如何在asp.net中创建发票

时间:2015-10-20 00:37:09

标签: c# asp.net invoice

我唯一需要的是在顶部和今天的日期添加公司名称,但现在其他一切都在为我工作。用户可以选择特定的行并以pdf格式导出所选行,但我需要顶部的公司名称请帮忙。感谢

 protected void ExportToPDF(object sender, EventArgs e)
    {


      using (StringWriter sw = new StringWriter())
      {
        using (HtmlTextWriter hw = new HtmlTextWriter(sw))
        {

          //Hide the Column containing CheckBox
          GridView1.Columns[0].Visible = false;
          foreach (GridViewRow row in GridView1.Rows)
          {
            if (row.RowType == DataControlRowType.DataRow)
            {
              //Hide the Row if CheckBox is not checked
              row.Visible = (row.FindControl("chkSelect") as CheckBox).Checked;
              // pnlBtn.Visible = true;
            }
          }

          GridView1.RenderControl(hw);
          StringReader sr = new StringReader(sw.ToString());
          Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
          HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
          PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
          pdfDoc.Open();
          htmlparser.Parse(sr);
          pdfDoc.Close();

          Response.ContentType = "application/pdf";
          Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
          Response.Cache.SetCacheability(HttpCacheability.NoCache);
          Response.Write(pdfDoc);
          Response.End();
        }
      }

    }

1 个答案:

答案 0 :(得分:1)

我认为你只需要在渲染gridview之前编写标题。

hw.Write("<H1>This is my title</H1>");
GridView1.RenderControl(hw);