Itext

Candhyjacques - 13 mai 2014 à 14:11
bonjour, comment augmenter la largeur d'un tableau en utilisant itext et de mettre un logo(image) au dessus du tableau!!! voici mon code

private void print() {
try{
     String input ="SELECT * FROM entree";
     PdfPTable table = new PdfPTable(8);
               PdfPCell cell=new PdfPCell(
                new Paragraph("LISTE DES ENTREES"));
                cell.setColspan(8);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);

		cell = new PdfPCell(new Phrase("Materiel"));
		cell.setColspan(0);
                cell.setBackgroundColor(new BaseColor(204, 204, 255));
		table.addCell(cell);

		cell = new PdfPCell(new Phrase("Date"));
		cell.setColspan(0);
                cell.setBackgroundColor(new BaseColor(204, 204, 255));
		table.addCell(cell);

		cell = new PdfPCell(new Phrase("Reference"));
		cell.setColspan(0);
                cell.setBackgroundColor(new BaseColor(204, 204, 255));
		table.addCell(cell);

                cell = new PdfPCell(new Phrase("Quantite"));
		cell.setColspan(0);
                cell.setBackgroundColor(new BaseColor(204, 204, 255));
		table.addCell(cell);

                cell = new PdfPCell(new Phrase("Designations"));
		cell.setColspan(0);
                cell.setBackgroundColor(new BaseColor(204, 204, 255));
		table.addCell(cell);

                cell = new PdfPCell(new Phrase("Panne"));
		cell.setColspan(0);
                cell.setBackgroundColor(new BaseColor(204, 204, 255));
		table.addCell(cell);

                cell = new PdfPCell(new Phrase("SIN"));
		cell.setColspan(0);
                cell.setBackgroundColor(new BaseColor(204, 204, 255));
		table.addCell(cell);

                cell = new PdfPCell(new Phrase("Client"));
		cell.setColspan(0);
                cell.setBackgroundColor(new BaseColor(204, 204, 255));
		table.addCell(cell);

                 pst=conn.prepareStatement(input);
                 rs=pst.executeQuery();
                 while(rs.next()){
                    //table.addCell(rs.getString("id"));

                    table.addCell(rs.getString("Materiel"));
                    //table.setWidths(new int[]{30, 30, 40});
                    table.addCell(rs.getString("Date"));
                    table.addCell(rs.getString("Reference"));
                    table.addCell(rs.getString("Quantite"));
                    table.addCell(rs.getString("Designations"));
                    table.addCell(rs.getString("Panne"));
                    table.addCell(rs.getString("SIN"));
                    table.addCell(rs.getString("Client"));
     // creation of a document-object
        Document document = new Document();
          try {
            // create a writer
            PdfWriter.getInstance(
            // that listens to the document
            document,
            // and directs a PDF-stream to a file
            new FileOutputStream("output.pdf"));
            //Image image1 = Image.getInstance("2miicon.png");
              //document.add(image1);

            // open document
            document.open();

            document.add(table);
        } catch (DocumentException de) {
            de.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
      document.close();
     }
    }catch(Exception e) {}
}



merci d'avance