Click here to Skip to main content
13,045,641 members (68,831 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hey All ..

when i try to export Datalist or gridview to pdf..ie exported without images !!!

this is my code :

Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition",
         "attachment;filename=Products.pdf");
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
 
        DataList1.DataBind();
        
        DataList1.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();
Posted 8-Jul-11 2:54am
Updated 20-Feb-17 23:42pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You may need to make sure that your images are referenced by absolute and not relative paths in your html. This is due to the fact that most pdf writers create a temporary copy of your html input in a temp directory before parsing which then causes the relative paths to fail.
  Permalink  
Comments
shms_rony 8-Jul-11 9:05am
   
datalist images get from path in database
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Try This:-

iTextSharp.text.Table table = new iTextSharp.text.Table(grdCust_accot_stmt.Columns.Count);
        table.Cellpadding = 2;
        table.Width = 100;
        grdCust_accot_stmt.AllowPaging = false;
        this.grd_Account_stmt();       
        //Transfer rows from GridView to table
        for (int i = 0; i < grdCust_accot_stmt.Columns.Count; i++)
        {
            string cellText = Server.HtmlDecode(grdCust_accot_stmt.Columns[i].HeaderText); 
            iTextSharp.text.Cell cell = new iTextSharp.text.Cell(cellText);
            cell.BackgroundColor = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml("#e8eff3"));
            table.AddCell(cell);
        }
 
        for (int i = 0; i < grdCust_accot_stmt.Rows.Count; i++)
        {
            if (grdCust_accot_stmt.Rows[i].RowType == DataControlRowType.DataRow)
            {
                for (int j = 0; j < grdCust_accot_stmt.Columns.Count; j++)
                {
                    string cellText = Server.HtmlDecode
                                      (grdCust_accot_stmt.Rows[i].Cells[j].Text);
                    iTextSharp.text.Cell cell = new iTextSharp.text.Cell(cellText);
 
                    //Set Color of Alternating row
                    if (i % 2 != 0)
                    {
                        cell.BackgroundColor = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml("#e8eff3"));
                    }
                    table.AddCell(cell);
                }
            }
        }
        Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 10f);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        pdfDoc.Add(table);
        pdfDoc.Close();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;" +"filename=Reports.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Write(pdfDoc);
        Response.End();
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Here is an article that explains how: iTextBox - Convert datalist and image in PDF[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 21 Feb 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100