我尝试在pdf文档的所有页面中添加徽标。 我的代码:
private string insertBgImage(string doc)
{
PdfReader reader = new PdfReader(doc);
int NumOfPages = reader.NumberOfPages;
//MemoryStream memoryStream = new MemoryStream();
//memoryStream.ToArray();
string newDoc = Path.Combine(Path.GetTempPath(), "resume1.pdf");
FileStream fileStream = new FileStream(newDoc, FileMode.Create);
PdfStamper stamp = new PdfStamper(reader, fileStream);
int i = 1;
PdfContentByte under;
PdfContentByte over;
string bgPath = SPUtility.GetGenericSetupPath(@"Template\Images\ResumeList");
string BgImgUri = Path.Combine(bgPath, "bg.gif");
iTs.Image bg = iTs.Image.GetInstance(new Uri(BgImgUri));
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
bg.ScaleToFit(300, 337);
float absX = (PageWidth - 300) / 2;
float absY = (PageHeight - 337) / 2;
bg.SetAbsolutePosition(absX, absY);
bg.Alignment = iTs.Image.UNDERLYING;
while (i <= NumOfPages)
{
under = stamp.GetUnderContent(i);
under.AddImage(bg);
//over = stamp.GetOverContent(i);
//over.AddImage(bg);
//over.BeginText();
//over.SetFontAndSize(bf, 10);
//over.ShowText("page" + i);
//over.EndText();
i++;
}
stamp.Close();
return newDoc;
}
但是这个:
under.AddImage(bg);
不工作