Hi,
    I dropped the example code from
http://itext.ugent.be/library/com/lowagie/examples/objects/tables/MyFirstTable.java
into the addTable() method below, only to discover that the setColSpan 
method of
PdfPCell does not seem to work for RTFs.  To double-check my code I did 
a similar
table for PDF I added in the PDF output code and the cells spanned as 
expected. 
    Anyways, I've need to do some RTF output, and I've been playing with 
IText; 
I'll certainly need to do tables,  and *almost* certainly need to 
setColspans on cells.

I searched the list for "rtf AND setColspan" and didn't find anything 
germaine,
so I'd thought I'd post ...

using: 2.1.3, 
jre 1.6
xp

Ross



-----Snip 
---------------------------------------------------------------------------

import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;

import com.lowagie.text.BadElementException;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Image;
import com.lowagie.text.List;
import com.lowagie.text.ListItem;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.rtf.RtfWriter2;

public class Main {

    public static void main(String[] args) throws DocumentException, 
MalformedURLException, IOException {
        Document document = new Document();
        RtfWriter2.getInstance(document, new 
FileOutputStream("C:\\testRTFdocument.rtf"));
        produceExampleDocument(document);

        document = new Document();
        PdfWriter.getInstance(document, new 
FileOutputStream("C:\\testRTFdocument.pdf"));
        produceExampleDocument(document);
    }

    private static void produceExampleDocument(Document document) throws 
DocumentException, BadElementException,
            MalformedURLException, IOException {
        document.open();
        addTable(document);
        document.close();
    }

    private static void addTable(Document document) throws 
DocumentException {
        PdfPTable table = new PdfPTable(3);
        PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 
3"));
        cell.setColspan(3);
        table.addCell(cell);
        table.addCell("1.1");
        table.addCell("2.1");
        table.addCell("3.1");
        table.addCell("1.2");
        table.addCell("2.2");
        table.addCell("3.2");

        cell = new PdfPCell(new Paragraph("cell test1"));
        cell.setBorderColor(new Color(255, 0, 0));
        table.addCell(cell);

        cell = new PdfPCell(new Paragraph("cell test2"));
        cell.setColspan(2);
        cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
        table.addCell(cell);

        document.add(table);
    }
}


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to