PDF添加水印

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp;
using iTextSharp.text.pdf;
using System.IO;
using System.Drawing;
using iTextSharp.testutils;



public partial class pdf : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        PdfReader PDFReader = new PdfReader(Server.MapPath("c.pdf"));

        FileStream Stream = new FileStream(Server.MapPath("d.pdf"), FileMode.Create, FileAccess.Write);

        PdfStamper PDFStamper = new PdfStamper(PDFReader, Stream);

        for (int iCount = 0; iCount < PDFStamper.Reader.NumberOfPages; iCount++)
        {
            PdfContentByte PDFData = PDFStamper.GetOverContent(iCount + 1);
            BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
            PDFData.BeginText();
            PDFData.SetColorFill(CMYKColor.LIGHT_GRAY);
            PDFData.SetFontAndSize(baseFont, 80);
             PDFData.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Sample", 300, 400, 45);
            PDFData.EndText();
        }

      
        PDFStamper.Close();
        PDFReader.Close();
        Stream.Close();
    }


   
}

https://files.cnblogs.com/files/mqingqing123/pdf.rar

posted @ 2021-01-05 12:59  启明星工作室  阅读(158)  评论(0编辑  收藏  举报