Guest User

Untitled

a guest
May 6th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. import java.io.FileOutputStream;
  2. import java.io.IOException;
  3. import com.itextpdf.text.BaseColor;
  4. import com.itextpdf.text.Document;
  5. import com.itextpdf.text.DocumentException;
  6. import com.itextpdf.text.Element;
  7. import com.itextpdf.text.Font;
  8. import com.itextpdf.text.Paragraph;
  9. import com.itextpdf.text.pdf.BaseFont;
  10. import com.itextpdf.text.pdf.PdfPTable;
  11. import com.itextpdf.text.pdf.PdfWriter;
  12.  
  13. public class DeckOfCards {
  14.  
  15. public static void main(String[] args) throws DocumentException, IOException {
  16.  
  17. Document document = new Document();
  18. PdfWriter.getInstance(document, new FileOutputStream("Deck-of-Cards.pdf"));
  19. document.open();
  20.  
  21. PdfPTable table = new PdfPTable(4);
  22. table.setWidthPercentage(55);
  23. table.getDefaultCell().setFixedHeight(55);
  24. table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
  25. table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
  26.  
  27. BaseFont baseFont = BaseFont.createFont("times.ttf", BaseFont.IDENTITY_H, true);
  28. Font black = new Font(baseFont, 30f, 0, BaseColor.BLACK);
  29. Font red = new Font(baseFont, 30f, 0, BaseColor.RED);
  30.  
  31. String card = " ";
  32. char symbol = ' ';
  33.  
  34. for(int i = 1; i < 14; i++)
  35. {
  36. switch(i)
  37. {
  38. case 1 : card = "A"; break;
  39. case 10 : card = "10"; break;
  40. case 11 : card = "J"; break;
  41. case 12 : card = "Q"; break;
  42. case 13 : card = "K"; break;
  43. default : card = " " + i; break;
  44. }
  45.  
  46. for(int j = 0; j < 4; j++)
  47. {
  48. switch (j)
  49. {
  50. case 0 : symbol = '♠'; table.addCell(new Paragraph(card + symbol, black));
  51. break;
  52. case 1 : symbol = '♥'; table.addCell(new Paragraph(card + symbol, red)); break;
  53. case 2 : symbol = '♣'; table.addCell(new Paragraph(card + symbol, black)); break;
  54. case 3 : symbol = '♦'; table.addCell(new Paragraph(card + symbol, red)); break;
  55. }
  56. }
  57. }
  58. document.add(table);
  59. document.close();
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment