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.FontFamily;
- import com.itextpdf.text.Paragraph;
- import com.itextpdf.text.Font;
- import com.itextpdf.text.FontFactory;
- import com.itextpdf.text.pdf.PdfPCell;
- import com.itextpdf.text.pdf.PdfPTable;
- import com.itextpdf.text.pdf.PdfWriter;
- public class Deck_Of_Cards {
- public static final String RESULT = "allCardsl.pdf";
- public static void main(String[] args)
- throws DocumentException, IOException {
- new Deck_Of_Cards().createPdf(RESULT);
- }
- public static final Font NORMAL = new Font(FontFamily.SYMBOL, 12);
- public static final Font RED = new Font(FontFamily.SYMBOL, 12);
- public void createPdf(String filename) throws DocumentException, IOException
- {
- Document document = new Document();
- PdfWriter.getInstance(document, new FileOutputStream(filename));
- document.open();
- document.add(createTable());
- document.close();
- }
- public PdfPTable createTable()
- {
- PdfPTable table = new PdfPTable(4);
- table.setWidthPercentage(80);
- table.getDefaultCell().setFixedHeight(140);
- table.getDefaultCell().setPadding(40);
- char[] cards = {'2', '3', '4', '5', '6', '7', '8', '9','T','J','Q', 'K','A'};
- int[] suites = {167,170,168,169};
- for (int i = 0; i < cards.length; i++) {
- for (int j = 0; j < suites.length; j++) {
- int code = suites[j];
- char suite = (char)code;
- if(j == 2 || j == 3)
- {
- RED.setColor(BaseColor.RED);
- Paragraph p = new Paragraph("\n\n" + cards[i] + "" + suite, RED);
- p.setAlignment(Element.ALIGN_CENTER);
- p.setAlignment(Element.ALIGN_MIDDLE);
- table.addCell(p);
- }
- else{
- Paragraph d = new Paragraph("\n\n" + cards[i] + "" + suite, NORMAL);
- d.setAlignment(Element.ALIGN_CENTER);
- table.addCell(d);
- }
- }
- }
- return table;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment