打开PDF文件时,在文件上面加一组随机码的水印
在打开PDF文件时,怎么才能做到放一组随机数据以水印的形式添加在文件中。
------解决方案--------------------itextsharp
PdfReader reader = new PdfReader("C:/PDF/Test.pdf");
PdfStamper stamp = new PdfStamper(reader, new FileStream("C:/PDF/Test.pdf", FileMode.Create));
int n = reader.NumberOfPages;
int i = 0;
PdfContentByte under;
iTextSharp.text.Image im = iTextSharp.text.Image.GetInstance("C:/Image/123.jpg");
im.SetAbsolutePosition(440, 730);
im.ScaleAbsolute(160, 60);
while (i < n)
{
i++;
under = stamp.GetOverContent(i);
under.AddImage(im);
}
stamp.Close();
reader.Close();
------解决方案--------------------参考我之前的代码
static void waterMark(String inputFile, String outputFile,String userPassWord, String ownerPassWord, String waterMarkName, int permission)
{
try {
PdfReader reader = new PdfReader(inputFile);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream( outputFile));
// 设置密码
stamper.setEncryption(userPassWord.getBytes(), ownerPassWord.getBytes(), permission, false);
BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
int total = reader.getNumberOfPages() + 1;
Image image = Image.getInstance(imageFilePath);
image.setAbsolutePosition(200, 400);
PdfContentByte under;
int j = waterMarkName.length();
char c = 0;
int rise = 0;
for (int i = 1; i <&