Advertisement
zontak

Create PDF

May 12th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. import com.itextpdf.text.BaseColor;
  2. import com.itextpdf.text.Document;
  3. import com.itextpdf.text.DocumentException;
  4. import com.itextpdf.text.Font;
  5. import com.itextpdf.text.Paragraph;
  6. import com.itextpdf.text.pdf.BaseFont;
  7. import com.itextpdf.text.pdf.PdfPTable;
  8. import com.itextpdf.text.pdf.PdfWriter;
  9.  
  10. import java.io.FileNotFoundException;
  11. import java.io.FileOutputStream;
  12. import java.io.IOException;
  13.  
  14.  
  15. public class myPDF {
  16.  
  17. public static void main(String[] args) throws DocumentException, IOException {
  18.  
  19. Document document = new Document();
  20. PdfWriter.getInstance(document, new FileOutputStream("MyPDF2.pdf"));
  21. document.addAuthor("zontak");
  22. document.addSubject("This is result from my first PDF document");
  23. document.addCreationDate();
  24. document.addProducer();
  25. document.open();
  26.  
  27. PdfPTable table = new PdfPTable(4);
  28. table.setWidthPercentage(100);
  29. table.getDefaultCell().setFixedHeight(180);
  30.  
  31. BaseFont baseFont = BaseFont.createFont("times.ttf", BaseFont.IDENTITY_H, true);
  32. Font black = new Font(baseFont, 82f, 0, BaseColor.BLACK);
  33. Font red = new Font(baseFont, 82f, 0, BaseColor.RED);
  34.  
  35. Font color = null;
  36. String [] cardStrings = new String [] {
  37. "2", "3", "4", "5",
  38. "6", "7", "8", "9",
  39. "10", "J", "Q", "K", "A" };
  40. String [] cardSuitStrings = new String [] { "♠", "♥", "♣", "♦" };
  41. String [] painting = new String [] { "black", "red", "black", "red" };
  42. for (int h = 0; h < cardSuitStrings.length; h++) {
  43. for (int k = 0; k < cardStrings.length; k++) {
  44. if (painting[h] == "red") {
  45. color = red;
  46. } else {
  47. color = black;
  48. }
  49. table.addCell(new Paragraph(cardStrings[k] + cardSuitStrings[h] , color));
  50. System.out.println(cardStrings[k] + cardSuitStrings[h]);
  51. }
  52. System.out.println();
  53. }
  54. document.add(table);
  55. document.close();
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement