2009-08-17 [.Net C#]利用iTextSharp在PDF上新增浮水印(WaterMark) [一] 11945 0 .Net C# 摘要:[.Net C#]利用iTextSharp在PDF上新增浮水印(WaterMark) [一] 在iTextSharp3.8之後,其原本的WaterMark Function被拿掉了所以我就使用插入圖片的方式做浮水印的功能程式碼如下public void Watermark(string inputPath, string outputPath, string watermarkPath) { try { PdfReader pdfReader = new PdfReader(inputPath); int numberOfPages = pdfReader.NumberOfPages; FileStream outputStream = new FileStream(outputPath, FileMode.Create); PdfStamper pdfStamper = new PdfStamper(pdfReader, outputStream); PdfContentByte waterMarkContent; string watermarkimagepath = watermarkPath; iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(watermarkimagepath); image.SetAbsolutePosition(255,785); for (int i = 1; i <= numberOfPages; i++) { waterMarkContent = pdfStamper.GetUnderContent(i); waterMarkContent.AddImage(image); } pdfStamper.Close(); pdfReader.Close(); } catch (Exception ex) { WriteLog.Log(ex.ToString()); throw ex; } } .Net C# 回首頁