How to add images in pdf and how to add images in pdf

Source: Internet
Author: User

How to add images in pdf and how to add images in pdf

Public class synchronized test {public static void main (String [] args) throws Exception {PdfReader reader = new PdfReader ("E: \ src.pdf"); int n = reader. getNumberOfPages (); // the number of pages in pdf Document document = new Document (reader. getPageSize (n); float width = document. getPageSize (). getWidth (); float height = document. getPageSize (). getHeight (); // output file export Stamper stamp = new export Stamper (reader, new FileOutputStream ("E: \ outputfileworkflow"); export contentbyte over; Image img = Image. getInstance ("E: \ test.jpg"); width = width-img.getWidth (); height = height-img.getHeight (); img. setAbsolutePosition (width, height); // The coordinate origin is img in the lower left corner. setAlignment (Image. ALIGN_RIGHT); if (n> 0) {over = stamp. getOverContent (1); // display the image on the page (1 on the first page) over. addImage (img);} stamp. close ();}}

Note: itextpdf-5.4.5.jar packages are required

<dependency>    <groupId>com.itextpdf</groupId>    <artifactId>itextpdf</artifactId>    <version>5.4.5</version></dependency>

 

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.