2

I am using iTextPdf to create a check-in application. I've added the an image already using the image object :

imagePath = "/sdcard/Mugshot.jpg";
Image image = Image.getInstance(imagePath);
image.setAbsolutePosition(165f, 465f);
image.scaleToFit(290f,290f);
document.add(image);

I would prefer to add the image in the same way before adding any content, as I expect any subsequent stuff would write over existing stuff.

Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83
Anurag Pande
  • 123
  • 8

1 Answers1

5

As per the API Documentation of iTextPdf you can also contruct using byte[] array

Convert drawable to byte[]

Drawable d = getResources ().getDrawable (R.drawable.your_drawable)
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitmapData = stream.toByteArray();

Then

Image image = Image.getInstance(bitmapData);
Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83