2012-11-29 20 views
2

我使用iText在我的Android應用程序中生成PDF。我需要爲pdf添加一個LIST。這個列表需要來自我已經在適配器中擁有的數據。我的適配器已經準備好了正確的數據,所以我只需要知道如何將這些數據從適配器添加到我的PDF文件中,甚至以單元格爲單位的LIST形式。 PS:它是填充應用程序另一部分的動態數據。所以這些數據只需要在PDF中顯示即可。使用iText將適配器數據轉換成PDF

回答

2

這是在PDF表中添加數據的方式..

private static void descriptionTable(Document p,ArrayList<String> list) throws BadElementException 
     { 
      PdfPTable table = new PdfPTable(3); 

      table.setWidthPercentage(100); 

      PdfPCell c1 = new PdfPCell(new Phrase("Site Address",ele_noraml_black)); 
      c1.setHorizontalAlignment(Element.ALIGN_LEFT); 
      c1.setColspan(1); 
      c1.setBorderWidth(1); 
      c1.setPaddingBottom(10); 
      c1.setBorderColor(celalBorderColor); 
      table.addCell(c1); 



      c1 = new PdfPCell(new Phrase(list_tree_tree.get(0),ele_noraml_black)); 
      c1.setHorizontalAlignment(Element.ALIGN_LEFT); 
      c1.setBorderWidth(1); 
      c1.setColspan(2); 
      c1.setPaddingBottom(10); 
      c1.setBorderColor(celalBorderColor); 
      table.addCell(c1); 
try { 
       p.add(table); 
      } catch (DocumentException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
} 
+0

超。謝謝Mehul。加工。尼斯。 –

+0

歡迎爵士..... –