首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >itextsharp无数据

itextsharp无数据
EN

Stack Overflow用户
提问于 2011-04-01 23:04:00
回答 1查看 1.2K关注 0票数 0

我有一个网格视图与一些数据,我想把它转换成pdf还显示图像从每篇文章,我有pdf格式的白色和绿色的每个单元格,但没有数据上它

我正在使用这段代码

代码语言:javascript
复制
    bool gerarpdf;
    protected void btn_pdf_Click(object sender, ImageClickEventArgs e) 
    { 
        gerarpdf = true; 
    }

    public override void VerifyRenderingInServerForm(Control control) 
    {
        /* Verifies that the control is rendered */     
        /* Necessario para gerar pdf com gridview */    
    }

    protected override void Render(HtmlTextWriter writer)
    {
        if (gerarpdf == true)
        {
            //pdf generation code called here       
            int columns = GridView2.Columns.Count;
            // Table and PdfTable classes removed in version 5.XXX          
            iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(columns);
            // padding can only be set for cells, __NOT__ PdfPTable object     
            int padding = 5; float[] widths = new float[columns]; for (int x = 0; x < columns; x++)
            {
                widths[x] = (float)GridView2.Columns[x].ItemStyle.Width.Value; string cellText = Server.HtmlDecode(GridView2.HeaderRow.Cells[x].Text);
                // Cell and Color classes are gone too                     
                iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new iTextSharp.text.Phrase(cellText)) { BackgroundColor = new iTextSharp.text.BaseColor(System.Drawing.ColorTranslator.FromHtml("#008000")), Padding = padding }; table.AddCell(cell);
            }
            // next two lines set the table's __ABSOLUTE__ width     
            table.SetTotalWidth(widths); table.LockedWidth = true; for (int i = 0; i < columns; i++) { if (GridView2.Rows[i].RowType == DataControlRowType.DataRow) { for (int j = 0; j < columns; j++) { string cellText = Server.HtmlDecode(GridView2.Rows[i].Cells[j].Text); iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new iTextSharp.text.Phrase(cellText)) { Padding = padding }; if (i % 2 != 0) { cell.BackgroundColor = new iTextSharp.text.BaseColor(System.Drawing.ColorTranslator.FromHtml("#C2D69B")); } table.AddCell(cell); } } } Response.ContentType = "application/pdf"; iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10f, 10f, 10f, 0f); iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); pdfDoc.Add(table); pdfDoc.Close(); Response.End();
        }
        else
        {
            //let page render normally     
            base.Render(writer);
        }
    }

需要paggin选项我在这里找到了一个demoe,但我不知道在这里把它放到我的代码http://archive.aspsnippets.com/demos/GridView2PDF.aspx

我需要的是类似于此,但也与包装http://www.aspsnippets.com/Articles/Export-GridView-with-Images-to-Word-Excel-and-PDF-Formats-in-ASP.Net.aspx

EN

回答 1

Stack Overflow用户

发布于 2011-04-02 00:56:40

有一次,我不得不做的工作,从数据库中提取数据,并生成Word和PDF文件和后,我来到了一个很棒的事情,有很大的帮助和方便,到use.You可以转换你的表格,你只需要取消列,然后添加你想要的行,加上你可以添加样式到表格too.Page格式是同样容易,页眉,页脚,每件事都很容易。

这是链接PDFsharp & MigraDoc

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5515190

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档