List of usage examples for com.lowagie.text.pdf PdfPRow PdfPRow
public PdfPRow(PdfPRow row)
From source file:net.sf.firemox.deckbuilder.BuildBook.java
License:Open Source License
/** * /*from w w w . j a va2 s . com*/ */ @SuppressWarnings("unchecked") public void build() { BufferedReader in = null; try { in = new BufferedReader(new InputStreamReader(new FileInputStream(MToolKit.getFile(checklist)), Charset.forName("ISO-8859-1"))); } catch (FileNotFoundException e) { e.printStackTrace(); return; } // String charset = Charset.forName("ISO-8859-1").name(); String line = null; int cur = 0; int row = 0; PdfPCell[] cells = new PdfPCell[3]; PdfPTable table = new PdfPTable(3); Document document = new Document(PageSize.A4); try { PdfWriter.getInstance(document, new FileOutputStream(this.pdfBook)); document.open(); } catch (Exception e) { e.printStackTrace(); return; } try { in.readLine(); // Removing header line String[] tokens = new String[] { "\t", "\\s{2,}" }; while ((line = in.readLine()) != null) { // line = new String(line.getBytes(),charset); // Card# Card Name Artist Color Rarity String[] fields = null; for (String token : tokens) { fields = line.split(token); if (fields.length == 5) { break; } } if (fields == null || fields.length < 5) { System.err.println("Unable to parse " + line); continue; } else if (fields.length > 5) { System.out.println("Too many value found on " + line); } fields[1] = fields[1].trim(); fields[1] = fields[1].replaceAll("[ -]", "_"); fields[1] = fields[1].replaceAll("[/',\\u0092]", ""); fields[1] = fields[1].replaceAll("", "AE"); System.out.println("Inserting " + fields[1]); if (basicLands.containsKey(fields[1])) { int x = basicLands.get(fields[1]); cells[cur] = new PdfPCell(getImage(fields[1] + x), true); x++; basicLands.put(fields[1], x); } else { cells[cur] = new PdfPCell(getImage(fields[1]), true); } cur++; if (cur == 3) { for (int j = 0; j < cells.length; j++) { cells[j].setPadding(2.0f); } table.getRows().add(new PdfPRow(cells)); row++; cur = 0; cells = new PdfPCell[3]; } if (row == 3) { table.setWidthPercentage(100); document.add(table); table = new PdfPTable(3); row = 0; } } } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } document.close(); }