List of usage examples for com.itextpdf.text Document Document
public Document()
Document
-object. From source file:bouttime.report.bracketsheet.BracketSheetReport.java
License:Open Source License
public static boolean generateReport(Dao dao, List<Group> list, String outputFile, boolean doBoutNumbers, boolean doTimestamp) { if (list.isEmpty()) { return false; }//from w w w. j av a 2 s. c o m // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(outputFile); if (fos == null) { return false; } PdfWriter writer = PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); String timestamp = ""; if (doTimestamp) { timestamp = DateFormat.getInstance().format(new Date()); } int rv; int i = 0; int size = list.size(); for (Group g : list) { rv = addBracket(cb, dao, g, doBoutNumbers); if (rv != PAGE_ERROR) { // Print the watermark, if necessary boolean doWatermark = false; String gClass = g.getClassification(); String wmValues = dao.getBracketsheetWatermarkValues(); if ((wmValues != null) && !wmValues.isEmpty()) { String[] tokens = wmValues.split(","); for (String s : tokens) { if (s.trim().equalsIgnoreCase(gClass)) { doWatermark = true; break; } } } int rotation = (rv == PAGE_ROUNDROBIN) ? 45 : 135; if (doWatermark) { PdfContentByte ucb = writer.getDirectContentUnder(); BaseFont helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false); ucb.saveState(); ucb.setColorFill(BaseColor.LIGHT_GRAY); ucb.beginText(); ucb.setFontAndSize(helv, 86); ucb.showTextAligned(Element.ALIGN_CENTER, gClass, document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, rotation); ucb.endText(); ucb.restoreState(); } if (doTimestamp) { rotation -= 45; float width = cb.getPdfWriter().getPageSize().getWidth(); int x = (rv == PAGE_ROUNDROBIN) ? 15 : (int) (width - 15); int y = 15; BracketSheetUtil.drawTimestamp(cb, null, x, y, 10, timestamp, rotation); } // If not doing bout numbers, this is an 'award' type of // bracket. So print an image/logo, if configured. if (!doBoutNumbers && (dao.getBracketsheetAwardImage() != null) && !dao.getBracketsheetAwardImage().isEmpty()) { Image image = Image.getInstance(Image.getInstance(dao.getBracketsheetAwardImage())); image.setRotationDegrees((rv == PAGE_ROUNDROBIN) ? 0 : 90); PositionOnPage positionOnPage = dao.getBracketsheetAwardImagePosition(); if (PositionOnPage.UPPER_RIGHT == positionOnPage) { float x = (rv == PAGE_ROUNDROBIN) ? document.getPageSize().getWidth() - 10 - image.getWidth() : 10; float y = document.getPageSize().getHeight() - 10 - image.getHeight(); image.setAbsolutePosition(x, y); cb.addImage(image); } else if (PositionOnPage.CENTER == positionOnPage) { // put the image in the background, in the middle of the page PdfContentByte ucb = writer.getDirectContentUnder(); float pageX = document.getPageSize().getWidth() / 2; float pageY = document.getPageSize().getHeight() / 2; float imageX = image.getWidth() / 2; float imageY = image.getHeight() / 2; image.setAbsolutePosition(pageX - imageX, pageY - imageY); ucb.addImage(image); } } if (++i < size) { document.newPage(); } } } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } catch (IOException ioe) { logger.error("IO Exception", ioe); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.bracketsheet.CommonBracketSheet.java
License:Open Source License
public Boolean doBlankPage(FileOutputStream fos, Dao dao) { if (!dao.isOpen()) { return false; }// w ww . ja va 2s .c om // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer if (fos == null) { return false; } PdfWriter writer = PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); drawBracket(cb, bf, dao, null, false); } catch (DocumentException de) { logger.error("Document Exception", de); return false; } catch (IOException ioe) { logger.error("IO Exception", ioe); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.bracketsheet.RoundRobinBracketSheetReport.java
License:Open Source License
public static Boolean doBlankPage(FileOutputStream fos, Dao dao, Integer numWrestlers) { if (!dao.isOpen()) { return false; }//from ww w . j a v a 2s .c o m // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer if (fos == null) { return false; } PdfWriter writer = PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); drawBracket(cb, bf, dao, null, numWrestlers); } catch (DocumentException de) { logger.error("Document Exception", de); return false; } catch (IOException ioe) { logger.error("IO Exception", ioe); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.matkey.MatKeyReport.java
License:Open Source License
/** * Generate the Mat Key report./*from www. j ava2 s. co m*/ * This is a color-coded report that maps the groups to a mat. * @param dao Dao object to use to retrieve data. * @return True if the report was generated. */ public static boolean doReport(Dao dao) { if (!dao.isOpen()) { logger.warn("Cannot create report : DAO not open"); return false; } String matValues = dao.getMatValues(); if ((matValues == null) || matValues.isEmpty()) { JFrame mainFrame = BoutTimeApp.getApplication().getMainFrame(); JOptionPane.showMessageDialog(mainFrame, "Mat values are not configured." + "\nSet the mat values in 'Edit -> Configuration'", "Mat Key Report error", JOptionPane.WARNING_MESSAGE); logger.warn("Cannot create report : mat values not configured"); return false; } // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: create and add content // create and add the header Paragraph p1 = new Paragraph(new Paragraph( String.format("%s %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()), FontFactory.getFont(FontFactory.HELVETICA, 10))); document.add(p1); Paragraph p2 = new Paragraph( new Paragraph("Mat Key Report", FontFactory.getFont(FontFactory.HELVETICA, 14))); p2.setAlignment(Paragraph.ALIGN_CENTER); document.add(p2); int cols = 4; // Class, Div, Weight, Mat // create and add the table PdfPTable datatable = new PdfPTable(cols); //int colWidths[] = { 55, 15, 15, 15 }; // percentage //datatable.setWidths(colWidths); datatable.getDefaultCell().setPadding(3); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell("Class"); datatable.addCell("Div"); datatable.addCell("Weight"); datatable.addCell("Mat"); datatable.setHeaderRows(1); // this is the end of the table header datatable.getDefaultCell().setBorderWidth(1); // Prepare the list of groups List<Group> groups = dao.getAllGroups(); Collections.sort(groups, new GroupClassDivWtSort()); // Prepare the list of mat values String[] mats = matValues.split(","); List<String> matList = new ArrayList<String>(); for (String m : mats) { matList.add(m.trim()); } for (Group g : groups) { String mat = g.getMat(); int idx = matList.indexOf(mat); datatable.getDefaultCell().setBackgroundColor(colorMap.get(idx)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(g.getClassification()); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(g.getAgeDivision()); datatable.addCell(g.getWeightClass()); datatable.addCell(g.getMat()); } datatable.setSpacingBefore(15f); // space between title and table document.add(datatable); } catch (DocumentException de) { logger.error("Document Exception", de); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.team.TeamReport.java
License:Open Source License
/** * Generate a summary report of the teams in the tournament. * This report lists the teams and the number of wresters on the team. * @param dao Dao object to use to retrieve data. * @return True if the report was generated. *//*from w w w . j a va2s . c o m*/ public static boolean doSummary(Dao dao) { if (!dao.isOpen()) { return false; } // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: create and add content // create and add the header Paragraph p1 = new Paragraph(new Paragraph( String.format("%s %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()), FontFactory.getFont(FontFactory.HELVETICA, 10))); document.add(p1); Paragraph p2 = new Paragraph( new Paragraph("Team Summary Report", FontFactory.getFont(FontFactory.HELVETICA, 14))); p2.setAlignment(Paragraph.ALIGN_CENTER); document.add(p2); int cols = 2; // Team name and Total String classVals = dao.getClassificationValues(); String[] classes = null; if (classVals != null) { if (classVals.length() > 0) { classes = classVals.split(","); cols += classes.length; } } // create and add the table PdfPTable datatable = new PdfPTable(cols); //int colWidths[] = { 55, 15, 15, 15 }; // percentage //datatable.setWidths(colWidths); datatable.getDefaultCell().setPadding(3); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell("Team Name"); // Make a column for each classification value int[] classesTotals = null; if (classes != null) { for (String c : classes) { datatable.addCell(c.trim()); } classesTotals = new int[classes.length]; for (int i = 0; i < classesTotals.length; i++) { classesTotals[i] = 0; } } datatable.addCell("Total"); datatable.setHeaderRows(1); // this is the end of the table header datatable.getDefaultCell().setBorderWidth(1); List<String> teams = dao.getTeams(); int total = 0; // total count of all wrestlers in this method int i = 0; for (String t : teams) { if ((i++ % 2) == 0) { datatable.getDefaultCell().setGrayFill(0.9f); } else { datatable.getDefaultCell().setGrayFill(1); } List<Wrestler> wrestlers = dao.getWrestlersByTeam(t); int count = wrestlers.size(); int rowTotal = 0; total += count; datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(t); if (classes != null) { //for (String c : classes) { for (int idx = 0; idx < classes.length; idx++) { String c = classes[idx].trim(); List<Wrestler> wrestlers2 = dao.getWrestlersByTeamClass(t, c); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); int count2 = wrestlers2.size(); datatable.addCell(Integer.toString(count2)); classesTotals[idx] += count2; rowTotal += count2; } } datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(Integer.toString(count)); // Check if there is an error in the counts. if ((classes != null) && (rowTotal != count)) { JFrame mainFrame = BoutTimeApp.getApplication().getMainFrame(); JOptionPane.showMessageDialog(mainFrame, "There is an error" + " with the total count for team '" + t + "'.\n" + "This is " + "most likely due to an incorrect classification value\nfor " + "one or more wrestlers.", "Team count error", JOptionPane.WARNING_MESSAGE); } } // Add totals row datatable.getDefaultCell().setGrayFill(0.7f); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell("Total"); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); if (classes != null) { for (int idx = 0; idx < classesTotals.length; idx++) { datatable.addCell(Integer.toString(classesTotals[idx])); } } datatable.addCell(Integer.toString(total)); datatable.setSpacingBefore(15f); document.add(datatable); } catch (DocumentException de) { logger.error("Document Exception", de); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.team.TeamReport.java
License:Open Source License
/** * Generate a detail report of the teams in the tournament. * This report includes the teams and all of the wrestlers on the team. * @param dao Dao object to use to retrieve data. * @return True if the report was generated. *//*from w w w. j ava 2 s .com*/ public static boolean doDetail(Dao dao) { if (!dao.isOpen()) { return false; } // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: create and add content // create and add the header Paragraph p1 = new Paragraph(new Paragraph( String.format("%s %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()), FontFactory.getFont(FontFactory.HELVETICA, 10))); document.add(p1); Paragraph p2 = new Paragraph( new Paragraph("Team Detail Report", FontFactory.getFont(FontFactory.HELVETICA, 14))); p2.setAlignment(Paragraph.ALIGN_CENTER); document.add(p2); Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12); Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10); PdfPCell headerCell = new PdfPCell(); headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); headerCell.setPadding(3); headerCell.setBorderWidth(2); List<String> teams = dao.getTeams(); for (String t : teams) { List<Wrestler> wrestlers = dao.getWrestlersByTeam(t); int count = wrestlers.size(); // create and add the table PdfPTable datatable = new PdfPTable(5); int colWidths[] = { 30, 30, 20, 10, 10 }; // percentage datatable.setWidths(colWidths); datatable.setWidthPercentage(100); datatable.getDefaultCell().setPadding(3); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // The header has the team name and the number of entries headerCell.setPhrase(new Phrase(t, headerFont)); headerCell.setColspan(3); datatable.addCell(headerCell); headerCell.setPhrase(new Phrase(String.format("Entries : %d", count), headerFont)); headerCell.setColspan(2); datatable.addCell(headerCell); datatable.setHeaderRows(1); // this is the end of the table header datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); int i = 0; for (Wrestler w : wrestlers) { if ((i++ % 2) == 0) { datatable.getDefaultCell().setGrayFill(0.9f); } else { datatable.getDefaultCell().setGrayFill(1); } datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(new Phrase(w.getFirstName(), detailFont)); datatable.addCell(new Phrase(w.getLastName(), detailFont)); datatable.addCell(new Phrase(w.getClassification(), detailFont)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(new Phrase(w.getAgeDivision(), detailFont)); datatable.addCell(new Phrase(w.getWeightClass(), detailFont)); } datatable.setSpacingBefore(5f); datatable.setSpacingAfter(15f); document.add(datatable); } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.weighin.WeighInReport.java
License:Open Source License
/** * Generate a report of the entries in the tournament for weigh-in. * @param sections List of sections for the report. Each section will start * on a new page./* w ww .j a va 2 s . c o m*/ * @param headerString String to be used for the header of each page of the report. * @return True if the report was generated. */ public static boolean doReport(List<List<Wrestler>> sections, String headerString) { // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: create and add content // create and add the header if (headerString != null) { Paragraph p1 = new Paragraph( new Paragraph(headerString, FontFactory.getFont(FontFactory.HELVETICA, 10))); document.add(p1); } Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10); for (List<Wrestler> wrestlers : sections) { // create and add the table PdfPTable datatable = new PdfPTable(7); int colWidths[] = { 20, 20, 20, 10, 10, 10, 10 }; // percentage datatable.setWidths(colWidths); datatable.setWidthPercentage(100); datatable.getDefaultCell().setPadding(3); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); //datatable.setHeaderRows(1); // this is the end of the table header datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); int i = 0; for (Wrestler w : wrestlers) { if ((i++ % 2) == 0) { datatable.getDefaultCell().setGrayFill(0.9f); } else { datatable.getDefaultCell().setGrayFill(1); } datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(new Phrase(w.getLastName(), detailFont)); datatable.addCell(new Phrase(w.getFirstName(), detailFont)); datatable.addCell(new Phrase(w.getTeamName(), detailFont)); datatable.addCell(new Phrase(w.getClassification(), detailFont)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(new Phrase(w.getAgeDivision(), detailFont)); datatable.addCell(new Phrase(w.getWeightClass(), detailFont)); datatable.addCell(new Phrase()); // actual weight } datatable.setSpacingBefore(5f); datatable.setSpacingAfter(15f); document.add(datatable); document.newPage(); } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.utility.bracketsheet.Bracket16Maker.java
License:Open Source License
/** * @param args the command line arguments * arg0 String filename for output file//from ww w . j a va 2 s.c o m * arg1 boolean value "true" will render/show PDF file in viewer, default is false * * For example : * Bracket2Maker /tmp/test.pdf true */ public static void main(String[] args) { // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer PdfWriter writer; if (args.length >= 1) { writer = PdfWriter.getInstance(document, new FileOutputStream(args[0])); } else { System.err.println("ERROR : Must specify output file."); return; } // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); drawBracket(cb, bf); } catch (DocumentException de) { System.err.println(de.getMessage()); return; } catch (IOException ioe) { System.err.println(ioe.getMessage()); return; } // step 5: we close the document document.close(); if ((args.length == 2) && (Boolean.parseBoolean(args[1]))) { RoundRobinBracketMaker.showPDF(args[0]); } }
From source file:bouttime.utility.bracketsheet.RoundRobinBracketMaker.java
License:Open Source License
/** * @param args the command line arguments * arg0 String filename for output file//from w w w .j a v a2s .c o m * arg1 int number of wrestlers * arg2 boolean value "true" will render/show PDF file in viewer, default is false * * For example : * RoundRobinBracketMaker /tmp/test.pdf 3 true */ public static void main(String[] args) { // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer PdfWriter writer; int numWrestlers; if (args.length >= 2) { writer = PdfWriter.getInstance(document, new FileOutputStream(args[0])); numWrestlers = Integer.parseInt(args[1]); } else { System.err.println("ERROR : Must specify output file and number of wrestlers."); return; } // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); drawBracket(cb, bf, numWrestlers); } catch (DocumentException de) { System.err.println(de.getMessage()); return; } catch (IOException ioe) { System.err.println(ioe.getMessage()); return; } // step 5: we close the document document.close(); if ((args.length == 3) && (Boolean.parseBoolean(args[2]))) { showPDF(args[0]); } }
From source file:br.com.bikefood.model.PdfGenerator.java
public File menuGenerator(File a, Bikefood bike) throws BadElementException, IOException { try {/*from w ww .j av a 2 s . c om*/ Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream(a.getAbsolutePath())); doc.open(); doc.add(new Paragraph("Cardpio do Bike Food: " + bike.getName())); doc.add(new Paragraph("Especialidade em: " + bike.getType().getType())); doc.add(new Paragraph("\n")); doc.add(new Paragraph("\n")); Dal dal = new Dal(); List<Product> cardapio = dal.getProducts((int) bike.getId()); for (int x = 0; x < cardapio.size(); x++) { String image; if (cardapio.get(x).getImg().contains("br/com/bikefood")) { image = "C:\\Users\\Aluno\\Documents\\NetBeansProjects\\Bikefood\\src\\br\\com\\bikefood\\image\\product.png"; } else { image = cardapio.get(x).getImg(); } Image img = Image.getInstance(image); img.scaleAbsolute(125, 125); doc.add(img); doc.add(new Paragraph("Nome do Prato: " + cardapio.get(x).getName())); doc.add(new Paragraph("Preo do Prato: " + cardapio.get(x).getPrice())); doc.add(new Paragraph("Ingredientes: " + cardapio.get(x).getIngredients())); doc.add(new Paragraph("\n")); System.out.println(cardapio.get(x).getImg()); } doc.close(); return a; } catch (FileNotFoundException ex) { Logger.getLogger(PdfGenerator.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ee) { Logger.getLogger(PdfGenerator.class.getName()).log(Level.SEVERE, null, ee); } return a; }