I have an ASP.NET application that has been working on all the environment we've tried so far and has been working on all of them. However, in the current server, which has Windows 2003 R2 x64 SP2, it is not working. There's no error thrown to the user by the application and no record in the Windows Event Viewer, which is why it seems unusual.
When I hit a button in the page, it starts reading the pdf file and adds header and footer to it. Both header and footer consists multiple lines, text, and images. But the application just keeps loading and loading until IE gives a "problem with your internet connection" error after 30mins.
My code is fairly simple:
// add header and footer PdfDocument doc = PdfSharp.Pdf.IO.PdfReader.Open(path);
XFont fontReportHeader = new XFont("Verdana", 16, XFontStyle.Bold); XFont fontReportTitle = new XFont("Verdana", 12, XFontStyle.Regular); XFont fontFooterAddress = new XFont("Verdana", 8, XFontStyle.Regular); XFont fontFooterCopyright = new XFont("Verdana", 6, XFontStyle.Regular);
XColor myColour = XColor.FromArgb(216, 30, 5); XPen pen = new XPen(myColour, 1);
XImage logo1= XImage.FromFile(HttpContext.Current.Server.MapPath(@"~/Images/image1.png")); XImage logo2 = XImage.FromFile(HttpContext.Current.Server.MapPath(@"~/Images/image2.png")); for (int i = 0; i < doc.PageCount; i++) { XUnit pageWidth = doc.Pages[i].Width; XUnit pageHeight = doc.Pages[i].Height;
XUnit headerTop = 25; XUnit headerBottom = 50; XUnit headerSeparator = pageWidth - (pageWidth / 4) - 20;
XUnit footerTop = pageHeight - 60; XUnit footerBottom = pageHeight - 38; XUnit footerSeparator = (pageWidth - logo2.PointWidth- 35) + 15;
XLinearGradientBrush brush = new XLinearGradientBrush(new XRect(0, 0, pageWidth, pageHeight), myColour, myColour, XLinearGradientMode.Horizontal);
XGraphics gfx = XGraphics.FromPdfPage(doc.Pages[i], XGraphicsPdfPageOptions.Append);
// header gfx.DrawLine(pen, 15, headerBottom, headerSeparator, headerBottom); gfx.DrawLine(pen, headerSeparator, headerTop, pageWidth - 15, headerTop); gfx.DrawLine(pen, headerSeparator, headerTop, headerSeparator, headerBottom); gfx.DrawString(reportHeader, fontReportHeader, brush, 15, 45, XStringFormat.Default); gfx.DrawString(reportTitle, fontReportTitle, brush, headerSeparator + ((pageWidth - headerSeparator - 15) / 2), 37, XStringFormat.Center);
// page number if (showPageNumber) { if (doc.Pages.Count > 1) gfx.DrawString(String.Format("Page {0} of {1}", i + 1, doc.Pages.Count), fontFooterAddress, XBrushes.Black, pageWidth - 60, pageHeight - 7); }
// footer gfx.DrawLine(pen, 15, footerBottom, footerSeparator, footerBottom); gfx.DrawLine(pen, footerSeparator, footerTop, pageWidth - 15, footerTop); gfx.DrawLine(pen, footerSeparator, footerTop, footerSeparator, footerBottom); gfx.DrawImage(logo1, 15, pageHeight - 56, logo1.PointWidth, logo1.PointHeight); gfx.DrawImage(logo2, pageWidth - logo2.PointWidth - 15, pageHeight - 56); gfx.DrawString("website", fontFooterAddress, brush, 15, footerBottom + 1, XStringFormat.TopLeft); gfx.DrawString("email", fontFooterAddress, brush, 137, footerBottom + 1, XStringFormat.TopLeft); gfx.DrawString(String.Format("©{0} company. All rights reserved.", DateTime.Now.Year), fontFooterCopyright, XBrushes.Silver, 15, footerBottom + 12, XStringFormat.TopLeft); gfx.DrawString("more copyright info", fontFooterCopyright, XBrushes.Silver, 15, footerBottom + 19, XStringFormat.TopLeft); }
doc.Save(path);
|