Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » iText »

[iText-questions] Headers problem ...

GRECU STEFAN

2005-06-23


/***************************************************************************
***********************************************************
Greetings to all ... and keep going with this great job ...

I have some problems with table headers (with an very old version everythig
was ok) ... maybe I'm doing something wrong: here is a sample code:


**********************************************************************/

import java.sql.*;
import java.util.*;
import java.io.*;
import java.text.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import com.lowagie.text.pdf.codec.*;

public class testpdf {
private static Document doc = null;


private static void addCell(Table datatable, Cell c, int halign, int
valign, int colspan, int rowspan, int border) throws Exception {
  addCell(datatable, c, halign, valign, colspan, rowspan, border, 1,
false);
}

private static void addCell(Table datatable, Cell c, int halign, int
valign, int colspan, int rowspan, int border, float gf, boolean isheader)
throws Exception {
  if (colspan > 1) {
   c.setColspan(colspan);
  }
  if (rowspan > 1) {
   c.setRowspan(rowspan);
  }
  c.setHorizontalAlignment(halign);
  c.setVerticalAlignment(valign);
  c.setBorder(border);
  if (gf != 1) {
   c.setGrayFill(0.90f);
  }
  c.setHeader(isheader);
  datatable.addCell(c);
}



private static void getPDFFromInvioGeneral() {
StringBuffer       buffer    = new StringBuffer();
NumberFormat       nf       =
NumberFormat.getInstance(Locale.ITALIAN);
String           sql_header = null;
String           sql_so    = null;
String           sql_ri    = null;
String           sql_sw    = null;
String           data_rif   = "";
String           lastkey   = "";
boolean           firstline  = true;

boolean           rec_so    = false;
boolean           rec_ri    = false;
boolean           rec_sw    = false;
boolean           rec      = false;
ByteArrayOutputStream baosPDF   = new ByteArrayOutputStream();
Font             font16B   = new Font(Font.TIMES_ROMAN, 16,
Font.BOLD, null);
Font             font16    = new Font(Font.TIMES_ROMAN, 16);
Font             font14B   = new Font(Font.TIMES_ROMAN, 14,
Font.BOLD, null);
Font             font14BU   = new Font(Font.TIMES_ROMAN, 14,
Font.BOLD + Font.UNDERLINE, null);
Font             font14    = new Font(Font.TIMES_ROMAN, 14);
Font             font12B   = new Font(Font.TIMES_ROMAN, 12,
Font.BOLD, null);
Font             font12    = new Font(Font.TIMES_ROMAN, 12);
Font             font10B   = new Font(Font.TIMES_ROMAN, 10,
Font.BOLD, null);
Font             font10BU   = new Font(Font.TIMES_ROMAN, 10,
Font.BOLD + Font.UNDERLINE, null);
Font             font10    = new Font(Font.TIMES_ROMAN, 10);
Font             font9B    = new Font(Font.TIMES_ROMAN, 9,
Font.BOLD, null);
Font             font9BU   = new Font(Font.TIMES_ROMAN, 9,
Font.BOLD + Font.UNDERLINE, null);
Font             font9     = new Font(Font.TIMES_ROMAN, 9);
Font             font8B    = new Font(Font.TIMES_ROMAN, 8,
Font.BOLD, null);


  try {


  Table datatableSO   = null;
  int   headerwidthsSO[] = {25, 8, 5, 15, 5};

  int   linenr       = 0;

   for (int j = 0; j < 50; j++) {
    datatableSO = new Table(5);
    datatableSO.setWidths(headerwidthsSO);
    datatableSO.setCellsFitPage(true);
    datatableSO.setDefaultCellBorder(Rectangle.NO_BORDER);
    datatableSO.setBorder(Rectangle.NO_BORDER);
    datatableSO.setWidth(100);
    datatableSO.setPadding(0);
    datatableSO.setSpaceInsideCell(3);
    datatableSO.setSpaceBetweenCells(0);
    datatableSO.setSpacing(0);
    datatableSO.setOffset(0);

    addCell(datatableSO, new Cell(new Phrase("HEADER LINE TYPE " + j,
font12B)), Element.ALIGN_CENTER, Element.ALIGN_CENTER, 5, 1,
Rectangle.NO_BORDER, 1, true);

    addCell(datatableSO, new Cell(new Phrase("xxxxxxxx:", font9B)),
Element.ALIGN_RIGHT, Element.ALIGN_CENTER, 1, 1, Rectangle.TOP +
Rectangle.LEFT, 1, true);
    addCell(datatableSO, new Cell(new
Phrase("LSKDJKLJSDLKGJKLFKLSFDKLG", font9B)), Element.ALIGN_LEFT,
Element.ALIGN_CENTER, 4, 1, Rectangle.TOP + Rectangle.RIGHT, 1, true);
    addCell(datatableSO, new Cell(new Phrase("YYYYYYYYY:", font9B)),
Element.ALIGN_RIGHT, Element.ALIGN_CENTER, 1, 1, Rectangle.BOTTOM +
Rectangle.LEFT, 1, true);
    addCell(datatableSO, new Cell(new
Phrase("LKSJRKJHSDKJGHJKSDHFGJKHSDKFJHGJKSDF", font9B)), Element.ALIGN_LEFT,
Element.ALIGN_CENTER, 4, 1, Rectangle.BOTTOM + Rectangle.RIGHT, 1, true);

    addCell(datatableSO, new Cell(new Phrase("Col1", font9B)),
Element.ALIGN_CENTER, Element.ALIGN_CENTER, 1, 1, Rectangle.BOX, 0.9f,
true);
    addCell(datatableSO, new Cell(new Phrase("Col2", font9B)),
Element.ALIGN_CENTER, Element.ALIGN_CENTER, 1, 1, Rectangle.BOX, 0.9f,
true);
    addCell(datatableSO, new Cell(new Phrase("Col3", font9B)),
Element.ALIGN_CENTER, Element.ALIGN_CENTER, 1, 1, Rectangle.BOX, 0.9f,
true);
    addCell(datatableSO, new Cell(new Phrase("Col4", font9B)),
Element.ALIGN_CENTER, Element.ALIGN_CENTER, 1, 1, Rectangle.BOX, 0.9f,
true);
    addCell(datatableSO, new Cell(new Phrase("Col5", font9B)),
Element.ALIGN_CENTER, Element.ALIGN_CENTER, 1, 1, Rectangle.BOX, 0.9f,
true);
    datatableSO.endHeaders();
    System.out.println("header " + j + " added");
    for (int i = 0; i < j % 13 + 5; i++) {

      linenr++;
      addCell(datatableSO, new Cell(new Phrase("SOME WIDE TEXT SOME WIDE
TEXT SOME WIDE TEXT SOME WIDE TEXT", font9B)), Element.ALIGN_LEFT,
Element.ALIGN_CENTER, 1, 1, Rectangle.BOX);
      addCell(datatableSO, new Cell(new Phrase("SMALLTEXTTTTTT",
font9)), Element.ALIGN_CENTER, Element.ALIGN_LEFT, 1, 1, Rectangle.BOX);
      addCell(datatableSO, new Cell(new Phrase("MAKE SOME WRAP",
font9B)), Element.ALIGN_CENTER, Element.ALIGN_CENTER, 1, 1, Rectangle.BOX);
      addCell(datatableSO, new Cell(new Phrase("Number " + linenr,
font9B)), Element.ALIGN_RIGHT, Element.ALIGN_RIGHT, 1, 1, Rectangle.BOX);
      addCell(datatableSO, new Cell(new Phrase("XXX", font9)),
Element.ALIGN_CENTER, Element.ALIGN_CENTER, 1, 1, Rectangle.BOX);

      System.out.println("  ... line " + j + " " + i + " added");
    }
    System.out.println("body " + j + " added");
    datatableSO.complete();
    doc.add(datatableSO);
    doc.add(new
Phrase("**************************************************************"));
   }

  } catch (Exception e) {
   e.printStackTrace();
  }

}
public static void main(String[] args) {
  doc = new Document(PageSize.A4.rotate(), 50, 50, 50, 50);

  try {
   PdfWriter.getInstance(doc, new FileOutputStream("c:/xxx_" +
doc.getVersion() + ".pdf"));
   doc.open();

   getPDFFromInvioGeneral();

  } catch (Exception e) {
   e.printStackTrace();
  }
  doc.close();
}


}


/*************************************************************



Best regards and TX,
Stefan


and an the result pdf: <<xxx_iText 1.3 by lowagie.com (based on
itext-paulo-153).pdf>>

*************************************************************/


Questo documento e gli eventuali allegati sono indirizzati unicamente al
destinatario, a cui la lettura e l'utilizzo delle informazioni contenute
sono esclusivamente riservati. Nel caso di utilizzo non autorizzato, Banca
Sella potra' dar corso alle azioni piu' opportune per il risarcimento dei
danni subiti anche da terzi. Nell'ipotesi che la e-mail non fosse
indirizzata a Voi o il contenuto lasci intendere che possano esservi stati
errori o manipolazioni nella trasmissione, vogliate cortesemente contattare
i seguenti indirizzi di posta elettronica: info@(protected)

This e-mail is directed uniquely to the interested party, which is the
exclusive addressee of any information contained herein. For any abuse about
the content of this message, Banca Sella will claim compensation for damages
occurred to third parties as well. In case the e-mail should be addressed to
other than you, or the content should reveal any transmission errors or
manipulations, please contact us at the following address: info@(protected);
reclami@(protected)
Il seguente messaggio conteneva il file xxx_iText 1.3 by lowagie.com (based on itext-paulo-153).pdf che รจ stato rimosso per motivi di sicurezza.
©2008 junlu.com - Jax Systems, LLC, U.S.A.