Click here to Skip to main content
15,905,912 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want to export text and image to Pdf file.I use asp.net image control but I can't export it.My code occur exception(not find image file path and htmlparser cannot parse image URL).Please quickly answer me.Give me a way to convenient me how to do it. asp.net with vb codes.
My source code is following.Unhandle exception error occur as "Could not find a part of the path 'C:\Images\Students Photo\images10.jpg'"
Protected Sub btnReport_Click(sender As Object, e As EventArgs) Handles btnReport.Click
       Using sw As New StringWriter()
           Using hw As New HtmlTextWriter(sw)
               viewReport.RenderControl(hw)
               Dim sr As New StringReader(sw.ToString())
               Dim pdfDoc As New Document(PageSize.A2, 10.0F, 10.0F, 100.0F, 0.0F)
               Dim htmlparser As New HTMLWorker(pdfDoc)
               PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
               pdfDoc.Open()
               htmlparser.Parse(sr)
               pdfDoc.Close()
               Response.ContentType = "application\pdf"
               Response.AddHeader("content-disposition", "attachment;filename=profile.pdf")
               Response.Write(pdfDoc)
               Response.End()
           End Using
       End Using
   End Sub
Posted
Updated 16-Jan-14 22:34pm
v3

Here is the code for adding image logo into pdf. in app settings you have to mention the path of logo.


string HeaderImagePath = ConfigurationManager.AppSettings["PdfHeader"].ToString();
iTextSharp.text.Image headerLogo = iTextSharp.text.Image.GetInstance(HeaderImagePath);

headerCell = new PdfPCell(headerLogo);
headerCell.BorderWidth = 0;
headerCell.HorizontalAlignment = Element.ALIGN_CENTER;
headerCell.VerticalAlignment = Element.ALIGN_MIDDLE;
tblHeader.AddCell(headerCell);
 
Share this answer
 
Comments
Member 10220152 17-Jan-14 4:23am    
Thank my senior.I want to show image as student profile image.I want to get it as student certification, so I can't set it as default logo.Please help me.
The best is to use iTextSharp.DLL, which converts HTML pages as it is in PDF format.
 
Share this answer
 

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