I am creating an rtf document with iText, it contains a table with a
mixture of text and picture cells, I am having two problems:
1) I cannot seem to get an image in a cell using a byte array.  See
commented call to getPicture() below.
2) if I load a picture in via a url it doesn't size to fit the cell I am
adding it to, is there a way to do this?


This is an example of the type of table I am trying to write to an rtf
document:

(Embedded image moved to file: pic05436.pcx)

I want the image to size to fit the number of cells it is given to span
across.


      Table table = null;

      // get cell from the jtable
      Object contents = jtable.getValueAt(r, c);

                    if (contents != null)
                    {
                        // get & record the span info
                        spanDetails =
tableModel.getCellAttribute().getSpan(r, c);
                        spanHeight = spanDetails[0];
                        spanWidth = spanDetails[1];

                         // ...................................

                            else if (contents instanceof PictureCell)
                            {
                                Image image = null;
                                try
                                {
                //  load an image via a url (this loads but it's too big)
                                    image =
Image.getInstance("C:\\Documents and Settings\\VBrown\\My Documents\\My
Pictures\\cloud.jpg");

                 // load an image via a byte array (doesn't work)
                                    //image =
Image.getInstance(getPicture((PictureCell)contents));
                                }
                                cell = new Cell(image);
                            }

                        table.addCell(cell);
                    }
                }
            }
            doc.add(table);


private byte[] getPicture(PictureCell cell)
    {
        PictureHolder objPicHolder = (PictureHolder) cell.getContent();

        java.awt.Image objContentAsImage  = objPicHolder.getImage();

        BufferedImage bufferedImage = new
BufferedImage(objContentAsImage.getWidth(null),
objContentAsImage.getHeight(null),        BufferedImage.TYPE_INT_RGB);
        Graphics graphics = bufferedImage.createGraphics();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();

        graphics.drawImage(objContentAsImage, 0, 0,
objContentAsImage.getWidth(null), objContentAsImage.getHeight(null), null);
        try
        {
            ImageIO.write(bufferedImage, "png", stream);
        }
        catch (Throwable e)
        {
            e.printStackTrace();
        }

        byte[] abytImage = stream.toByteArray();
        return abytImage;
    }

Any help would be greatly appreciated.

Victoria Brown
[EMAIL PROTECTED]


****************************************************************************

Join IDBS' webinars for the latest information on our new software for drug
discovery.
Don't miss this opportunity for convenient, bite-sized views of how we can
help
you be more effective and efficient in your research.
http://www.idbs.com/webinar

*****************************************************************************

The information contained in this email may contain confidential or legally
privileged information. If you are not the intended recipient any
disclosure, copying, distribution or taking any action on the contents of
this information may be unlawful. If you have received this email in error,
please delete it from your system and notify us immediately.  Any views
expressed in this message are those of the individual sender, except where
the message states otherwise. IDBS takes no responsibility for any
computer virus which might be transferred by way of this email and
recommends that you subject any incoming E-mail to your own virus checking
procedures.  We may monitor all E-mail communication through our networks.
If you contact us by E-mail, we may store your name and address to
facilitate communication.

*****************************************************************************

Attachment: pic05436.pcx
Description: Binary data

Reply via email to