Question Locked

ASPX to PDF conversion image path problem

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

HI i am trying to convert aspx to pdf but while converting if images are on aspx page means its searching the images path on hard disk instead of serching on root directory ...and if i place the images on specified path like F:\img.jpg then its not giving any problem...so please let me know if any good answer/solution for this issue...i am using following code to solve the above issue

string attachment = "attachment; filename=Article.pdf";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/pdf";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
form1.RenderControl(htextw);// (this is the error part)
Document document = new Document();
PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
//iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(imagepath + "/mikesdotnetting.gif");
StringReader str = new StringReader(stw.ToString());
HTMLWorker htmlworker = new HTMLWorker(document);
htmlworker.Parse(str);//Here is the error
document.Close();
Response.Write(document);
Response.End();

please give soltion waiting for reply..many thanks in advance

2 replies

by robo_dev

e.g.:
string imagepath = Server.MapPath("Images");

And imagepath depends on the Server.MapPath method.

Don't forget that the Server.MapPath method is relative or absolute depending on whether there's a slash there or not.

Server.MapPath Method
"Specifies the relative or virtual path to map to a physical directory. If Path starts with either a forward (/) or backward slash (\), the MapPath method returns a path as if Path were a full, virtual path. If Path doesn't start with a slash, the MapPath method returns a path relative to the directory of the .asp file being processed."

http://msdn.microsoft.com/en-us/library/ms524632%28v=vs.90%29.aspx

This discussion is closed to new replies.