Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 20th, 2012  |  syntax: None  |  size: 2.74 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ItextSharp 401 error (Image issue)
  2. public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document)
  3.     {
  4.  
  5.         //Include the header image
  6.         //System.Web.HttpContext.Current.Server.MapPath("/image.jpg");
  7.  
  8.         iTextSharp.text.Image HeadImg = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("/image.jpg"));
  9.         HeadImg.ScalePercent(50f);
  10.         HeadImg.SetAbsolutePosition(document.PageSize.Width - 60f - 72f, document.PageSize.Height - 36f - 216.6f);
  11.  
  12.         //Include the footer image/text
  13.         iTextSharp.text.Image FootImgMS = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("/image.jpg"));
  14.         FootImgMS.ScalePercent(50f);
  15.  
  16.         iTextSharp.text.Image FootLeftImg = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("/image.jpg"));
  17.         FootLeftImg.ScalePercent(50f);
  18.  
  19.         Phrase FootText = new Phrase("Phone: " + Tel, FontFactory.GetFont("verdana", 10));
  20.  
  21.         Paragraph LeftFoot = new Paragraph();
  22.         LeftFoot.Add(new Chunk(FootLeftImg, 0, 0));
  23.         LeftFoot.Add(new Chunk(Chunk.NEWLINE));
  24.         LeftFoot.Add(new Phrase(FootText));
  25.  
  26.         //Create header table
  27.         PdfPTable PDFTab = new PdfPTable(1);
  28.  
  29.         //Create footer table
  30.         PdfPTable PDFFootTab = new PdfPTable(2);
  31.  
  32.         //Create header cell
  33.         PdfPCell PDFCell1 = new PdfPCell(HeadImg);
  34.         PDFCell1.Border = 0;
  35.  
  36.         //create footer cells
  37.         PdfPCell PDFFootCell1 = new PdfPCell(LeftFoot);
  38.         PDFFootCell1.PaddingTop = 35;
  39.         PdfPCell PDFFootCell2 = new PdfPCell(FootImgMS);
  40.         PDFFootCell1.Border = 0;
  41.         PDFFootCell2.Border = 0;
  42.         PDFFootCell1.HorizontalAlignment = Element.ALIGN_LEFT;
  43.         PDFFootCell2.HorizontalAlignment = Element.ALIGN_RIGHT;
  44.  
  45.         //Add cells to tables
  46.         PDFTab.AddCell(PDFCell1);
  47.         PDFTab.TotalWidth = document.PageSize.Width;
  48.         PDFFootTab.AddCell(PDFFootCell1);
  49.         PDFFootTab.AddCell(PDFFootCell2);
  50.         PDFFootTab.TotalWidth = document.PageSize.Width - 80;
  51.  
  52.         //Write out header table
  53.         PDFTab.WriteSelectedRows(0, -1, 0, document.PageSize.Height, writer.DirectContent);
  54.  
  55.         //Write out footer table
  56.         PDFFootTab.WriteSelectedRows(0, -1, 40, 60, writer.DirectContent);
  57.  
  58.         //set pdfContent value
  59.         pdfContent = writer.DirectContent;
  60.  
  61.         pdfContent.MoveTo(30, document.PageSize.Height - 145);
  62.         pdfContent.LineTo(document.PageSize.Width - 40, document.PageSize.Height - 145);
  63.  
  64.     }
  65.        
  66. iTextSharp.text.Image HeadImg = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("/image.jpg"));
  67.        
  68. iTextSharp.text.Image HeadImg = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("~/image.jpg"));