Ver Mensaje Individual
  #2 (permalink)  
Antiguo 19/05/2011, 16:28
abulon81
 
Fecha de Ingreso: mayo-2010
Mensajes: 99
Antigüedad: 14 años, 6 meses
Puntos: 5
Respuesta: create table with itext

Oops!, There I go again, put the remaining code here.

Código PHP:
public void pintaEncabezado(JTextField tituloini,JTextField textJTextArea textArea,JTextField tipoliza,Document document) {
        try{


            
//            PdfWriter.getInstance(document,resp.getOutputStream()); //FIXME for web
//                    PdfWriter.getInstance(document, new FileOutputStream("c:/tmp_Siniestros/prueba.pdf"));
//                    document.open();
//                    Image img1 = Image.getInstance("/JDeveloper10132/jdev/mywork/JDK4_4/ViewController/public_html/css/images/OXXOwm2.png");//agrega imagen
//            //            Image img1 = Image.getInstance(this.getClass().getClassLoader().getResource("/css/images/OXXOwm2.png"));//agrega imagen //FIXME FOR WEB
//                    img1.scaleToFit(600, 600);//escala de la imagen
//                    img1.setAlignment(Image.MIDDLE| Image.UNDERLYING);//imagen centrada y de fondo.
//                    document.add(img1);
                    
Image img2 Image.getInstance("/JDeveloper10132/jdev/mywork/JDK4_4/ViewController/public_html/css/images/Logo_OXXO.gif");//agrega imagen
            //            Image img2 = Image.getInstance(this.getClass().getClassLoader().getResource("/css/images/Logo_OXXO.gif"));//agrega imagen //FIXME FOR WEB
                    
img2.scaleToFit(100100);//escala de la imagen
                    
img2.setAlignment(Image.ALIGN_LEFT);//imagen centrada y de fondo.
                    
                //[TABLA #1] Encabezado
                     
PdfPCell cell;
                     
PdfPTable titulo = new PdfPTable(1);
                     
//titulo.setSpacingAfter(10f);
                     
titulo.setWidthPercentage(100);
                     
                     
cell = new PdfPCell(new Paragraph(tituloini!=null?tituloini.getText():"",FUENTE_NUM3));
                     
cell.setBorder(0);
                     
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                     
cell.setVerticalAlignment(Element.ALIGN_TOP);
                     
titulo.addCell(cell);
                     
                     
cell = new PdfPCell(new Paragraph(text.getText(),FUENTE_NUM3));
                     
cell.setBorder(0);
                     
cell.setPaddingTop(10f);
                     
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                     
cell.setVerticalAlignment(Element.ALIGN_TOP);
                     
titulo.addCell(cell);
                     
document.add(titulo);
                
                     
float[] widths = {83f,346f };//ancho tabla
                     
PdfPTable table = new PdfPTable(widths);
                     
                     
cell = new PdfPCell(img2);
                     
cell.setFixedHeight(50f);
                     
cell.setBorder(0);
                     
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                     
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                     
table.addCell(cell);  
                     
                     
cell = new PdfPCell(new Paragraph(textArea.getText(), FUENTE_NUM2));
                     
cell.setBorder(0);
                     
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                     
cell.setVerticalAlignment(Element.ALIGN_TOP);
                     
table.addCell(cell);
                     
        
//             float[] widths = {83f,346f };//ancho tabla
        //             Rectangle r = new Rectangle(PageSize.A4.getRight(150), PageSize.A4.getTop(120));
                     
table.setWidthPercentage(100);
                     
table.setHorizontalAlignment(Element.ALIGN_LEFT);
                     
table.setSpacingBefore(20f);
                    
            
//            float[] widths = { 95f,330f };//ancho tabla
            //            Rectangle r = new Rectangle(PageSize.A4.getRight(150), PageSize.A4.getTop(120));
            //            table.setWidthPercentage(widths, r);
                    
                     
table.setHorizontalAlignment(Element.ALIGN_LEFT);
                     
table.setSpacingBefore(20);
                     
document.add(table);//AGREGAR TABLA #1 AL DOCUMENTO
                     
                      ////////tabla de plaza y fecha
                      
float[] width4 = { 11f,15f,11f,15f};  
                      
PdfPTable plazfec = new PdfPTable(width4);
                      
plazfec.setWidthPercentage(100f); 
                      
plazfec.setSpacingBefore(10f);
                      
                      
cell = new PdfPCell(new Paragraph(ttlPlaza.getText(),FUENTE_NUM2));
                      
cell.setBorder(0);
                      
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                      
cell.setVerticalAlignment(Element.ALIGN_TOP);
                      
plazfec.addCell(cell);
                      
                      
cell = new PdfPCell(new Paragraph("ok",FUENTE_NUM2));
                      
cell.setBorder(2);
                      
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                      
cell.setVerticalAlignment(Element.ALIGN_TOP);
                      
plazfec.addCell(cell); 
                      
                      
cell = new PdfPCell(new Paragraph(ttlFecha.getText(),FUENTE_NUM2));
                      
cell.setBorder(0);
                      
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                      
cell.setVerticalAlignment(Element.ALIGN_TOP);
                      
plazfec.addCell(cell);
                      
                      
cell = new PdfPCell(new Paragraph("ok",FUENTE_NUM2));
                      
cell.setBorder(2);
                      
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                      
cell.setVerticalAlignment(Element.ALIGN_TOP);
                      
plazfec.addCell(cell);
                                 
                      
document.add(plazfec);
                      
                      
PdfPTable poliza = new PdfPTable(1);
                      
poliza.setWidthPercentage(100f);
                      
poliza.setSpacingBefore(10f);
                      
                      
cell = new PdfPCell(new Paragraph(tipoliza.getText(),FUENTE_NUM2));
                      
cell.setBorder(0);
                      
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                      
cell.setVerticalAlignment(Element.ALIGN_TOP);
                      
poliza.addCell(cell);
                      
document.add(poliza);

                      
///fin tabla fecha y plaza
                     
                      
}
                      
                      catch(
DocumentException de){
                          
System.err.println(de.getMessage());
                      }
                      catch(
IOException ioe){
                          
System.err.println(ioe.getMessage());
                      }
    } 
Cheers