How to Add Image into MergeDocument

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Generator for Java (v8)  /  How to Add Image into MergeDocument

DynamicPDF Generator for Java (v8) Forum

 Mar 02 2019 12:05 PM
I want  to add an image into Image Form Control of PDF.
 MergeDocument templateDoc = new MergeDocument("X:\\PDF_templates\\test_signature.pdf",options);
fls.getFormField("customer1_signature").setValue() ;

I want to signature byte[] update into Image Control.
Posted by a ceTe Software moderator
You can read an image in the form of byte array and add it to an existing PDF using Image class of the DynamicPDF Merger for Java product. You can access the desired page using index to add the image. Below is the code sample. The documentation on Image class is found here.
            File file = new File("Input image file path");
            FileInputStream fileInputStream = new FileInputStream(file);
            long byteLength = file.length(); // byte count of the file-content
            byte[] filecontent = new byte[(int) byteLength];
  , 0, (int) byteLength);
            PdfDocument pdf = new PdfDocument("PDF file path");
             MergeDocument mergeDoc=new MergeDocument(pdf);
             Page page=mergeDoc.getPages().getPage(0);
             ImageData imageDataObj=ImageData.getImage(filecontent);
             Image imageobj=new Image(imageDataObj,0,0);
             mergeDoc.draw("Path to save output PDF");
Signature form field is used to sign the PDF document. You can refer to the documentation on digital signing here. Also The DynamicPDF Merger does not support signing existing signature fields. You can only add new Signature field and sign it using Merger product.

ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 7:19 AM.