Click here to Skip to main content
15,903,030 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
   protected void btnPDF_Click1(object sender, ImageClickEventArgs e)
    {


        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView1.AllowPaging = false;
        GridView1.DataBind();
        GridView1.RenderControl(hw);
        GridView1.HeaderRow.Style.Add("width", "15%");
        GridView1.HeaderRow.Style.Add("font-size", "10px");
        GridView1.Style.Add("text-decoration", "none");
        GridView1.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
        GridView1.Style.Add("font-size", "8px");
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

        pdfDoc.Open();
       htmlparser.Parse(sr);  ///////////error came here
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
    }
    protected string GetUrl(string uploadimage)
    {
        string[] splits = Request.Url.AbsoluteUri.Split('/');
        if (splits.Length >= 2)
        {
            string url = splits[0] + "//";
            for (int i = 2; i < splits.Length - 1; i++)
            {
                url += splits[i];
                url += "/";
            }
            return url + uploadimage;
        }
        return uploadimage;
    }
}
Posted
Updated 9-Oct-14 19:58pm
v3
Comments
Member 10918596 10-Oct-14 2:14am    
Asp.net Export WebPage with Images to PDF using iTextSharp in C#
King Fisher 10-Oct-14 2:20am    
What's Your Question ?Update it,we can't Get what you think.
Sinisa Hajnal 10-Oct-14 2:32am    
I'd say the folder does not exist on the server or the process does not have write permission on it. Try it.
Member 10918596 10-Oct-14 2:27am    
autually my task is asp.net Export WebPage with Images to PDF using iTextSharp in C#
but i got error Could not find a part of the path 'C:\userimage\MAHA MITTAI.jpg'.
Member 10918596 10-Oct-14 2:28am    
My asp.code

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="624px" CssClass="grid"
AllowPaging="True" AllowSorting="True" BackColor="White" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" PageSize = "5"
OnRowUpdating="GridView1_RowUpdating" DataKeyNames="id">

<columns> <asp:TemplateField>
<itemtemplate>
<asp:CheckBox ID="chkchild" runat="server" AutoPostBack="true" />


<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="username" HeaderText="username" SortExpression="username" />
<asp:BoundField DataField="password" HeaderText="password" SortExpression="password" />
<asp:BoundField DataField="mail" HeaderText="mail" SortExpression="mail" />

<asp:BoundField DataField="imagename" HeaderText="imagename" SortExpression="imagename" />
<
<asp:ImageField DataImageUrlField="uploadimage" HeaderText="uploadimage" ControlStyle-Width = "80" ControlStyle-Height = "100">
<controlstyle height="100px" width="80px">


<asp:CommandField ShowEditButton="True" />



<footerstyle backcolor="White" forecolor="#000066">
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<rowstyle forecolor="#000066">
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<sortedascendingcellstyle backcolor="#F1F1F1">
<sortedascendingheaderstyle backcolor="#007DBB">
<sorteddescendingcellstyle backcolor="#CAC9C9">
<sorteddescendingheaderstyle backcolor="#00547E">

1 solution

Quote:
Could not find a part of the path 'C:\userimage\MAHA MITTAI.jpg
That means either the image is not present in that path or you don't have permission to operate on the file.

Please go through the below articles to know how to deal with images using iTextSharp.
1. iTextSharp - Working with images[^]
2. Asp.net Export WebPage with Images to PDF using iTextSharp in C#, VB.NET[^]
3. How to use image in PDF document in ASP.NET with C# using iTextSharp[^]
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900