I checked out your code, and I tried centering the Image, and it worked. This is a snippet of your code, with the
 
    'img.setAlignment(Element.ALIGN_CENTER);' added, it is the only change I made you your code... Hope this helps
 
 
 
 
    Cell c2 = new Cell();
      Image img = Image.getInstance("C:\bobdylan.jpg");
      img.setAlignment(Element.ALIGN_CENTER);
      img.scalePercent(20F);
      c2.addElement(new Chunk(img, 0, 0));
      table.addCell(c2);
 
 

 
~~~~~~~~~~~~~~~~~~~~~~~~~
Timothy Woolley
[EMAIL PROTECTED]
www.intervisionmedia.com
~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
Sent: Thursday, January 20, 2005 10:22 AM
Subject: [iText-questions] Center Image In Cell

For the past couple of days, I have been trying to center an image in a cell. But for some reason the image always goes to the left. I want to align_center the image in the cell. How can this be accomplished? Can it be accomplished? I have tried everything I could think of only to come up shy.
 
Please run below test file, or see attached RTF for visual.
PS, I need a RTF document.
 
 
Thanks,
Scott
 
 
 
 
import com.lowagie.text.DocumentException;
import com.lowagie.text.*;
import com.lowagie.text.rtf.RtfWriter2;
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
 
 
 
/**
 * Class shows some table work using the RtfWriter2
 * Problems still abound in the fact that we are
 * having troubles aligning images in the cells.
 */
 
public class CenterImage {
 
  static String propertiesLocation = "C:/bgl.properties";
  static AppObject appObject = new AppObject(propertiesLocation);
  static String db_id = "enkl_37";
  static DatabaseHandle dh = DataSources.getInstance().getDatabaseHandle(db_id);
 
  public static void main(String[] args) {
    System.out.println("rtf example");
    Document document = new Document(PageSize.LETTER, 50, 50, 50, 50);
    try {
      RtfWriter2.getInstance(document, new FileOutputStream("centerImage.rtf"));
      document.open();
      Table table = new Table(2);
      table.setPadding(4);
      table.setSpacing(0);
      table.setBorder(Rectangle.NO_BORDER);
 
      int headerwidths[] = { 75, 25 };
      table.setWidths(headerwidths);
      table.setWidth(90);
 
      Cell c1 = new Cell("Column 1");
      c1.setHorizontalAlignment(Element.ALIGN_CENTER);
      table.addCell(c1);
 
      Cell c2 = new Cell();
      Image img = Image.getInstance("C:/bobdylan.jpg");
      img.scalePercent(20F);
      c2.addElement(new Chunk(img, 0, 0));
      table.addCell(c2);
 
      document.add(table);
 
    } catch (DocumentException de) {
      System.err.println(de.getMessage());
    } catch(IOException ioe) {
      System.err.println(ioe.getMessage());
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
 
 
 
    document.close();
    System.exit(0);
  }
}
 

Scott K Purcell | Developer | VERTIS |
555 Washington Ave. 4th Floor | St. Louis, MO 63101 |
314.588.0720 Ext:1320 | [EMAIL PROTECTED] | http://www.vertisinc.com

Vertis is the premier provider of targeted advertising, media, and
marketing services that drive consumers to marketers more effectively.
                                                

 

Reply via email to