List of usage examples for com.itextpdf.text Element ALIGN_MIDDLE
int ALIGN_MIDDLE
To view the source code for com.itextpdf.text Element ALIGN_MIDDLE.
Click Source Link
From source file:Main_Frame.java
private void jMenuItem29ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem29ActionPerformed try {/*from w w w. ja v a 2 s .c om*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con1 = DriverManager.getConnection("jdbc:odbc:College"); Statement stm1 = con1.createStatement(); //Statement stm1 = con1.createStatement(); ResultSet rs = stm1.executeQuery("SELECT * from Slot_Details"); //ResultSet rs1 = stm2.executeQuery("SELECT * from Slot_Details"); String[] start = new String[10]; String[] end = new String[10]; int line = 0; while (rs.next()) { start[line] = rs.getString("START"); end[line] = rs.getString("END"); line++; } /* try{ Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con2=DriverManager.getConnection("jdbc:odbc:College");*/ Statement stm2 = con1.createStatement(); ResultSet query_set = stm2.executeQuery("SELECT * from format"); /* Step-2: Initialize PDF documents - logical objects */ Document my_pdf_report = new Document(PageSize.A4); PdfWriter.getInstance(my_pdf_report, new FileOutputStream("C:\\Users\\Durga\\Desktop\\Time_Table.pdf")); my_pdf_report.open(); //we have four columns in our table PdfPTable table = new PdfPTable(10); //table.setWidthPercentage(100); // table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); String a[] = { "//////", "//////", "//////", "//////", "//////", "//////", "//////", "//////", "L", "U", "N", "C", "H", "//////", "//////", "//////", "//////", "//////", "//////" }; int len = 1; table.addCell("Day"); table.addCell("Branch"); String s; for (int i = 0; i < line; i++) { int j = i; if (i == 5) table.addCell(a[0]); if (i >= 5) j = line - 1; table.addCell("Period" + (i) + " \n[" + start[j] + "-" + end[j] + "]"); } table.getDefaultCell().setFixedHeight(70); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); while (query_set.next()) { String Day = query_set.getString("Day"); table.addCell(Day); String Branch = query_set.getString("Branch"); table.addCell(Branch); for (int i = 0; i < line; i++) { if (i == 5) { table.addCell(a[len++]); table.addCell(query_set.getString("slot" + (i + 1)) + "G1"); } else if (i == 6) { table.addCell(query_set.getString("slot" + (i + 1)) + "G2"); } else table.addCell(query_set.getString("slot" + (i + 1))); } } /* Attach report table to PDF */ // my_pdf_report.add(my_report_table); my_pdf_report.add(table); my_pdf_report.close(); /* Close all DB related objects */ query_set.close(); stm2.close(); //con2.close(); // } /* catch(Exception e) { System.out.println(e); }*/ stm1.close(); con1.close(); } catch (Exception e) { System.out.println(e); } if (Desktop.isDesktopSupported()) //Open pdf file { try { File myFile = new File("C:\\Users\\Durga\\Desktop\\Time_Table.pdf"); Desktop.getDesktop().open(myFile); } catch (Exception ex) { System.out.println(ex); } //System.out.println(ex); } }
From source file:be.kcbj.placemat.Placemat.java
License:Open Source License
private PdfPCell generateCell(Sponsor sponsor, float cellHeight) throws IOException, BadElementException { int numLines = 0; Paragraph p = new Paragraph(); if (sponsor.image != null) { Image image = Image.getInstance(SponsorManager.getImageUrl(sponsor.image)); if (sponsor.imageWidth != 0) { image.scaleToFit(sponsor.imageWidth, 1000); } else if (sponsor.imageHeight != 0) { image.scaleToFit(1000, sponsor.imageHeight); }/* ww w . j a va2s . com*/ Chunk imageChunk = new Chunk(image, 0, 0, true); p.add(imageChunk); } if (sponsor.twoColumns) { StringBuilder sb = new StringBuilder(); if (sponsor.name != null) { sb.append(sponsor.name); } if (sponsor.name2 != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.name2); } if (sponsor.address != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.address); } if (sponsor.address2 != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.address2); } p.add(Chunk.NEWLINE); p.add(new Chunk(sb.toString(), new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))); numLines++; } else { if (sponsor.twoRows && sponsor.image != null) { p.add(Chunk.NEWLINE); } if (sponsor.name != null) { p.add(generateFittedChunk(sponsor.name, Font.BOLD)); numLines++; } if (sponsor.name2 != null) { p.add(Chunk.NEWLINE); p.add(generateFittedChunk(sponsor.name2, Font.BOLD)); numLines++; } if (sponsor.address != null) { p.add(new Chunk("\n\n", new Font(Font.FontFamily.HELVETICA, 2, Font.NORMAL))); p.add(new Chunk(sponsor.address, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); numLines++; } if (sponsor.address2 != null) { p.add(Chunk.NEWLINE); p.add(new Chunk(sponsor.address2, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); numLines++; } } p.setPaddingTop(0); p.setSpacingBefore(0); p.setAlignment(Element.ALIGN_CENTER); p.setMultipliedLeading(numLines <= 3 ? 1.3f : 1.1f); PdfPCell cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setFixedHeight(cellHeight); if (sponsor.twoColumns) { cell.setColspan(2); } if (sponsor.twoRows) { cell.setRowspan(2); if (sponsor.image == null) { p.setMultipliedLeading(p.getMultipliedLeading() * 1.5f); } } cell.setBorder(PdfPCell.NO_BORDER); cell.setCellEvent(CELL_EVENT); cell.setPaddingBottom(4); cell.addElement(p); if (sponsor.isTodo()) { cell.setBackgroundColor(BaseColor.ORANGE); } return cell; }
From source file:be.rheynaerde.poolsheets.AbstractPoolSheet.java
License:Open Source License
protected PdfPCell getHeaderCell(String text) { PdfPCell headerCell = new PdfPCell(new Phrase(text, configuration.getHeaderFont())); headerCell.setHorizontalAlignment(Element.ALIGN_CENTER); headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); headerCell.setFixedHeight(configuration.getSquareCellSize()); return headerCell; }
From source file:be.rheynaerde.poolsheets.AbstractPufPoolSheet.java
License:Open Source License
protected PdfPCell getNameCell(String text) { PdfPCell nameCell = text == null ? new PdfPCell() : new PdfPCell(new Phrase(text)); nameCell.setBorder(Rectangle.BOTTOM); nameCell.setHorizontalAlignment(Element.ALIGN_CENTER); nameCell.setVerticalAlignment(Element.ALIGN_MIDDLE); nameCell.setFixedHeight(configuration.getSquareCellSize()); return nameCell; }
From source file:be.rheynaerde.poolsheets.ClubPoolSheet.java
License:Open Source License
@Override protected void buildTable(Document document) throws DocumentException { int columnCount = configuration.getNrOfPlayers() + configuration.getSummaryColumnCount() + 3; int nameCellWidth = 5; PdfPTable table = new PdfPTable(columnCount); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.setTotalWidth(/*from w ww . j a v a 2 s . com*/ (configuration.getNrOfPlayers() + 1 + nameCellWidth + 0.1f + configuration.getSummaryColumnCount()) * configuration.getSquareCellSize()); table.setLockedWidth(true); float[] widths = new float[columnCount]; widths[0] = 1f * nameCellWidth; for (int i = 1; i < widths.length; i++) { widths[i] = 1f; } widths[widths.length - 1 - configuration.getSummaryColumnCount()] = 0.1f; table.setWidths(widths); PdfPCell cell = new PdfPCell(new Paragraph(configuration.getTitle(), configuration.getTitleFont())); cell.setColspan(columnCount); cell.setPaddingBottom(configuration.getSquareCellSize() / 2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); { table.addCell(getHeaderCell(bundle.getString("name"))); table.addCell(getSolidCell()); for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); } table.addCell(new PdfPCell()); //spacer column for (int i = 0; i < configuration.getSummaryColumnCount(); i++) { table.addCell(getHeaderCell(configuration.getSummaryColumnName(i))); } } for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(configuration.getNamePlayer(i + 1) == null ? "" : configuration.getNamePlayer(i + 1)); table.addCell(getHeaderCell(Integer.toString(i + 1))); for (int j = 0; j < i; j++) { String result = configuration.getResult(i + 1, j + 1); PdfPCell resultCell = new PdfPCell(new Phrase(result == null ? "" : result)); resultCell.setHorizontalAlignment(Element.ALIGN_CENTER); resultCell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(resultCell); } table.addCell(getSolidCell()); for (int j = i + 1; j < configuration.getNrOfPlayers(); j++) { String result = configuration.getResult(i + 1, j + 1); PdfPCell resultCell = new PdfPCell(new Phrase(result == null ? "" : result)); resultCell.setHorizontalAlignment(Element.ALIGN_CENTER); resultCell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(resultCell); } table.addCell(new PdfPCell()); //spacer column for (int j = 0; j < configuration.getSummaryColumnCount(); j++) { String result = configuration.getSummaryColumnValue(i + 1, j); PdfPCell summaryCell = new PdfPCell(new Phrase(result == null ? "" : result)); summaryCell.setHorizontalAlignment(Element.ALIGN_CENTER); summaryCell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(summaryCell); } } document.add(table); }
From source file:be.rheynaerde.poolsheets.StandardPoolSheet.java
License:Open Source License
protected void buildTable(Document document) throws DocumentException { int columnCount = 1 + 1 + configuration.getNrOfPlayers() + 1 + configuration.getSummaryColumnCount(); // name + number + scores + spacer // + summary PdfPTable table = new PdfPTable(columnCount); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.setTotalWidth((configuration.getNrOfPlayers() + 7 //the name column + extra space between grid and summary //currently the name column just gets a width that is //a multiple of the width of the other cells. Better //would be to let this cell take up the remaining space. + configuration.getSummaryColumnCount()) * configuration.getSquareCellSize()); table.setLockedWidth(true);// ww w . ja v a2 s. c om float[] widths = new float[columnCount]; widths[0] = 5f; for (int i = 1; i < widths.length; i++) { widths[i] = 1f; } widths[widths.length - 1 - configuration.getSummaryColumnCount()] = 0.1f; table.setWidths(widths); { table.addCell(getHeaderCell(bundle.getString("name"))); table.addCell(getSolidCell()); for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); } table.addCell(new PdfPCell()); //spacer column for (int i = 0; i < configuration.getSummaryColumnCount(); i++) { table.addCell(getHeaderCell(configuration.getSummaryColumnName(i))); } } for (int i = 0; i < configuration.getNrOfPlayers(); i++) { table.addCell(configuration.getNamePlayer(i + 1) == null ? "" : configuration.getNamePlayer(i + 1)); table.addCell(getHeaderCell(Integer.toString(i + 1))); for (int j = 0; j < i; j++) { String result = configuration.getResult(i + 1, j + 1); PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } table.addCell(getSolidCell()); for (int j = i + 1; j < configuration.getNrOfPlayers(); j++) { String result = configuration.getResult(i + 1, j + 1); PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } table.addCell(new PdfPCell()); //spacer column for (int j = 0; j < configuration.getSummaryColumnCount(); j++) { String result = configuration.getSummaryColumnValue(i + 1, j); PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } } document.add(table); }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private PdfPTable createOrderButton(Model model) throws IOException, BadElementException { final Chunk chunk = new Chunk("Order on taconic.com", iTextUtil.getFontButton()); chunk.setAction(//from w ww . j a va 2 s . c om new PdfAction("http://www.taconic.com/start-an-order?modelNumber=" + model.getModelNumber())); final PdfPCell cell = cell(new Phrase(chunk)); cell.setBackgroundColor(iTextUtil.getTaconicRed()); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingTop(5); cell.setPaddingBottom(8); final PdfPTable button = new PdfPTable(new float[] { 80f, 20f }); button.addCell(cell(new Phrase(" "), 2)); button.addCell(cell); button.addCell(cell(new Phrase(" "))); button.addCell(cell(new Phrase(" "), 2)); return button; }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private PdfPCell cellD(Phrase p, boolean invert) { final PdfPCell cell = new PdfPCell(p); cell.setBorder(0);/*from w ww .j a va 2 s. co m*/ cell.setPadding(5f); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); if (invert) { cell.setBackgroundColor(iTextUtil.getSilver()); } return cell; }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private PdfPCell cellH(Phrase p) { final PdfPCell cell = new PdfPCell(p); cell.setBackgroundColor(iTextUtil.getPurple()); cell.setPadding(5f);// w ww . j ava2 s . c o m cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); return cell; }
From source file:bouttime.report.award.AwardInventoryReport.java
License:Open Source License
private static PdfPTable getDataTable(int[] awardCounts, int maxAward) throws DocumentException { Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10); // create and add the table PdfPTable datatable = new PdfPTable(2); int colWidths[] = { 90, 10 }; // percentage datatable.setWidths(colWidths);//from w w w . j a va 2 s . c o m datatable.setWidthPercentage(100); datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); for (int i = 0; i < maxAward; i++) { if ((i % 2) == 0) { datatable.getDefaultCell().setGrayFill(0.9f); } else { datatable.getDefaultCell().setGrayFill(1); } String place = null; switch (i) { case 0: place = "1st Place"; break; case 1: place = "2nd Place"; break; case 2: place = "3rd Place"; break; case 3: place = "4th Place"; break; case 4: place = "5th Place"; break; case 5: place = "6th Place"; break; case 6: place = "7th Place"; break; default: logger.warn("unexpected place value : " + i); place = "???"; break; } datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(new Phrase(place, detailFont)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(new Phrase(Integer.toString(awardCounts[i]), detailFont)); } datatable.setSpacingBefore(5f); datatable.setSpacingAfter(15f); return datatable; }