Question

I have a png image in drawable folder and I want to use that png image in the pdf . I am using itextpdf.jar for creating the pdf. I searched for solution ,but I am not able to figure it out.

Was it helpful?

Solution

try {
            InputStream inputStream = MainActivity.this.getAssets().open(
                    "launchscreen.png");
            Bitmap bmp = BitmapFactory.decodeStream(inputStream);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
            Image signature;
            signature = Image.getInstance(stream.toByteArray());
            signature.setAbsolutePosition(400f, 150f);
            signature.scalePercent(100f);
            document.add(signature);
                    document.close();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

I hope its useful to you.

OTHER TIPS

You can use

Image image = Image.getInstance(yourImageByteArray);

document.add(image);

where document is an object of Document

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top