2013-11-09 59 views
0

我想導出java..But我得到下面的PDF文件中的PDF表格的對齊問題利用iText PDF庫從數據庫記錄到PDF ..如何增加PdfPTable的寬度iText的PDF閱讀器

1.表格未顯示在完整的pdf頁面中。它將從pdf頁面的左側和右側留出空格。

2.每個頁面的顯示值只有.Means PDF表在PDF頁面的一半顯示頁面的一半..

這裏是我的代碼..

Document document = new Document(); 
     PdfWriter.getInstance(document, fos); 


     PdfPTable table = new PdfPTable(10); 

     table.setWidthPercentage(100); 
     table.setSpacingBefore(0f); 
     table.setSpacingAfter(0f); 



     PdfPCell cell = new PdfPCell(new Paragraph("DateRange")); 

     cell.setColspan(10); 
     cell.setHorizontalAlignment(Element.ALIGN_CENTER); 
     cell.setPadding(5.0f); 
     cell.setBackgroundColor(new BaseColor(140, 221, 8)); 

     table.addCell(cell); 

     table.addCell("Calldate"); 
     table.addCell("Calltime"); 
     table.addCell("Source"); 
     table.addCell("DialedNo"); 
     table.addCell("Extension"); 
     table.addCell("Trunk"); 
     table.addCell("Duration"); 
     table.addCell("Calltype"); 
     table.addCell("Callcost"); 
     table.addCell("Site"); 

     while (rs.next()) { 
      table.addCell(rs.getString("date")); 
      table.addCell(rs.getString("time")); 
      table.addCell(rs.getString("source")); 
      table.addCell(rs.getString("destination")); 
      table.addCell(rs.getString("extension")); 
      table.addCell(rs.getString("trunk")); 
      table.addCell(rs.getString("dur")); 
      table.addCell(rs.getString("toc")); 
      table.addCell(rs.getString("callcost")); 
      table.addCell(rs.getString("Site")); 
     } 




     table.setSpacingBefore(5.0f);  // Space Before table starts, like margin-top in CSS 
     table.setSpacingAfter(5.0f);  // Space After table starts, like margin-Bottom in CSS           

     document.open();//PDF document opened........     

     document.add(Chunk.NEWLINE); //Something like in HTML :-) 

     document.add(new Paragraph("TechsoftTechnologies.com")); 
     document.add(new Paragraph("Document Generated On - " + new Date().toString())); 

     document.add(table); 
     document.add(Chunk.NEWLINE); //Something like in HTML :-)   
     document.newPage();   //Opened new page 
        //In the new page we are going to add list 

     document.close(); 

     fos.close(); 

回答

4

我在我明白你想壓制利潤率之前多次閱讀你的問題。我複製/粘貼(和修改)您的示例,並且我認爲我無法重現您的問題,因爲我(和許多其他開發人員)習慣了頁面具有邊距的事實。

無論如何,這是我的版本的例子:FullPageTable並創建PDF文件:full_page_table.pdf

我做了一些細微的變化,比如:它沒有意義的傳遞'Paragraph'作爲一個PdfPCell,因爲Paragraph將被視爲一個Phrase,但我認爲你正在尋找的行是一個參數:

Document document = new Document(PageSize.A4, 0, 0, 0, 0); 

的零點定義邊緣的寬度,如果我明白你的問題正確地說,你想壓制這些利潤率。

至於你的指控每個畫面都顯示只有.Means PDF表在PDF頁面的一半顯示頁面的一半價值,我認爲你是導致該自己通過引入document.newPage();否則你的指控沒有按」沒有道理;-)