Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileOutputStream;
- import java.io.IOException;
- import com.itextpdf.text.BaseColor;
- import com.itextpdf.text.Document;
- import com.itextpdf.text.DocumentException;
- import com.itextpdf.text.Element;
- import com.itextpdf.text.Font;
- import com.itextpdf.text.Paragraph;
- import com.itextpdf.text.pdf.BaseFont;
- import com.itextpdf.text.pdf.PdfPTable;
- import com.itextpdf.text.pdf.PdfWriter;
- public class DeckOfCards {
- public static void main(String[] args) throws DocumentException, IOException {
- Document document = new Document();
- PdfWriter.getInstance(document, new FileOutputStream("Deck-of-Cards.pdf"));
- document.open();
- PdfPTable table = new PdfPTable(4);
- table.setWidthPercentage(55);
- table.getDefaultCell().setFixedHeight(55);
- table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
- table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
- BaseFont baseFont = BaseFont.createFont("times.ttf", BaseFont.IDENTITY_H, true);
- Font black = new Font(baseFont, 30f, 0, BaseColor.BLACK);
- Font red = new Font(baseFont, 30f, 0, BaseColor.RED);
- String card = " ";
- char symbol = ' ';
- for(int i = 1; i < 14; i++)
- {
- switch(i)
- {
- case 1 : card = "A"; break;
- case 10 : card = "10"; break;
- case 11 : card = "J"; break;
- case 12 : card = "Q"; break;
- case 13 : card = "K"; break;
- default : card = " " + i; break;
- }
- for(int j = 0; j < 4; j++)
- {
- switch (j)
- {
- case 0 : symbol = '♠'; table.addCell(new Paragraph(card + symbol, black));
- break;
- case 1 : symbol = '♥'; table.addCell(new Paragraph(card + symbol, red)); break;
- case 2 : symbol = '♣'; table.addCell(new Paragraph(card + symbol, black)); break;
- case 3 : symbol = '♦'; table.addCell(new Paragraph(card + symbol, red)); break;
- }
- }
- }
- document.add(table);
- document.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment