使用Java和使用iText以PDF格式生成的卡片组

时间:2015-01-16 19:47:23

标签: java pdf

我有下一个问题:

  1. 我已经用PDF创建了一个表格,但是我试图找到如何将单元格与它们之间的空格分开,所以它们看起来就像一张卡片。
  2. 我在PDF中打印/显示套装时遇到问题。我得到了排名,但西装丢失了。我尝试使用少量字体,但没有成功。
  3. 有什么想法吗?

    import java.io.FileOutputStream;
    import java.io.IOException;
    
    import com.itextpdf.text.BaseColor;
    import com.itextpdf.text.Chapter;
    import com.itextpdf.text.Document;
    import com.itextpdf.text.DocumentException;
    import com.itextpdf.text.Element;
    import com.itextpdf.text.Font;
    import com.itextpdf.text.List;
    import com.itextpdf.text.ListItem;
    import com.itextpdf.text.Paragraph;
    import com.itextpdf.text.Phrase;
    import com.itextpdf.text.Section;
    import com.itextpdf.text.pdf.BaseFont;
    import com.itextpdf.text.pdf.PdfPCell;
    import com.itextpdf.text.pdf.PdfPTable;
    import com.itextpdf.text.pdf.PdfWriter;
    
    public class DeckOf52Cards {
        public static void main(String[] args) throws DocumentException,IOException {
    
            Document generatePDF = new Document();
    
            FileOutputStream someName = new FileOutputStream("DeckOf52Cards.pdf");
    
            PdfWriter.getInstance(generatePDF, someName);
    
            generatePDF.open();
    
            BaseFont downloaded = BaseFont.createFont("Burn outfade away.ttf",BaseFont.IDENTITY_H,true);
    
            Font[] someStyle = {
                    new Font(downloaded, 40, 0, new BaseColor (0,0,0)),
                    new Font(downloaded, 40, 0, new BaseColor(255,0,0))             
                };  
    
            PdfPTable table = new PdfPTable(4);     
    
    
            String[] ranks ={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
            char[] suits = {'\u2660','\u2663','\u2666','\u2665'};
    
    
            for (int i = 0; i < ranks.length; i++) {
                for (int j = 0; j < suits.length; j++) {
    
                    if (suits[j] == '\u2666' || suits[j] == '\u2665') {
                        table.addCell(new Paragraph(suits[j] + ranks[i] + "",someStyle[0]));
                    }
                    else {
                        table.addCell(new Paragraph(ranks[i] + suits[j] + "",someStyle[1]));
                    }
                }
            }       
            generatePDF.add(table);
            generatePDF.close();
        }
    }
    

0 个答案:

没有答案