Hello,
I got server error when downloading pdf file from my webpage in asp.net.
"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond in asp.net."
Please tell me any solution.
Code:
protected void btnPdf_Click(object sender, EventArgs e)
{
imgphoto.Src = "http://localhost:51350/Project/imagesLogin/black.png";
string imgurl = Convert.ToString(imgChart.ImageUrl);
imgurl = imgurl.Replace("~", "");
imgChart.ImageUrl = "D:/Project" + imgurl;
Chart1.Visible = false;
//lblOrganisationTitle.Font.Size = 14;
lbltitle.Font.Size = 14;
lblOrgname.Font.Size = 9;
lblOrganisationname.Font.Size = 9;
lblbatchName.Font.Size = 9;
lblParticipantBatchname.Font.Size = 9;
lblChapter.Font.Size = 9;
lblChpaterName.Font.Size = 9;
lbldesc.Font.Size = 9;
lbldescription.Font.Size = 9;
lblfooter.Font.Size = 8;
Label1.Font.Size = 9;
Label2.Font.Size = 9;
Label3.Font.Size = 9;
Label4.Font.Size = 9;
MyImage.Visible = false;
Image1.Visible = false;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=AudioViewReport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 50f, 50f, 10f, 10f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
Phrase phrase = null;
PdfPCell cell = null;
PdfPTable table = null;
table = new PdfPTable(3);
table.TotalWidth = 500f;
table.LockedWidth = true;
table.SetWidths(new float[] { 0.3f, 0.6f, 0.3f });
iTextSharp.text.Image gifImage = iTextSharp.text.Image.GetInstance(Image1.ImageUrl);
gifImage.ScalePercent(50f);
// gifImage.Alignment = iTextSharp.text.Image.ALIGN_CENTER;
cell = new PdfPCell(gifImage);
cell.BorderColor = BaseColor.WHITE;
cell.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell);
phrase = new Phrase();
phrase.Add(new Chunk("\n\n", FontFactory.GetFont("Arial", 16, Font.BOLD)));
cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
cell.VerticalAlignment = Element.ALIGN_TOP;
table.AddCell(cell);
cell = ImageCell("~/imagesLogin/darklogo_2.png", 50f, PdfPCell.ALIGN_CENTER);
table.AddCell(cell);
pdfDoc.Add(table);
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
Thanks.