Visualizzazione dei risultati da 1 a 8 su 8
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    81

    Itext - pdf uso di PdfTable

    Non riesco ad ottenere in con il pdf la seguente forma tabellare:

    Codice PHP:
    <table width="620" border="1">   <tr>     <td width="20" rowspan="2" colspan=2></td>      <td width="11" colspan=2 rowspan="1"></td>     <td width="11" colspan=4 rowspan="1"></td>     <td width="11" colspan=3 rowspan="1"></td>        </tr>   <tr>          <td></td>     <td></td>     <td></td>     <td></td>     <td></td>     <td></td>     <td></td>     <td></td>     <td></td>   </tr>   <tr>     <td></td>     <td></td>     <td></td>     <td></td>     <td></td>     <td></td>     <td></td>     <td></td>     <td></td>     <td></td>     <td></td>   </tr> </table
    qui il mio codice

    Codice PHP:
    public static PdfPTable createFirstTable() {

             
    PdfPTable table = new PdfPTable(11);
            
    PdfPCell cell1 GetCell("territorio",2,2);
            
    table.addCell(cell1);
            
    table.addCell(GetCell("A",2,1));
            
    table.addCell(GetCell("B",4,1));
            
    table.addCell(GetCell("C",3,1));
     
            
    table.addCell(GetCell("D"));
            
    table.addCell(GetCell("E"));
            
    table.addCell(GetCell("F"));
            
    table.addCell(GetCell("G"));
            
    table.addCell(GetCell("H"));
            
    table.addCell(GetCell("I"));
            
    table.addCell(GetCell("L"));
            
    table.addCell(GetCell("M"));
            
    table.addCell(GetCell("N"));
            
            
    table.addCell(GetCell("1"));
            
    table.addCell(GetCell("2"));
            
    table.addCell(GetCell("3"));
            
    table.addCell(GetCell("4"));
            
    table.addCell(GetCell("5"));
            
    table.addCell(GetCell("6"));
            
    table.addCell(GetCell("7"));
            
    table.addCell(GetCell("8"));
            
    table.addCell(GetCell("9"));
            
    table.addCell(GetCell("10"));
            
    table.addCell(GetCell("11"));
            return 
    table;
        }
        
        private static 
    PdfPCell GetCell(String text) {
            return 
    GetCell(text11);
        }
        private static 
    PdfPCell GetCell(String textint colSpanint rowSpan ) {
            
    PdfPCell cell = new PdfPCell(new Phrase(text));
            
    cell.setHorizontalAlignment(1);
            
    cell.setRowspan(rowSpan);
            
    cell.setColspan(colSpan);
            
            return 
    cell;
        } 
    help?

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2004
    Messaggi
    309
    la seconda riga ha una cella in meno
    tomcat 6.016
    netbeans 6.1

  3. #3
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    81
    ne ha 2 cell1 + altre 9 non è corretto?

    l'errore che mi becco è:

    Exception in thread "main" java.lang.NullPointerException
    at com.lowagie.text.pdf.PdfPTable.getRowHeight(Unknow n Source)
    at com.lowagie.text.pdf.PdfPTable.calculateHeights(Un known Source)
    at com.lowagie.text.pdf.PdfPTable.setTotalWidth(Unkno wn Source)
    at com.lowagie.text.pdf.ColumnText.goComposite(Unknow n Source)
    at com.lowagie.text.pdf.ColumnText.go(Unknown Source)
    at com.lowagie.text.pdf.ColumnText.go(Unknown Source)

  4. #4
    Utente di HTML.it
    Registrato dal
    May 2004
    Messaggi
    309
    si cell1 si espande sulla riga sotto e poi seguono altre 9. totale 10 mentre ne vuole 11.
    per l'eccezione dal codice che hai postato non vedo niente che non va. poi non saprei la versione che usi non l'ho mai usata. sono partito direttamente con l'ultima
    tomcat 6.016
    netbeans 6.1

  5. #5
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    81
    cell1 si espande sulla riga sotto su 2 colonne e poi ne seguono 9, o forse ho capito male come funziona il colspan?

  6. #6
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    81
    Di seguito il codice,
    quello che vorrei ottenere è che A1 prenda il posto di A2 e B2
    quindi unire le celle (1.1 - 1.2 - 2.1 - 2.2) e metterci dentro il valore A1 al centro.


    codice:
     
    
    import java.awt.Color;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import com.lowagie.text.Document;
    import com.lowagie.text.DocumentException;
    import com.lowagie.text.Element;
    import com.lowagie.text.Font;
    import com.lowagie.text.Phrase;
    import com.lowagie.text.pdf.PdfPCell;
    import com.lowagie.text.pdf.PdfPTable;
    import com.lowagie.text.pdf.PdfWriter;
    
    public class Esempio {
    	
        public static final String RESULT= "c:/test.pdf";
     
        public static void main(String[] args)
            throws IOException, DocumentException {
            new Esempio().createPdf(RESULT);
        }
     
        public void createPdf(String filename)
            throws IOException, DocumentException {
    
            Document document = new Document();
            PdfWriter.getInstance(document, new FileOutputStream(filename));
            document.open();
            document.add(getHeader());
            document.close();
        }
         
        public static PdfPTable getHeader(){
        	PdfPTable table = new PdfPTable(11);
        	table.setWidthPercentage(100);
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); 
            PdfPCell c1 = getCell("A1",2,1);
        	c1.setBorderColorBottom(Color.BLUE);
            table.addCell(c1);
        	table.addCell(getCell("B1",2,1));
        	table.addCell(getCell("C1",4,1));
        	table.addCell(getCell("D1",3,1));
        	
        	table.addCell(getCell("A2",1,1));
        	table.addCell(getCell("B2",1,1));
        	
        	table.addCell(getCell("C2"));
            table.addCell(getCell("D2"));
            table.addCell(getCell("E2"));
            table.addCell(getCell("F2"));
            table.addCell(getCell("G2"));
            table.addCell(getCell("H2"));
            table.addCell(getCell("I2"));
            table.addCell(getCell("L2"));
            table.addCell(getCell("M2"));
            
            table.addCell(getCell("1"));
            table.addCell(getCell("2"));
        	table.addCell(getCell("3"));
            table.addCell(getCell("4"));
            table.addCell(getCell("5"));
            table.addCell(getCell("6"));
            table.addCell(getCell("7"));
            table.addCell(getCell("8"));
            table.addCell(getCell("9"));
            table.addCell(getCell("10"));
            table.addCell(getCell("11"));
            return table;
    	}
    
    	
    	private static  PdfPCell getCell(String text) {
            return getCell(text, 1, 1);
        }
        
    	private static  PdfPCell getCell(String text, int colSpan, int rowSpan) {
        	Font font=new Font();
        	font.setColor(Color.WHITE);
        	Phrase ph=new Phrase(text,font);
        	PdfPCell tmpcell = new PdfPCell(ph);
        	tmpcell.setHorizontalAlignment(1);
        	tmpcell.setRowspan(rowSpan);
        	tmpcell.setColspan(colSpan);
        	tmpcell.setBackgroundColor(Color.BLUE);
        	tmpcell.setPaddingBottom(8);
            return tmpcell;
        }
    }

  7. #7
    Utente di HTML.it
    Registrato dal
    May 2004
    Messaggi
    309
    scusami ma la prima risposta ho cannato. ho risposto in fretta mentre avevo un casino a lavoro.... in effetti era corretto come hai inserito le celle....
    tomcat 6.016
    netbeans 6.1

  8. #8
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    81
    Uso la 2.1.7 e in giro non trovo esempi di colspan e rowspan entrambi >1, sbaglio io a settare qualcosa o potrebbe essere un bug. Non riesco ad uscirne ma non sono ferrato su itext ho praticamente iniziato 3-4 giorni fa ad usarlo

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.