Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 使用iTextSharp将2个GridView合并为一个生成的PDF文件_Asp.net_Gridview_Itextsharp - Fatal编程技术网

Asp.net 使用iTextSharp将2个GridView合并为一个生成的PDF文件

Asp.net 使用iTextSharp将2个GridView合并为一个生成的PDF文件,asp.net,gridview,itextsharp,Asp.net,Gridview,Itextsharp,我使用的是2个GridView。第一个已启用分页,并且每页允许的行数为1。第二个gridview将第一行中的值作为时间范围,每次我在gridview上更改页面时,第二个GV都会根据GV1的值自动更改其内容 以前,我能够使用iTextSharp生成一个PDF文件,只有一个gridview,并且没有启用分页。但现在我首先要努力实现分页功能,其次要将两个GridView合并到一个pdf文件中 有人知道我怎么做吗 提前谢谢 编辑:这是我使用iTextSharp从gridview生成PDF文件的代码 us

我使用的是2个GridView。第一个已启用分页,并且每页允许的行数为1。第二个gridview将第一行中的值作为时间范围,每次我在gridview上更改页面时,第二个GV都会根据GV1的值自动更改其内容

以前,我能够使用iTextSharp生成一个PDF文件,只有一个gridview,并且没有启用分页。但现在我首先要努力实现分页功能,其次要将两个GridView合并到一个pdf文件中

有人知道我怎么做吗

提前谢谢

编辑:这是我使用iTextSharp从gridview生成PDF文件的代码

using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;

StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
gvReportes.AllowPaging = false;
gvReportes.HeaderRow.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
gvReportes.HeaderRow.Style.Add("font-size", "7.20px");
gvReportes.HeaderRow.Style.Add("color", "#284775");
gvReportes.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
gvReportes.Style.Add("font-size", "6px");
gvReportes.RenderControl(htextw);
Document document = new Document();
string path = "path.pdf";
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(path, FileMode.Create));
document.Open();
StringReader str = new StringReader(stw.ToString());
HTMLWorker htmlworker = new HTMLWorker(document);
htmlworker.Parse(str);
Response.Write(document);
document.Close();
这就是GridView的显示方式,您可以看到GV1上的值“Salida”和“Llegada”作为时间范围在GV2上显示数据

protected void Button1_Click(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=injoin.pdf");

        Response.Cache.SetCacheability(HttpCacheability.NoCache);

        StringWriter sw = new StringWriter();

        HtmlTextWriter hw = new HtmlTextWriter(sw);

        GridView1.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();  

    }

您需要为其他人发布一些代码来帮助您。还指出代码的哪个部分没有按预期工作。请考虑添加更多的解释而不是代码。