Adding Image in Existing PDF File using Java
These days, PDF is frequently used for report generation like to generate In order to make the java program interact with files be it of any type word, excel openCV Apache framework comes into play. External Files Required for Build this Code. The first requirement is to import the following libraries files
- Linking PDF document and java program
- Create PDDocument object
- Create PDPage
- Add page to document objects
- Create FileInputStream object for image.
- Create PDJpeg object by passing PDDocument object and FIleInputStream as its constructor
- Invoke drawXObject() object and specify coordinates with width and height to draw the image onto PDF file.
- Close the stream, saving the document object, and close the document.
Implementation: Considering an input image sample to illustrate the working of a program where in order to illustrate the working PDF document before is as follows:
Processing with the usage of java program to insert text in the above PDF document
Output: Text inserted in the same input image.