开发者

itextsharp no data

i have a gridview with some data and i want to transform it to pdf also showing images from each article and i have the pdf formatted white and green each cell but no data on it

i'm using this code

    bool gerarpdf;
    protected void btn_pdf_Click(object sender, ImageClickEventArgs e) 
    { 
        gerarpdf = true; 
    }

    public override void VerifyRenderingInServerForm(Control control) 
    {
        /* V开发者_运维问答erifies 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);
        }
    }

need with paggin option i found a demoe here but i dont know here to put it into my code http://archive.aspsnippets.com/demos/GridView2PDF.aspx

what i need is sothinng similar to this but also with pagging http://www.aspsnippets.com/Articles/Export-GridView-with-Images-to-Word-Excel-and-PDF-Formats-in-ASP.Net.aspx


Once i had to do the job to Fetch Datafrom database and generate Word and PDF documents and after alot of RND i came to a thing that was awesome with great Help and ease to use.You can convert you tables to the tables in PDF you just have to decelare columns and then add as many rows as you want Plus you can add Styles to the table too.Page formatting is equally easy header footer every thing is easy.

Here is the Link PDFsharp & MigraDoc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜