var path = string.Empty; if (writer.PageNumber == 1) { path = AppSetting.ApiSiteUrl+ "/Images/ContractTitle.png"; } else { path = AppSetting.ApiSiteUrl+ "/Images/ContractDetail.png"; } Uri url = new Uri(path); iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(url); var chunk = new Chunk(image, -200, 0,false); Phrase header = new Phrase(chunk); //Phrase header = new Phrase("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"); Phrase footer = new Phrase("第" + (writer.PageNumber+1) + "页", font); PdfContentByte cb = writer.DirectContent; //模版 显示总共页数 //cb.AddTemplate(tpl, document.Right - 54 + document.LeftMargin, document.Bottom - 8);//调节模版显示的位置 //页眉显示的位置 ColumnText.ShowTextAligned(cb, Element.ALIGN_CENTER, header, document.Right - 140 + document.LeftMargin, document.Top + 10, 0); //页脚显示的位置 ColumnText.ShowTextAligned(cb, Element.ALIGN_CENTER, footer, document.Right - 60 + document.LeftMargin, document.Bottom - 10, 0);
通过以上方法生成的页眉图片变的很小很小,而且设置Image的大小之类的属性也没有用,图片原尺寸是1280*960