Guest User

DeckOfCards

a guest
May 6th, 2014
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. import java.io.FileOutputStream;
  2. import java.io.IOException;
  3.  
  4.  
  5.  
  6.  
  7. import com.itextpdf.text.BaseColor;
  8. import com.itextpdf.text.Document;
  9. import com.itextpdf.text.DocumentException;
  10. import com.itextpdf.text.Element;
  11. import com.itextpdf.text.Font.FontFamily;
  12. import com.itextpdf.text.Paragraph;
  13. import com.itextpdf.text.Font;
  14. import com.itextpdf.text.FontFactory;
  15. import com.itextpdf.text.pdf.PdfPCell;
  16. import com.itextpdf.text.pdf.PdfPTable;
  17. import com.itextpdf.text.pdf.PdfWriter;
  18.  
  19. public class Deck_Of_Cards {
  20.     public static final String RESULT = "allCardsl.pdf";
  21.    
  22.     public static void main(String[] args)
  23.        
  24.         throws DocumentException, IOException {
  25.             new Deck_Of_Cards().createPdf(RESULT);
  26.         }
  27.        
  28.     public static final Font NORMAL = new Font(FontFamily.SYMBOL, 12);
  29.     public static final Font RED = new Font(FontFamily.SYMBOL, 12);
  30.    
  31.     public void createPdf(String filename) throws DocumentException, IOException
  32.     {
  33.         Document document = new Document();
  34.         PdfWriter.getInstance(document, new FileOutputStream(filename));
  35.         document.open();
  36.         document.add(createTable());
  37.         document.close();
  38.     }
  39.        
  40.        
  41.     public PdfPTable createTable()
  42.     {
  43.        
  44.         PdfPTable table = new PdfPTable(4);
  45.        
  46.         table.setWidthPercentage(80);
  47.         table.getDefaultCell().setFixedHeight(140);
  48.         table.getDefaultCell().setPadding(40);
  49.         char[] cards = {'2', '3', '4', '5', '6', '7', '8', '9','T','J','Q', 'K','A'};
  50.         int[] suites = {167,170,168,169};
  51.        
  52.  
  53.         for (int i = 0; i < cards.length; i++) {
  54.             for (int j = 0; j < suites.length; j++) {
  55.                 int code = suites[j];
  56.                 char suite = (char)code;
  57.                 if(j == 2 || j == 3)
  58.                 {
  59.                     RED.setColor(BaseColor.RED);
  60.                     Paragraph p = new Paragraph("\n\n" + cards[i] + "" + suite, RED);
  61.                     p.setAlignment(Element.ALIGN_CENTER);
  62.                     p.setAlignment(Element.ALIGN_MIDDLE);
  63.                     table.addCell(p);
  64.                    
  65.                 }
  66.                 else{
  67.                        
  68.                         Paragraph d = new Paragraph("\n\n" + cards[i] + "" + suite, NORMAL);
  69.                         d.setAlignment(Element.ALIGN_CENTER);
  70.                         table.addCell(d);
  71.                     }
  72.             }
  73.         }
  74.            
  75.      return table;
  76.     }
  77.  
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment