I'm workig with this, and i change the SAXiTextHandler.java on the "ROW"
area (see below between the //DANY are my change to support relative
width)
I'm change this when i use the HTMLParser but, now i'm need stylesheet and
i use the HTMLWorker, the table are some problems yet. I'm working on
that.
Hope this help.
Daniela
// rows
if (Row.isTag(name)) {
ArrayList cells = new ArrayList();
int columns = 0;
Table table;
Cell cell;
while (true) {
Element element = (Element) stack.pop();
if (element.type() == Element.CELL) {
cell = (Cell) element;
columns += cell.colspan();
cells.add(cell);
} else {
table = (Table) element;
break;
}
}
if (table.columns() < columns) {
table.addColumns(columns - table.columns());
}
Collections.reverse(cells);
String width;
//DANY
float totalpix = 0;
for (Iterator i = cells.iterator(); i.hasNext();) {
cell = (Cell) i.next();
width = cell.cellWidth();
if ( width != null){
if ( width.endsWith("%") == false)
totalpix += Float.parseFloat(width);
}
}
if(totalpix > 0){
int temp = 0;
for (Iterator i = cells.iterator(); i.hasNext();)
{
cell = (Cell) i.next();
width = cell.cellWidth();
temp =
(int)((Float.parseFloat(width)*100)/totalpix);
cell.setWidth(temp + "%");
}
}
//DANY
float[] cellWidths = new float[columns];
boolean[] cellNulls = new boolean[columns];
for (int i = 0; i < columns; i++) {
cellWidths[i] = 0;
cellNulls[i] = true;
}
float total = 0;
int j = 0;
for (Iterator i = cells.iterator(); i.hasNext();) {
cell = (Cell) i.next();
if ((width = cell.cellWidth()) == null) {
if (cell.colspan() == 1 && cellWidths[j] == 0) {
try {
cellWidths[j] = 100f / columns;
total += cellWidths[j];
} catch (Exception e) {
// empty on purpose
}
} else if (cell.colspan() == 1) {
cellNulls[j] = false;
}
} else if (cell.colspan() == 1 && width.endsWith("%"))
{
try {
cellWidths[j] = Float.parseFloat(
width.substring(0, width.length() - 1)
+ "f");
total += cellWidths[j];
} catch (Exception e) {
// empty on purpose
}
}
j += cell.colspan();
table.addCell(cell);
}
float widths[] = table.getProportionalWidths();
if (widths.length == columns) {
float left = 0.0f;
for (int i = 0; i < columns; i++) {
//if (cellNulls[i] && widths[i] != 0) {
//DANY
if (cellNulls[i] && widths[i] != 0 && widths[i] !=
100) {
//DANY
left += widths[i];
cellWidths[i] = widths[i];
}
}
if (100.0 >= total) {
for (int i = 0; i < widths.length; i++) {
if (cellWidths[i] == 0 && widths[i] != 0) {
cellWidths[i] = (widths[i] / left)
* (100.0f - total);
}
}
}
table.setWidths(cellWidths);
}
stack.push(table);
}
"Bruno Lowagie (iText)" <[EMAIL PROTECTED]>
Enviado Por: [EMAIL PROTECTED]
09/03/2007 11:51
Favor responder a Post all your questions about iText here
Para: Post all your questions about iText here
<itext-questions@lists.sourceforge.net>
cc:
Assunto: Re: [iText-questions] HTML attributes in Table
danielb wrote:
> I'd like to know if its possible to add html attributes
> (like 'id') to Table or Cell objects, or at least if its possible to set
> relative widths.
Add html attributes: wrap the iText objects in a MarkedContent object.
Set relative widths: inspect the HtmlWriter code. I don't know the
answer by heart; it's as much work for me as it is for you to check
the code; so I'd rather have you doing it ;-)
br,
Bruno
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/