0

I am using droidText jar for PDF create in my application but i can't re-size image and set text and image in same line. in my code i can get image in pdf but can not set with my size.

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmimg.compress(Bitmap.CompressFormat.JPEG, 100, stream);
Image myImg = Image.getInstance(stream.toByteArray());

PdfPTable table = new PdfPTable(2);
table.setWidthPercentage(100);
table.setWidths(new int[]{1, 2});

float documentWidth = 100;
float documentHeight = 100;
myImg.scaleToFit(documentWidth, documentHeight);

float leftMargin =  doc.getPageSize().getWidth() - myImg.getScaledWidth();
float lMargin = leftMargin / 2 ;
float topMargin =  doc.getPageSize().getHeight() - myImg.getScaledHeight(); 
float tMargin = topMargin / 2 ;
myImg.setAbsolutePosition(lMargin,tMargin);

table.addCell("\n\nRavi Vaghela");
table.addCell(myImg);

doc.add(table); 
Robin Giltner
  • 3,057
  • 2
  • 18
  • 26
Ravi Vaghela
  • 3,420
  • 2
  • 23
  • 51

2 Answers2

2

Robin

You can try scaleAbsolute() method for resize Image like this,

 myImg.scaleAbsolute(documentWidth, documentHeight);

For Image and Text in Same line How to display image and text beside each other Itext

Community
  • 1
  • 1
0

I got solution about that. image and text set in same line and set to image fix size. show following my code:

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bmimg.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    myImg = Image.getInstance(stream.toByteArray());

    Paragraph p1 = new Paragraph("About Me::\n",catFont);
    p1.setAlignment(Paragraph.ALIGN_LEFT);
    doc.add(p1);


    Paragraph nk = new Paragraph("Nick Name",catFont);
    nk.setAlignment(Paragraph.ALIGN_LEFT);
    doc.add(nk);



    Paragraph p = new Paragraph(20); 
    p.add(new Chunk("RAVI", subFont)); 
    myImg.scalePercent(100); 
    p.add(new Chunk(myImg, 280.0f, -100.0f));
    doc.add(p); 


    Paragraph ppp = new Paragraph("SunSign",catFont);
    ppp.setAlignment(Paragraph.ALIGN_LEFT);
    doc.add(ppp);

with chunk we can add image and set size and position in pdf. here subFont and catFont is FONT i have declared in my code.

Ravi Vaghela
  • 3,420
  • 2
  • 23
  • 51