Itextsharp. the component used to operate pdf on the net platform is powerful, but the front-end time encounters a problem. When a PDF is dynamically generated (multiple tables are generated in the generated PDF, and the table data comes from the database ), you cannot add a watermark image to each page. It may be because you are not familiar with the itextsharp component and cannot add a watermark to each page when dynamic PDF is generated. At last, we had to use itextsharp to generate a PDF file and then use itextsharp to add a watermark to the generated PDF file. If a friend in the garden adds a watermark to each page when generating a PDF file, give me some advice.
The following code adds a watermark to the PDF file in itextsharp for your reference.
# Add the official seal string areacode = unitinfoquerybll. instance. getareacode (currentuser. uintid); If (! String. isnullorempty (areacode) {int pages = document. pagenumber; pdfreader reader = new pdfreader (httpcontexthelper. approotpath + pdfpath + release name + ". PDF "); int n = reader. numberofpages; pdfstamper Stamper = new pdfstamper (reader, new filestream (httpcontexthelper. approotpath + pdfpath + release name + "a.pdf", filemode. create); Int J = 0; contentbyte; itextsharp. text. image IMG = itextsharp. text. image. getinstance (imgepath + areacode + ". PNG "); IMG. scalepercent (75f); IMG. setabsoluteposition (300,550); While (j <n) {J ++; contentbyte = Stamper. getovercontent (j); contentbyte. addimage (IMG);} Stamper. close (); reader. close () ;}# endregion