使用iTextSharp创建pdf文件时出错

时间:2013-12-18 22:32:06

标签: c# asp.net pdf itextsharp

我的asp .Net项目(c#)中有一个Gridview,我想将其导出为pdf 为此目的我正在使用iTextSharp:

public override void VerifyRenderingInServerForm(Control control)

{ /* Do nothing */ }

protected void Button2_Click1(object sender, EventArgs e)
{

    Response.Clear(); //this clears the Response of any headers or previous output
    Response.Buffer = true; //ma
    Response.ContentType = "application/pdf";

    Response.AddHeader("content-disposition", "attachment;filename=DataTable.pdf");

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    StringWriter sw = new StringWriter();

    HtmlTextWriter hw = new HtmlTextWriter(sw);

    ASPxGridView1.RenderControl(hw);

    StringReader sr = new StringReader(sw.ToString());

    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);

    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

    pdfDoc.Open();

    htmlparser.Parse(sr);

    pdfDoc.Close();

    Response.Write(pdfDoc);

    Response.End();  



}

当我测试它时,我收到此错误:

  

UNC路径的格式应为\ server \ share

有人请帮帮我吗?

0 个答案:

没有答案