62,046
社区成员
发帖
与我相关
我的任务
分享
private void ConvertPDFToPDF(string filePath, string toPath)
{
PdfReader reader = new PdfReader(filePath);
int n = reader.NumberOfPages;
PdfStamper stamp = new PdfStamper(reader, new FileStream(toPath, FileMode.Create));
int i = 0;
PdfContentByte under = null;
string text = hfEventCode.Value;
int width = text.Length * 16 > 40 ? text.Length * 16 : 40;
System.Drawing.Bitmap image = new System.Drawing.Bitmap(width, 18);
SetBgColor(image, Color.White);
Graphics g = Graphics.FromImage(image);
System.Drawing.Font font = new System.Drawing.Font("Arial", 9, (System.Drawing.FontStyle.Bold));
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), Color.Black, Color.Black, 1.2F, true);
g.DrawString(text, font, brush, 2, 2);
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Byte[] img = ms.ToArray();
iTextSharp.text.Image mm = iTextSharp.text.Image.GetInstance(img);
mm.SetAbsolutePosition(155, 478);
mm.ScaleAbsolute(width, 18);
while (i < n)
{
i++;
under = stamp.GetOverContent(i);
under.AddImage(mm);
}
stamp.Close();
reader.Close();
ms.Close();
ms.Dispose();
}