2012-08-11 2 views

답변

0

안녕 plese 체크 .... 당신의 친절한 도움을

Document doc = new Document(); 
    PdfWriter docWrite = null; 
    DecimalFormat df = new DecimalFormat("0.00"); 

    DB.getPlayerName_OrderBy(TID1 , Match_ID); 

    try { 
      String path = Environment.getExternalStorageDirectory().getPath() + "/Cric"; 

      Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); 
      Font bf12 = new Font(FontFamily.TIMES_ROMAN, 12); 

      File dir = new File(path); 

       if(!dir.exists()){dir.mkdirs();} 

      Log.d("PDFCreator", "PDF Path: " + path);     

      File file = new File(dir, "cric_sample.pdf"); 
      FileOutputStream fOut = new FileOutputStream(file); 

      docWrite = PdfWriter.getInstance(doc, fOut);   

      doc.addTitle("Cricket Scord Card 2013 PDF"); 
      doc.addCreationDate(); 
      doc.open(); 
      Paragraph p1 = new Paragraph(teamBatting + " Socre Card 2013 "); 

      float[] columnWidths = {5f, 5f, 2f, 2f,2f,2f,2f}; 
      PdfPTable table = new PdfPTable(columnWidths); 
      table.setWidthPercentage(90f); 

      insertCell(table, "Player Names", Element.ALIGN_LEFT, 1, bfBold12); 
      insertCell(table, "Wicket Status", Element.ALIGN_LEFT, 1, bfBold12); 
      insertCell(table, "Runs", Element.ALIGN_LEFT, 1, bfBold12); 
      insertCell(table, "Balls", Element.ALIGN_LEFT, 1, bfBold12); 
      insertCell(table, "6's", Element.ALIGN_LEFT, 1, bfBold12); 
      insertCell(table, "4's", Element.ALIGN_LEFT, 1, bfBold12); 
      insertCell(table, "SR", Element.ALIGN_LEFT, 1, bfBold12); 

      table.setHeaderRows(1); 

      for(int x= 0; x<DatabaseHandler.Player_SD.size(); x++){ 

       float SR; 

       if(DatabaseHandler.Player_SD.get(x).StrikerName == null) 
       { 
        break; 
       } 
       else 
       { 

        if(DatabaseHandler.Player_SD.get(x).Mrun !=0 &&DatabaseHandler.Player_SD.get(x).MBolls !=0) 
        { 
         SR= (((float)DatabaseHandler.Player_SD.get(x).Mrun/(float)DatabaseHandler.Player_SD.get(x).MBolls)) * 100; 
        } 
        else 
        { 
         SR =(float) 0.00; 
        } 

         insertCell(table, String.valueOf(DatabaseHandler.Player_SD.get(x).StrikerName), Element.ALIGN_LEFT, 1, bf12); 
         insertCell(table, String.valueOf(DatabaseHandler.Player_SD.get(x).MOut), Element.ALIGN_LEFT, 1, bf12); 
         insertCell(table, String.valueOf(DatabaseHandler.Player_SD.get(x).Mrun) , Element.ALIGN_LEFT, 1, bf12); 
         insertCell(table, String.valueOf(DatabaseHandler.Player_SD.get(x).MBolls), Element.ALIGN_LEFT, 1, bf12); 
         insertCell(table, String.valueOf(DatabaseHandler.Player_SD.get(x).MSix), Element.ALIGN_LEFT, 1, bf12); 
         insertCell(table, String.valueOf(DatabaseHandler.Player_SD.get(x).MFour), Element.ALIGN_LEFT, 1, bf12);      
         insertCell(table, String.valueOf(String.format("%.1f",SR)), Element.ALIGN_LEFT, 1, bf12); 
       } 
       } 

      // p1.setAlignment(Paragraph.ALIGN_CENTER); 
      p1.add(table); 
      doc.add(p1); 

    } catch (DocumentException de) { 
      Log.e("PDFCreator", "DocumentException:" + de); 
    } catch (IOException e) { 
      Log.e("PDFCreator", "ioException:" + e); 
    } 
    finally 
    { 
     if(doc != null) 
     { 
      doc.close(); 
     } 
     if(docWrite != null) 
     { 
      docWrite.close(); 
     } 
    }