> Hello
>
(Excuse me if this has been sent already, but i did not see it on the list
the first time) I am facing a weird situation that seems like a bug - unless
i am missing something. If someone can help, it will be very-very much
appreciated, as i am really desperate and this is needed urgently. Here's
the story:
> I am using a base class PDFProducer that is subclassed in order to produce
> variations of documents with basically the same format. Sublasses call a
> method named buildPdfDocumentAsTable in PDFProducer and provide it with
> values that are used to (obviously) build a pdf that consists of a table.
>
> One of these arguments is used to provide the table with headers. It works
> fine for a normal A4 portrait document, but for some reason the header
> content does not show when the document is landscape!
>
> I've had quite some trouble with finding the right fonts in the first
> place, so i suspect it might have something to do with that..but i've
> really tried all i can think of and come up with nothing so far.
>
> Has anyone ever come across a similar situation? Could this be some kind
> of weird bug?
>
> Help please!
> George Anadiotis
>
> The code for the method is as follows:
>
> protected void buildPdfDocumentAsTable(Document doc, String title,
> String[] topHeaders, Integer[] topHeadersAlignment, Font[]
> topHeadersFont,Integer[] topHeadersBorder,Boolean[]
> topHeadersKeepBgColor,
> String[] columnHeaders, boolean useHeaderColor,
> java.util.List content, String[] textAfter, float[] widths)
> throws Exception
> {
>
> if (this.getTextBefore()!=null)
> {
> Table table1 = new Table(2);
> table1.setWidth(this.getDefaultWidth());
> table1.setBorder(Table.NO_BORDER);
>
> int columnsNo = getTextBefore()[0].length;
> System.out.println("columnsNo = "+columnsNo);
> for(int i=0;i<columnsNo;i++)
> {
> System.out.println("getTextBefore()[0][i] =
> "+getTextBefore()[0][i]);
> if (getTextBefore()[0][i] == null)
>
> PDFDocumentPrinter.insertEmptyCell(table1);
> else
>
> PDFDocumentPrinter.insertTextCell(table1,
> getTextBefore()[0][i],getTableContentFont(),Element.ALIGN_LEFT) ;
>
> System.out.println("getTextBefore()[1][i] =
> "+getTextBefore()[1][i]);
> if (getTextBefore()[1][i] == null)
>
> PDFDocumentPrinter.insertEmptyCell(table1);
> else
>
> PDFDocumentPrinter.insertTextCell(table1, getTextBefore()[1][i],
> getTableContentFont(),Element.ALIGN_RIGHT) ;
>
> }
> doc.add(table1);
> }
>
> if (title!=null)
> {
> Table t3 = new Table(1);
> t3.setBorder(Table.NO_BORDER);
> PDFDocumentPrinter.insertTextCell(t3,
> title,getTableContentFont(),Element.ALIGN_CENTER) ;
> doc.add( t3 );
> }
>
> int columnsNo = columnHeaders.length;
>
>
>
> Table table1= new Table(columnsNo);
> table1.setCellsFitPage(true);
> Chunk ch1 = null;
> Cell cell1 = null;
>
>
>
> boolean doTopHeaders = (topHeaders!=null);
> if (doTopHeaders)
> {
> int topHeadersNo = topHeaders.length;
>
> for (int i=0; i<topHeadersNo; i++)
> {
> if (topHeadersFont!=null &&
> topHeadersFont[i]!=null)
> ch1 = new Chunk(topHeaders[i] ,
> getTableContentFont());
> else
> ch1 = new Chunk(topHeaders[i] ,
> getTableContentFont());
> ch1.setTextRise(4);
> cell1 =new Cell(ch1);
> if (topHeadersBorder!=null &&
> topHeadersBorder[i]!=null)
>
> cell1.setBorder(topHeadersBorder[i].intValue());
> else
> cell1.setBorder(Rectangle.BOX);
>
> if (topHeadersAlignment!=null &&
> topHeadersAlignment[i]!=null)
>
> cell1.setHorizontalAlignment(topHeadersAlignment[i].intValue());
>
>
> if (topHeadersKeepBgColor!=null &&
> topHeadersKeepBgColor[i]!=null && topHeadersKeepBgColor[i].booleanValue())
>
> cell1.setBackgroundColor(getTableHeaderColor());
>
> cell1.setHeader(true);
> cell1.setColspan(columnsNo);
> table1.addCell(cell1);
> }
> }
>
>
>
>
> table1.setAlignment(com.lowagie.text.Element.ALIGN_CENTER);
> table1.setBorderWidth(0);
>
> table1.setDefaultHorizontalAlignment(com.lowagie.text.Element.ALIGN_CENTER
> );
>
> if (widths!=null)
> {
> table1.setWidth(getWidth(widths));
> table1.setWidths(widths);
> }
> else
> table1.setWidth(getDefaultWidth());
>
>
>
>
> //loop that adds headers to the table
> for (int i=0; i<columnsNo; i++)
> {
> ch1 = new Chunk(columnHeaders[i] ,
> getTableHeaderFont());
> ch1.setTextRise(4);
> cell1 =new Cell(ch1);
> cell1.setBorder(Rectangle.BOX);
> if (useHeaderColor)
>
> cell1.setBackgroundColor(getTableHeaderColor());
> cell1.setHeader(true);
> table1.addCell(cell1);
> }
> table1.endHeaders();
>
> table1.setDefaultHorizontalAlignment(com.lowagie.text.Element.ALIGN_CENTER
> );
>
>
> String[] currentRow = null;
>
> for (int i=0; i<content.size(); i++)
> {
> currentRow = ((String[] )content.get(i));
>
> for (int j=0; j<currentRow.length; j++)
> {
> if (currentRow[j]!=null)
> {
> ch1 = new Chunk( currentRow[j] ,
> getTableContentFont() );
> ch1.setTextRise(4);
> cell1 =new Cell(ch1);
> cell1.setBorder(Rectangle.BOX);
> table1.addCell(cell1);
> }
> else
>
> PDFDocumentPrinter.insertEmptyCell(table1,Rectangle.BOX);
> }
>
> }
>
> doc.add(table1);
>
> if (textAfter!=null)
> for (int i=0; i<textAfter.length ; i++)
> {
> Table atable = new Table(1);
> atable.setBorder(Table.NO_BORDER);
> atable.setWidth(getWidth(widths));
> ch1 = new Chunk( textAfter[i] ,
> getTableContentFont() );
> cell1 = new Cell(ch1);
> cell1.setBorder(Rectangle.NO_BORDER);
> atable.addCell(cell1);
>
> doc.add(atable);
> }
>
> System.out.println( "doc.newPage() = "+doc.newPage() );
>
> }
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions