Hi,
I am testing iText and trying to obtain two tables, side by side. I am
using PdfPTables and everything is working, except that the last line
of the left table is extended. I have used setExtendLastRow(false) but
without success. Where's the mistake?
package it.mksgs.action;
import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public class PdfBuilder {
public static void main(String[] argv)
{
try {
Document document = new Document(PageSize.A4, 36, 36, 96, 48);
OutputStream ostream = new FileOutputStream("c:\\my.pdf");
PdfWriter.getInstance(document, ostream);
document.open();
doSomething(document);
document.close();
System.out.println("ok");
}
catch ( Exception e ) {
e.printStackTrace();
}
}
private static Font titleFont =
FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD);
private static Font slantFont =
FontFactory.getFont(FontFactory.HELVETICA, 7, Font.ITALIC);
private static Font boldFont =
FontFactory.getFont(FontFactory.HELVETICA_BOLD, 7, Font.BOLD);
private static Font normFont = FontFactory.getFont(FontFactory.HELVETICA, 7);
private static void doSomething(Document doc)
throws Exception
{
float[] widths = {36, 64};
PdfPTable frameset = new PdfPTable(widths);
frameset.setExtendLastRow(false);
frameset.setWidthPercentage(100);
PdfPCell cell;
cell = new PdfPCell(fillMargini());
cell.setPaddingRight(6);
cell.setBorder(0);
cell.setVerticalAlignment(Element.ALIGN_TOP);
frameset.addCell(cell);
cell = new PdfPCell(fillCentraleRischi());
cell.setBorder(0);
cell.setVerticalAlignment(Element.ALIGN_TOP);
frameset.addCell(cell);
doc.add(frameset);
}
private static PdfPTable fillMargini()
throws DocumentException
{
float[] widths = {22, 26, 26, 26};
PdfPTable tab = new PdfPTable(widths);
tab.setExtendLastRow(false);
PdfPCell cell = createCell("Margini al 318 a.C.", titleFont,
Element.ALIGN_LEFT);
cell.setColspan(4);
cell.setBorder(Rectangle.BOTTOM);
tab.addCell(cell);
cell = new PdfPCell();
tab.addCell(cell);
tab.addCell(createCell("Cum.A.C.", boldFont, Element.ALIGN_CENTER));
tab.addCell(createCell("Cum.A.P.", boldFont, Element.ALIGN_CENTER));
tab.addCell(createCell("Tot.A.P.", boldFont, Element.ALIGN_CENTER));
tab.addCell(createCell("Intermed.", slantFont, Element.ALIGN_LEFT));
tab.addCell(createCell("1.234,567", slantFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("34.567,890", slantFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("45,680", slantFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("Finanziario", normFont, Element.ALIGN_LEFT));
tab.addCell(createCell("2.255,000", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("45,680", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("666.999,000", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("Servizi", normFont, Element.ALIGN_LEFT));
tab.addCell(createCell("98,760", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("3.567,890", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("33,333", normFont, Element.ALIGN_RIGHT));
return tab;
}
private static PdfPTable fillCentraleRischi()
throws DocumentException
{
float[] widths = {6, 15, 15, 10, 15, 12, 15, 12};
PdfPTable tab = new PdfPTable(widths);
tab.setExtendLastRow(false);
PdfPCell cell = createCell("Centrale Rischi al 32.13.1999",
titleFont, Element.ALIGN_LEFT);
cell.setColspan(8);
cell.setBorder(Rectangle.BOTTOM);
tab.addCell(cell);
cell = new PdfPCell();
cell.setBorder(Rectangle.LEFT);
tab.addCell(cell);
cell = createCell("Banca", boldFont, Element.ALIGN_CENTER);
cell.setColspan(3);
tab.addCell(cell);
cell = createCell("Sistema", boldFont, Element.ALIGN_CENTER);
cell.setColspan(4);
tab.addCell(cell);
cell = new PdfPCell();
cell.setBorder(Rectangle.LEFT);
tab.addCell(cell);
tab.addCell(createCell("Acc", slantFont, Element.ALIGN_CENTER));
tab.addCell(createCell("Util.", slantFont, Element.ALIGN_CENTER));
tab.addCell(createCell("%Sat.", slantFont, Element.ALIGN_CENTER));
tab.addCell(createCell("Acc.", slantFont, Element.ALIGN_CENTER));
tab.addCell(createCell("%Pen.Acc.", slantFont, Element.ALIGN_CENTER));
tab.addCell(createCell("Util.", slantFont, Element.ALIGN_CENTER));
tab.addCell(createCell("%Pen.Util.", slantFont, Element.ALIGN_CENTER));
tab.addCell(createCell("B/T", boldFont, Element.ALIGN_LEFT));
tab.addCell(createCell("1.234.567,890", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("234.567,890", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("33,333", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("222.555,000", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("45,680", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("666.999,000", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("98,760", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("a.p.", boldFont, Element.ALIGN_LEFT));
tab.addCell(createCell("234.567,890", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("3.567,890", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("33,333", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("222.555,000", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("0,120", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("777.444,000", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("98,760", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("TOT.", boldFont, Element.ALIGN_LEFT));
tab.addCell(createCell("234.567,890", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("777.889,000", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("33,333", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("3.567,890", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("0,120", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("222.555,000", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("98,760", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("a.p.", boldFont, Element.ALIGN_LEFT));
tab.addCell(createCell("234.567,890", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("677.889,000", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("33,333", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("3.567,890", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("77,120", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("222.555,000", normFont, Element.ALIGN_RIGHT));
tab.addCell(createCell("98,760", normFont, Element.ALIGN_RIGHT));
return tab;
}
public static PdfPCell createCell(String content, Font font, int align)
throws BadElementException
{
Phrase phr = new Phrase(content, font);
PdfPCell cell = new PdfPCell(phr);
cell.setHorizontalAlignment(align);
return cell;
}
}
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions