0

I am struggling with positioning the image in the attached PDF. Here is the code that I used

 PdfReader reader = new PdfReader(getResources().openRawResource(R.raw.template3));
                    PdfStamper stamper = new PdfStamper(reader, output);
                    Bitmap bmp = FileUtils.getResizedBitmap(mInvoice.getProfile().getLogoImagePath(), 150, 150);
                    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
                    Image image = Image.getInstance(stream.toByteArray());
                    image.scaleAbsolute(150f, 150f);
                    image.setAbsolutePosition(385f, 768f);
                    image.setSpacingBefore(50f);

                    PdfContentByte overContent = stamper.getOverContent(1);
                    overContent.addImage(image);

I have tried many variables as far as the inputs for the setAbsolutePath without success. I added spacing before hoping to push the image down without success. I want to push the image down the page a little, It is currently sitting at the top right edge.

Sample PDF Generated by iTextG

Any input is appreciated.

Val Okafor
  • 3,371
  • 13
  • 47
  • 72
  • Does your invoice template have form fields? Usually one uses a button as a place holder for an image. What you're doing is not an example of good coding: using hard-coded coordinates is what one does in an example to explain a principle. It's not something you do in a real-world application. You should not *guess* coordinates. You should define them up-front in the template. – Bruno Lowagie May 09 '15 at 08:23
  • Thank you Bruno, I was not actually guessing those co-ordinates, I obtained the coordinates using Adobe Acrobat Pro. I am using a text box as a place holder for the image and I can try a button. And yes, my template has a lot of form fields. – Val Okafor May 09 '15 at 14:32
  • In that case, you can get the position of the field (text field, button; it doesn't matter that much) and use those coordinates to position the image. In the free ebook [The Best iText Questions on StackOverflow](http://pages.itextpdf.com/ebook-stackoverflow-questions.html), you'll find the answer to the question [How to add an image to an AcroForm field?](http://stackoverflow.com/questions/16052047/add-image-to-acrofield-in-itext) which also answers your question. – Bruno Lowagie May 09 '15 at 15:12

0 Answers0