Click here to Skip to main content
15,894,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
Hai,
When I am trying to convert a HTML to Word, if my HTML contains only one image, it is displaying. But not, when my HTML contains more than one images. All the images are displayed as cross marks. Please help me to over come this issue.

My Code Snippet:

XML
string strImgCandidate = "";
string strImgWork1 = "";
string strImgWork2 = "";
string strImgWork3 = "";
strImgCandidate = Convert.ToString(imgCandidate.Src);
strImgWork1 = Convert.ToString(imgWork1.Src);
strImgWork2 = Convert.ToString(imgWork2.Src);
strImgWork3 = Convert.ToString(imgWork3.Src);
string strImageHeight = Convert.ToString(ConfigurationSettings.AppSettings["PreviewPDFImageHeight"]);
string strImageWidth = Convert.ToString(ConfigurationSettings.AppSettings["PreviewPDFImageWidth"]);
string candImg = "<img alt=\"candidate\" src=" + strImgCandidate + " width=\"" + strImageWidth + "\" height=\"" + strImageHeight + "\" />";
string wrkImg1 = "<img alt=\"test1\" id=\"imgtest1\" src=" + strImgWork1 + " width=\"" + strImageWidth + "\" height=\"" + strImageHeight + "\" />";
string wrkImg2 = "<img alt=\"test2\" id=\"imgtest2\" src=" + strImgWork2 + " width=\"" + strImageWidth + "\" height=\"" + strImageHeight + "\" />";
string wrkImg3 = "<img alt=\"test3\" id=\"imgtest3\" src=" + strImgWork3 + " width=\"" + strImageWidth + "\" height=\"" + strImageHeight + "\" />";
string candImg = "<img alt=\"candidate\" src=" + strImgCandidate + " style=\"height:250px; width:200px;\" />";
string wrkImg1 = "<img alt=\"test1\" id=\"imgtest1\" src=" + strImgWork1 + " style=\"height:350px; width:300px;\" />";
string wrkImg2 = "<img alt=\"test2\" id=\"imgtest2\" src=" + strImgWork2 + " style=\"height:350px; width:300px;\" />";
string wrkImg3 = "<img alt=\"test3\" id=\"imgtest3\" src=" + strImgWork3 + " style=\"height:350px; width:300px;\" />";
if (strImgCandidate != "")
lblimgCandidate.Text = candImg;
if (strImgWork1 != "")
lblimgWork1.Text = wrkImg1;
if (strImgWork2 != "")
lblimgWork2.Text = wrkImg2;
if (strImgWork3 != "")
lblimgWork3.Text = wrkImg3;
SaveToPdf();
string attachment = "attachment; filename=MyProfile.pdf";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/pdf";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
lblimgCandidate.Visible = true;
lblimgWork1.Visible = true;
lblimgWork2.Visible = true;
lblimgWork3.Visible = true;
lblimgCandidate.Visible = false;
lblimgWork1.Visible = false;
lblimgWork2.Visible = false;
lblimgWork3.Visible = false;
tblPreview.RenderControl(htextw);
tblProfileDetails.RenderControl(htextw);
Document document = new Document();
PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
string tempPostContent = getImage(stw.ToString());
StringReader str = new StringReader(stw.ToString());
HTMLWorker htmlworker = new HTMLWorker(document);
htmlworker.Parse(str);
document.Close();
Response.Write(document);
Response.End();
lblimgCandidate.Visible = false;
lblimgWork1.Visible = false;
lblimgWork2.Visible = false;
lblimgWork3.Visible = false;
Posted
Comments
fjdiewornncalwe 16-May-12 11:15am    
Have you checked to make sure that the source for your images are using absolute paths and not relative paths. From your code, we cannot tell you, but I would check that first.
maajanes 18-May-12 0:49am    
Hai Marcus,
Thank you for your reply.
Can you tel me the difference between absolute and relative paths.
My image path is: http://localhost/..../.../Images/
fjdiewornncalwe 18-May-12 9:42am    
You should learn how to search the internet for questions. You will find most of your answers there.
Absolute vs Relative Paths is a reasonable good explanation of what these are.
maajanes 21-May-12 3:14am    
I mentioned the absolute path as what you've said, but if I access it in a remote machine the images are not displaying. Can you tell a solution.

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