List of usage examples for com.itextpdf.text.pdf PdfPTable setHeaderRows
public void setHeaderRows(int headerRows)
From source file:com.microware.intrahealth.Createpdf2.java
private static void createTable(Paragraph preface, String[] Header, ArrayList<HashMap<String, String>> data) throws BadElementException { Context _con = null;/*www .j av a 2s .co m*/ // PdfPTable table = new PdfPTable(new float[] { 2, 1 }); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPTable table = new PdfPTable(new float[] { 1, 3, 3, 5, 5, 2, 3, 2, 2, 2 }); table.setHorizontalAlignment(Element.ALIGN_LEFT); for (int i = 0; i < Header.length; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold)); c1.getBorder(); c1.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(c1); } // table.addCell("Value"); // table.addCell("Location"); table.setHeaderRows(1); // PdfPCell c1 = new PdfPCell(new Phrase("Text",smallBold)); // c1.getBorder(); // c1.setHorizontalAlignment(Element.ALIGN_CENTER); // table.addCell(c1); // // c1 = new PdfPCell(new Phrase("Value",smallBold)); // c1.getBorder(); // c1.setHorizontalAlignment(Element.ALIGN_CENTER); // table.addCell(c1); // // table.setHeaderRows(1); PdfPCell[] cells = table.getRow(0).getCells(); for (int j = 0; j < cells.length; j++) { cells[j].setBackgroundColor(new BaseColor(0, 85, 133)); if (j == 0) { cells[j].setHorizontalAlignment(Element.ALIGN_LEFT); } else { cells[j].setHorizontalAlignment(Element.ALIGN_CENTER); } } dataprovider = new DataProvider(_con); // // Font f = FontFactory.getFont(getFilesDir() + "/" + HINDI_FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // PdfPCell eCell = new PdfPCell(new Phrase(entry, f)); for (int i = 0; i < data.size(); i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(data.get(i).get("ASHAName"), subFont)); table.addCell(String.valueOf((i + 1))); table.addCell(data.get(i).get("ASHAName")); table.addCell(data.get(i).get("VillageName")); table.addCell(data.get(i).get("PWName")); table.addCell(data.get(i).get("MotherMCTSID")); table.addCell(data.get(i).get("HusbandName")); table.addCell(Validate.changeDateFormat(data.get(i).get("CheckupVisitDate"))); table.addCell(data.get(i).get("DangerSign")); table.addCell(data.get(i).get("CheckupPlace")); table.addCell(""); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); // cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER); // cells1[2].setHorizontalAlignment(Element.ALIGN_CENTER); } // table.addCell("Colour"); // table.addCell("Hazen Unit"); // table.addCell("1.2"); // table.addCell("Turbidity"); // table.addCell("NTU"); // table.addCell("2.3"); preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable1(Paragraph preface, String[] Header, String[] Text, String[] Value) throws BadElementException { Context _con = null;//ww w . j av a2s . co m PdfPTable table = new PdfPTable(new float[] { 2, 1 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (int i = 0; i < Header.length; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold)); c1.getBorder(); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); PdfPCell[] cells = table.getRow(0).getCells(); for (int j = 0; j < cells.length; j++) { cells[j].setBackgroundColor(new BaseColor(0, 85, 133)); if (j == 0) { cells[j].setHorizontalAlignment(Element.ALIGN_LEFT); } else { cells[j].setHorizontalAlignment(Element.ALIGN_CENTER); } } dataprovider = new DataProvider(_con); if (Text.length == Value.length) { for (int i = 0; i < Value.length; i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text[i], subFont)); table.addCell(phrase); table.addCell(Value[i]); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER); } } else { for (int i = 0; i < Value.length; i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text[i], subFont)); table.addCell(phrase); table.addCell(""); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); } } preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable2(Paragraph preface, String[] Header, String[] Text, String[] Source, String[] Value) throws BadElementException { Context _con = null;/*from w w w . j a va 2 s .com*/ PdfPTable table = new PdfPTable(new float[] { 2, 1, 1 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (int i = 0; i < Header.length; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold)); c1.getBorder(); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); PdfPCell[] cells = table.getRow(0).getCells(); for (int j = 0; j < cells.length; j++) { cells[j].setBackgroundColor(new BaseColor(0, 85, 133)); if (j == 0) { cells[j].setHorizontalAlignment(Element.ALIGN_LEFT); } else { cells[j].setHorizontalAlignment(Element.ALIGN_CENTER); } } dataprovider = new DataProvider(_con); if (Text.length == Value.length) { for (int i = 0; i < Value.length; i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text[i], subFont)); table.addCell(phrase); table.addCell(Source[i]); table.addCell(Value[i]); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER); cells1[2].setHorizontalAlignment(Element.ALIGN_CENTER); } } else { for (int i = 0; i < Value.length; i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text[i], subFont)); table.addCell(phrase); table.addCell(""); table.addCell(""); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); } } preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable3(Paragraph preface, String[] Header, String[] Text, String[] Value, String[] Value1, String[] Value2) throws BadElementException { Context _con = null;//from w ww . ja v a 2 s. c o m PdfPTable table = new PdfPTable(new float[] { 1, 2, 1, 1 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (int i = 0; i < Header.length; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold)); c1.getBorder(); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); PdfPCell[] cells = table.getRow(0).getCells(); for (int j = 0; j < cells.length; j++) { cells[j].setBackgroundColor(new BaseColor(0, 85, 133)); if (j == 0) { cells[j].setHorizontalAlignment(Element.ALIGN_LEFT); } else { cells[j].setHorizontalAlignment(Element.ALIGN_CENTER); } } dataprovider = new DataProvider(_con); if (Text != null && Text.length > 0) { if (Text.length == Value.length) { for (int i = 0; i < Value.length; i++) { table.addCell(Text[i]); table.addCell(Value[i]); table.addCell(Value1[i]); table.addCell(Value2[i]); } } else { for (int i = 0; i < Value.length; i++) { table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); } } } else { table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); } preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable4(Paragraph preface, String[] Header, String Text, String Value) throws BadElementException { Context _con = null;/*w ww . ja v a 2 s . c o m*/ PdfPTable table = new PdfPTable(new float[] { 1, 1 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (int i = 0; i < Header.length; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold)); c1.getBorder(); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); PdfPCell[] cells = table.getRow(0).getCells(); for (int j = 0; j < cells.length; j++) { cells[j].setBackgroundColor(new BaseColor(0, 85, 133)); if (j == 0) { cells[j].setHorizontalAlignment(Element.ALIGN_LEFT); } else { cells[j].setHorizontalAlignment(Element.ALIGN_CENTER); } } dataprovider = new DataProvider(_con); if (Text.length() > 0 && Value.length() > 0) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text, subFont)); table.addCell(phrase); table.addCell(Value); PdfPCell[] cells1 = table.getRow(1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER); } else { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text, subFont)); table.addCell(phrase); table.addCell(""); PdfPCell[] cells1 = table.getRow(1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); } preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable5(Paragraph preface, String[] Header, String[] Text, String[] Value, String[] Value1, String[] Value2, String[] Value3) throws BadElementException { Context _con = null;/* w ww.ja v a 2s .c o m*/ PdfPTable table = new PdfPTable(new float[] { 1, 2, 1, 1, 1 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (int i = 0; i < Header.length; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold)); c1.getBorder(); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); PdfPCell[] cells = table.getRow(0).getCells(); for (int j = 0; j < cells.length; j++) { cells[j].setBackgroundColor(new BaseColor(0, 85, 133)); } dataprovider = new DataProvider(_con); if (Text != null && Text.length > 0) { if (Text.length == Value.length) { for (int i = 0; i < Value.length; i++) { table.addCell(Text[i]); table.addCell(Value[i]); table.addCell(Value1[i]); table.addCell(Value2[i]); table.addCell(Value3[i]); } } else { for (int i = 0; i < Value.length; i++) { table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); } } } else { table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); } preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable6(Paragraph preface, String[] Header, String[] Text, String[] Value, String[] Value1, String[] Value2, String[] Value3, String[] Value4) throws BadElementException { Context _con = null;/*w ww . j a v a2 s.co m*/ PdfPTable table = new PdfPTable(new float[] { 1, 2, 1, 1, 1, 1 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (int i = 0; i < Header.length; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold)); c1.getBorder(); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); PdfPCell[] cells = table.getRow(0).getCells(); for (int j = 0; j < cells.length; j++) { cells[j].setBackgroundColor(new BaseColor(0, 85, 133)); } dataprovider = new DataProvider(_con); if (Text != null && Text.length > 0) { if (Text.length == Value.length) { for (int i = 0; i < Value.length; i++) { table.addCell(Text[i]); table.addCell(Value[i]); table.addCell(Value1[i]); table.addCell(Value2[i]); table.addCell(Value3[i]); table.addCell(Value4[i]); } } else { for (int i = 0; i < Value.length; i++) { table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); } } } else { table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); } preface.add(table); }
From source file:com.mobicage.rogerthat.enterprise.samples.hr.bizz.GenerateExpenseNote.java
License:Open Source License
public int handle(final User user, final User manager, final ExpenseNote en) throws MalformedURLException, IOException, DocumentException { log.info("Building list of expenses ..."); List<Expense> expenses = Expense.list(en); log.info("Retrieved " + expenses.size() + " expenses from the datastore"); log.info("Creating ExpenseNoteDocOutputStream"); ExpenseNoteDocOutputStream stream = new ExpenseNoteDocOutputStream(en); Document document = new Document(); PdfWriter.getInstance(document, stream); document.open();//from w ww .jav a 2s . c o m document.addTitle("Expense note " + en.id + " of " + user.name); document.addSubject("Expense note generated by Rogerthat Enterprise!"); document.addKeywords("expense note"); document.addAuthor(user.name); document.addCreator("Rogerthat OneApp Enterprise Mobility"); Paragraph preface = new Paragraph(); preface.add(new Paragraph("TP Vision expense note", titleFont)); preface.add(new Paragraph(" ")); DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy"); Date date = new Date(); preface.add(new Paragraph("Date: " + dateFormat.format(date))); preface.add(new Paragraph("Requestor: " + user.name)); preface.add(new Paragraph("Approver: " + manager.name)); preface.add(new Paragraph(" ")); PdfPTable table = new PdfPTable(7); table.setWidthPercentage(110); table.setWidths(new int[] { 5, 15, 15, 35, 10, 15, 10 }); addHeader(table, "Id"); addHeader(table, "Date"); addHeader(table, "Nature"); addHeader(table, "Description"); addHeader(table, "Account"); addHeader(table, "Amount"); addHeader(table, "Voucher"); table.setHeaderRows(1); Collections.sort(expenses, new Comparator<Expense>() { @Override public int compare(Expense e1, Expense e2) { return (int) (e1.date - e2.date); } }); int i = 0; double total = 0; for (Expense expense : expenses) { PdfPCell c1 = new PdfPCell(new Phrase("" + ++i)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.addCell(dateFormat.format(new Date(expense.date * 1000))); table.addCell(expense.nature); table.addCell(expense.description); table.addCell("" + expense.account); c1 = new PdfPCell(new Phrase(DECIMAL_FORMAT.format(expense.amount) + " " + expense.currency)); c1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(c1); table.addCell(expense.voucher); total += expense.amount; } preface.add(table); preface.add(new Paragraph(" ")); preface.add(new Paragraph("Total: " + DECIMAL_FORMAT.format(total), titleFont)); document.add(preface); i = 0; for (Expense expense : expenses) { i++; if (expense.receipt == null) continue; document.newPage(); Paragraph receipt = new Paragraph(); receipt.add(new Paragraph("Attachment " + i, titleFont)); document.add(receipt); Image image = Image.getInstance(new URL(expense.receipt)); image.setRotationDegrees(-90); float scaler = (document.getPageSize().getWidth() / image.getWidth()) * 100; image.scalePercent(scaler); document.add(image); } document.close(); stream.close(); return stream.getSize(); }
From source file:com.mstoyanov.music_lessons.pdf.CreatePDF.java
License:Open Source License
private static PdfPTable createTable() throws DocumentException { PdfPTable table = new PdfPTable(6); table.setTotalWidth(new float[] { 114, 114, 114, 114, 114, 114 }); table.setLockedWidth(true);/* w w w .jav a 2 s . com*/ PdfPCell cell; cell = new PdfPCell(new Phrase("Monday", smallBold)); // cell.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Tuesday", smallBold)); table.addCell(cell); cell = new PdfPCell(new Phrase("Wednesday", smallBold)); table.addCell(cell); cell = new PdfPCell(new Phrase("Thursday", smallBold)); table.addCell(cell); cell = new PdfPCell(new Phrase("Friday", smallBold)); table.addCell(cell); cell = new PdfPCell(new Phrase("Saturday", smallBold)); table.addCell(cell); table.setHeaderRows(1); while (cells.size() > 0) { // rows for (int i = 0; i < weekdays_array.length; i++) { // columns boolean cell_empty = true; // scan all cell objects: for (int j = 0; j < cells.size(); j++) { // if there is a cell on this day: if (cells.get(j).getWeekDay().equalsIgnoreCase(weekdays_array[i])) { Phrase phrase = new Phrase( cells.get(j).getTimeFrom() + " - " + cells.get(j).getTimeTo() + "\n" + cells.get(j).getStudentName() + "\n" + cells.get(j).getPhoneNumber(), smallFont); // add it to the table: table.addCell(phrase); cell_empty = false; cells.remove(j); break; } } if (cell_empty) { // otherwise add an empty cell: table.addCell(new Phrase("\n" + "\n" + "\n", smallFont)); } } } return table; }
From source file:com.mycompany.mavenproject2.VirtualkeyController.java
private static void createTable(/*Section subCatPart*/String tableName, Paragraph preface) throws BadElementException { try {//w ww .j ava2 s . com ArrayList<String> list = new ArrayList<String>(); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); int length = 0; java.sql.Connection conn = Connection.getConnect(); Statement st = conn.createStatement(); st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM " + tableName); ResultSetMetaData rsMetaData = rs.getMetaData(); int numberOfColumns = rsMetaData.getColumnCount(); System.out.println("resultSet MetaData column Count=" + numberOfColumns); for (int i = 1; i <= numberOfColumns; i++) { length = i; } MongoClient client = new MongoClient(); MongoDatabase db = client.getDatabase("FinalDemo"); PdfPTable table = new PdfPTable(length); for (int i = 1; i <= numberOfColumns; i++) { // System.out.println("column MetaData "); //System.out.println("column number " + i); // get the column's name. System.out.println(rsMetaData.getColumnName(i)); PdfPCell c1 = new PdfPCell(new Phrase(rsMetaData.getColumnName(i))); c1.setHorizontalAlignment(Element.ALIGN_CENTER); list.add(rsMetaData.getColumnName(i)); table.addCell(c1); } while (rs.next()) { for (String col : list) { //System.out.println("Column name is "+col+"value is "+rs.getString(col)); table.addCell(rs.getString(col)); } } /*PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Table Header 2")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Table Header 3")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);*/ table.setHeaderRows(1); preface.add(table); //subCatPart.add(table); } catch (ClassNotFoundException ex) { Logger.getLogger(VirtualkeyController.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(VirtualkeyController.class.getName()).log(Level.SEVERE, null, ex); } }