Itextsharp adds watermarks to PDF files

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.