Foros del Web » Programación para mayores de 30 ;) » Java »

itext 2.0

Estas en el tema de itext 2.0 en el foro de Java en Foros del Web. Estoy usando itext la version 1.2 y tiene que ser esta aunque haya mas actuales. Tengo la siguiente clase import java.awt.Color; import java.io.FileNotFoundException; import java.io.FileOutputStream; ...
  #1 (permalink)  
Antiguo 22/04/2010, 04:41
 
Fecha de Ingreso: octubre-2008
Ubicación: Madrid
Mensajes: 352
Antigüedad: 15 años, 6 meses
Puntos: 5
itext 2.0

Estoy usando itext la version 1.2 y tiene que ser esta aunque haya mas actuales.

Tengo la siguiente clase

import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import com.lowagie.text.BadElementException;
import com.lowagie.text.Cell;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

public class pruebaPDFPOI {

private static final int Letra = Font.NORMAL;

/**
* @param args
* @throws DocumentException
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException, DocumentException {
try {

Document document = new Document(PageSize.A4.rotate(), 50, 50, 30, 50);//izquierda,derecha,arriba,abajo
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("D:\\resumenPlan.pdf"));
document.open();

Table table = new Table(2);
// 2 pixel wide blue border
table.setWidth(100);
//table.setBackgroundColor(Color.GRAY);
table.setPadding(3);
//table.setSpacing(3);
table.setBorderWidth(0);
table.setAlignment(Element.ALIGN_LEFT);

table.setWidths(new int[]{70,30});

Font font = new Font(Letra, 16, Font.BOLD);
font.setColor(new Color(255 ,255, 255));
Chunk chunk = new Chunk("Referencias", font);
Cell c = new Cell(chunk);
c.setHeader(false);
c.setBorder(0);
c.setBackgroundColor(new Color(176 ,196 ,222));
c.setHorizontalAlignment(Element.ALIGN_LEFT);

table.addCell(c);
c = new Cell(Image.getInstance("D:/WS_INDRABMB/Proyecto_Egeo/WebContent/view/protected/img/indra_bmb.png"));
c.setHeader(false);
c.setBorder(0);
c.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(c);

document.add(table);

document.addTitle("TITULO");

Chunk underlined = new Chunk("Gestión de nómina y beneficios sociales ");
underlined.setTextRise(0.0f);
//1) 2)Grosor del fondo de linea
//underlined.setUnderline(new Color(169,169,169), 0.0f, 0.2f, 3.0f, -0.5f, PdfContentByte.LINE_CAP_PROJECTING_SQUARE);
document.add(new Paragraph(underlined));

//Fila 1
filas(document,"Cliente", "nombre cliente", false);

//Fila 2
filas(document,"Proyecto", "asfasdfasdddddddfffffffffffffffffffffffffffffffff fffffffffffffffffffffffffffafasdfsadfasdfasdfasdfa sdf" +
"asfasdfasdddddddfffffffffffffffffffffffffffffffff fffffffffffffffffffffffffffafasdfsadfasdfasdfasdfa sdf" +
"asfasdfasdddddddfffffffffffffffffffffffffffffffff fffffffffffffffffffffffffffafasdfsadfasdfasdfasdfa sdf" +
"asfasdfasdddddddfffffffffffffffffffffffffffffffff fffffffffffffffffffffffffffafasdfsadfasdfasdfasdfa sdf" +
"asfasdfasdddddddfffffffffffffffffffffffffffffffff fffffffffffffffffffffffffffafasdfsadfasdfasdfasdfa sdf" +
"asfasdfasdddddddfffffffffffffffffffffffffffffffff fffffffffffffffffffffffffffafasdfsadfasdfasdfasdfa sdf" +
"asfasdfasdddddddfffffffffffffffffffffffffffffffff fffffffffffffffffffffffffffafasdfsadfasdfasdfasdfa sdf", false);
//Fila 3
filas(document,"Aportación de Valor","asdfasdfasdfasdffasdffffffffffffffffffffff fffffffffffffffffffffffffffffffffffffff", false);
//Fila 4
filas(document,"Dimensionamiento", "esto es el dimensionamiento", false);

document.close();
}
catch (Exception e2) {
System.out.println(e2.getMessage());
}

}

private static void filas(Document document, String textoIzq, String textoDerecha, boolean derechaBordeada) throws DocumentException {
//TABLAS INFERIORES
Table table = new Table(5);
table.setSpacing(0);
// 2 pixel wide blue border
table.setWidth(100);
//table.setBackgroundColor(Color.GRAY);
table.setPadding(3);
//table.setSpacing(3);
table.setBorderWidth(0);
table.setAlignment(Element.ALIGN_LEFT);
table.setWidths(new int[]{30,2,2,1,65});


Font font = new Font(Letra, 10, Font.BOLD); // 1
font.setColor(new Color(0 ,0, 255));
Chunk chunk =new Chunk(textoIzq + "\n\n", font); // 2

Cell c;

//columna titulos izquierda
c = new Cell(chunk);
c.setHeader(false);
c.setBorder(0);
c.setBackgroundColor(new Color(176 ,196 ,222)); //color fondo cabeceras izquierda
c.setHorizontalAlignment(Element.ALIGN_LEFT);
c.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(c);

//Vacia
columnaEspacioEnColor(table); //entre primera columna y segunda

//Vacia
c = new Cell("");
c.setHeader(false);
c.setBorder(0);
c.setBackgroundColor(new Color(255, 250, 250));
table.addCell(c);

//Derecha
c = new Cell();
c.setBorder(0);
table.addCell(c);

font = new Font(Letra, 8, Letra); // 1
font.setColor(new Color(105, 105, 105));
chunk =new Chunk(textoDerecha, font); // 2

c = new Cell(chunk);
c.setHeader(false);
if(derechaBordeada){
c.setBorderWidth((float) 0.5);
c.setBorderColor(new Color(0, 0, 255));
}
else{
c.setBorder(0);
}
c.setHorizontalAlignment(Element.ALIGN_LEFT);
//c.setMaxLines(1);

table.addCell(c);

c = new Cell("");
c.setHeader(false);
c.setBorder(0);
c.setBackgroundColor(new Color(255, 250, 250));
//c.setHorizontalAlignment(Element.ALIGN_LEFT);
//c.setVerticalAlignment(Element.ALIGN_TOP);
c.setColspan(5);
table.addCell(c);

document.add(table);
}


private static void columnaEspacioEnColor(Table table) {
Cell c;
c = new Cell("");
c.setHeader(false);
c.setBorder(0);
c.setBackgroundColor(new Color( 245 ,245 ,245));
table.addCell(c);
}


}


El problema que tengo que cada vez que llamo al método "filas" se genera un tabla con los valores que quiero. Y me mete espacio en blanco entre cada una de las filas...

¿Como se puede quitar para que no haya ese espacion en blanco?
Gracias.

Etiquetas: itext
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 13:05.