List of usage examples for com.itextpdf.text.pdf PdfPCell setPaddingLeft
public void setPaddingLeft(float paddingLeft)
From source file:fll.web.playoff.ScoresheetGenerator.java
License:Open Source License
public void writeFile(final OutputStream out, final boolean orientationIsPortrait) throws DocumentException { // This creates our new PDF document and declares its orientation Document pdfDoc;/*ww w . ja v a 2 s.co m*/ if (orientationIsPortrait) { pdfDoc = new Document(PageSize.LETTER); // portrait } else { pdfDoc = new Document(PageSize.LETTER.rotate()); // landscape } PdfWriter.getInstance(pdfDoc, out); // Measurements are always in points (72 per inch) // This sets up 1/2 inch margins side margins and 0.35in top and bottom // margins pdfDoc.setMargins(0.5f * POINTS_PER_INCH, 0.5f * POINTS_PER_INCH, 0.35f * POINTS_PER_INCH, 0.35f * POINTS_PER_INCH); pdfDoc.open(); // Header cell with challenge title to add to both scoresheets final Paragraph titleParagraph = new Paragraph(); final Chunk titleChunk = new Chunk(m_pageTitle, FontFactory.getFont(FontFactory.HELVETICA_BOLD, 14, Font.NORMAL, BaseColor.WHITE)); titleParagraph.setAlignment(Element.ALIGN_CENTER); titleParagraph.add(titleChunk); titleParagraph.add(Chunk.NEWLINE); final Chunk swVersionChunk = new Chunk("SW version: " + Version.getVersion(), FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE)); titleParagraph.add(swVersionChunk); if (null != m_revision) { final Chunk revisionChunk = new Chunk(" Descriptor revision: " + m_revision, FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE)); titleParagraph.add(revisionChunk); } final PdfPCell head = new PdfPCell(); head.setColspan(2); head.setBorder(1); head.setPaddingTop(0); head.setPaddingBottom(3); head.setBackgroundColor(new BaseColor(64, 64, 64)); head.setVerticalAlignment(Element.ALIGN_TOP); head.addElement(titleParagraph); // Cells for score field, and 2nd check initials final Phrase des = new Phrase("Data Entry Score _______", ARIAL_8PT_NORMAL); final PdfPCell desC = new PdfPCell(des); desC.setBorder(0); desC.setPaddingTop(9); desC.setPaddingRight(36); desC.setHorizontalAlignment(Element.ALIGN_RIGHT); final Phrase sci = new Phrase("2nd Check Initials _______", ARIAL_8PT_NORMAL); final PdfPCell sciC = new PdfPCell(sci); sciC.setBorder(0); sciC.setPaddingTop(9); sciC.setPaddingRight(36); sciC.setHorizontalAlignment(Element.ALIGN_RIGHT); // Create a table with a grid cell for each scoresheet on the page PdfPTable wholePage = getTableForPage(orientationIsPortrait); wholePage.setWidthPercentage(100); for (int i = 0; i < m_numSheets; i++) { if (i > 0 && (orientationIsPortrait || (i % 2) == 0)) { pdfDoc.newPage(); wholePage = getTableForPage(orientationIsPortrait); wholePage.setWidthPercentage(100); } // This table is a single score sheet final PdfPTable scoreSheet = new PdfPTable(2); // scoreSheet.getDefaultCell().setBorder(Rectangle.LEFT | Rectangle.BOTTOM // | Rectangle.RIGHT | Rectangle.TOP); //FIXME DEBUG should be NO_BORDER scoreSheet.getDefaultCell().setBorder(Rectangle.NO_BORDER); scoreSheet.getDefaultCell().setPaddingRight(1); scoreSheet.getDefaultCell().setPaddingLeft(0); scoreSheet.addCell(head); final PdfPTable teamInfo = new PdfPTable(7); teamInfo.setWidthPercentage(100); teamInfo.setWidths(new float[] { 1f, 1f, 1f, 1f, 1f, 1f, .9f }); // Time label cell final Paragraph timeP = new Paragraph("Time:", ARIAL_10PT_NORMAL); timeP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell timeLc = new PdfPCell(scoreSheet.getDefaultCell()); timeLc.addElement(timeP); teamInfo.addCell(timeLc); // Time value cell final Paragraph timeV = new Paragraph(null == m_time[i] ? SHORT_BLANK : m_time[i], COURIER_10PT_NORMAL); final PdfPCell timeVc = new PdfPCell(scoreSheet.getDefaultCell()); timeVc.addElement(timeV); teamInfo.addCell(timeVc); // Table label cell final Paragraph tblP = new Paragraph("Table:", ARIAL_10PT_NORMAL); tblP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell tblLc = new PdfPCell(scoreSheet.getDefaultCell()); tblLc.addElement(tblP); teamInfo.addCell(tblLc); // Table value cell final Paragraph tblV = new Paragraph(m_table[i], COURIER_10PT_NORMAL); final PdfPCell tblVc = new PdfPCell(scoreSheet.getDefaultCell()); tblVc.addElement(tblV); teamInfo.addCell(tblVc); // Round number label cell final Paragraph rndP = new Paragraph("Round:", ARIAL_10PT_NORMAL); rndP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell rndlc = new PdfPCell(scoreSheet.getDefaultCell()); rndlc.addElement(rndP); teamInfo.addCell(rndlc); // Round number value cell final Paragraph rndV = new Paragraph(m_round[i], COURIER_10PT_NORMAL); final PdfPCell rndVc = new PdfPCell(scoreSheet.getDefaultCell()); // rndVc.setColspan(2); rndVc.addElement(rndV); teamInfo.addCell(rndVc); final PdfPCell temp1 = new PdfPCell(scoreSheet.getDefaultCell()); // temp1.setColspan(2); temp1.addElement(new Paragraph("Judge ____", ARIAL_8PT_NORMAL)); teamInfo.addCell(temp1); // Team number label cell final Paragraph nbrP = new Paragraph("Team #:", ARIAL_10PT_NORMAL); nbrP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell nbrlc = new PdfPCell(scoreSheet.getDefaultCell()); nbrlc.addElement(nbrP); teamInfo.addCell(nbrlc); // Team number value cell final Paragraph nbrV = new Paragraph(null == m_number[i] ? SHORT_BLANK : String.valueOf(m_number[i]), COURIER_10PT_NORMAL); final PdfPCell nbrVc = new PdfPCell(scoreSheet.getDefaultCell()); nbrVc.addElement(nbrV); teamInfo.addCell(nbrVc); // Team division label cell final Paragraph divP = new Paragraph(m_divisionLabel[i], ARIAL_10PT_NORMAL); divP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell divlc = new PdfPCell(scoreSheet.getDefaultCell()); divlc.addElement(divP); divlc.setColspan(2); teamInfo.addCell(divlc); // Team division value cell final Paragraph divV = new Paragraph(m_division[i], COURIER_10PT_NORMAL); final PdfPCell divVc = new PdfPCell(scoreSheet.getDefaultCell()); divVc.setColspan(2); divVc.addElement(divV); teamInfo.addCell(divVc); final PdfPCell temp2 = new PdfPCell(scoreSheet.getDefaultCell()); // temp2.setColspan(2); temp2.addElement(new Paragraph("Team ____", ARIAL_8PT_NORMAL)); teamInfo.addCell(temp2); // Team name label cell final Paragraph nameP = new Paragraph("Team Name:", ARIAL_10PT_NORMAL); nameP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell namelc = new PdfPCell(scoreSheet.getDefaultCell()); namelc.setColspan(2); namelc.addElement(nameP); teamInfo.addCell(namelc); // Team name value cell final Paragraph nameV = new Paragraph(m_name[i], COURIER_10PT_NORMAL); final PdfPCell nameVc = new PdfPCell(scoreSheet.getDefaultCell()); nameVc.setColspan(5); nameVc.addElement(nameV); teamInfo.addCell(nameVc); // add team info cell to the team table final PdfPCell teamInfoCell = new PdfPCell(scoreSheet.getDefaultCell()); teamInfoCell.addElement(teamInfo); teamInfoCell.setColspan(2); scoreSheet.addCell(teamInfoCell); if (null != m_goalsTable) { final PdfPCell goalCell = new PdfPCell(m_goalsTable); goalCell.setBorder(0); goalCell.setPadding(0); goalCell.setColspan(2); scoreSheet.addCell(goalCell); } scoreSheet.addCell(desC); scoreSheet.addCell(sciC); if (null != m_copyright) { final Phrase copyright = new Phrase("\u00A9" + m_copyright, f6i); final PdfPCell copyrightC = new PdfPCell(scoreSheet.getDefaultCell()); copyrightC.addElement(copyright); copyrightC.setBorder(0); copyrightC.setHorizontalAlignment(Element.ALIGN_CENTER); copyrightC.setColspan(2); scoreSheet.addCell(copyrightC); } // the cell in the whole page table that will contain the single score // sheet final PdfPCell scoresheetCell = new PdfPCell(scoreSheet); scoresheetCell.setBorder(0); scoresheetCell.setPadding(0); // Interior borders between scoresheets on a page if (!orientationIsPortrait) { if (i % 2 == 0) { scoresheetCell.setPaddingRight(0.1f * POINTS_PER_INCH); } else { scoresheetCell.setPaddingLeft(0.1f * POINTS_PER_INCH); } } // Add the current scoresheet to the page wholePage.addCell(scoresheetCell); // Add the current table of scoresheets to the document if (orientationIsPortrait || (i % 2 != 0)) { pdfDoc.add(wholePage); } } // Add a blank cells to complete the table of the last page if (!orientationIsPortrait && m_numSheets % 2 != 0) { final PdfPCell blank = new PdfPCell(); blank.setBorder(0); wholePage.addCell(blank); pdfDoc.add(wholePage); } pdfDoc.close(); }
From source file:fxml.test.PDFService.java
public PdfPTable createFooter1() { //String[] names = new String[]{"Md. Eamin Rahman", "Md. Mujibur Rahman", "Md Masum", "Md. Saiful Islam", "Husne Ara Chowdhury", "Sabir Ismail"}; PdfPTable table = new PdfPTable(5); table.setHorizontalAlignment(Element.ALIGN_LEFT); try {//from ww w . jav a2 s . co m table.setTotalWidth(new float[] { 161f, 161f, 133f, 167f, 161f }); table.setLockedWidth(true); } catch (DocumentException ex) { Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex); } //table.setWidthPercentage(100); PdfPCell chairmanSIgnature = new PdfPCell(new Paragraph("Signature of the Chairman:", font9)); chairmanSIgnature.setBorder(Rectangle.NO_BORDER); chairmanSIgnature.setPaddingLeft(0f); chairmanSIgnature.setPaddingTop(5); table.addCell(chairmanSIgnature); PdfPCell underLine = new PdfPCell(new Paragraph("_______________________")); underLine.setBorder(Rectangle.NO_BORDER); table.addCell(underLine); PdfPCell blankColumn = new PdfPCell(new Paragraph(" ")); blankColumn.setBorder(Rectangle.NO_BORDER); table.addCell(blankColumn); Paragraph p = new Paragraph("Signature of The Controller of Examinations:", font9); p.setLeading(0, 1.3f); PdfPCell controllerSignature = new PdfPCell(); controllerSignature.addElement(p); controllerSignature.setBorder(Rectangle.NO_BORDER); table.addCell(controllerSignature); table.addCell(underLine); PdfPCell cell1 = new PdfPCell(new Paragraph(inputs.get(5).trim(), font9)); cell1.setPaddingTop(0f); cell1.setBorder(Rectangle.NO_BORDER); PdfPCell cell2 = new PdfPCell(new Paragraph(inputs.get(6).trim(), font9)); cell2.setPaddingTop(0f); cell2.setBorder(Rectangle.NO_BORDER); PdfPCell nameColumn = new PdfPCell(new Paragraph("Name :", font9)); nameColumn.setBorder(Rectangle.NO_BORDER); nameColumn.setPaddingLeft(0f); nameColumn.setPaddingTop(0f); PdfPCell nameColumn2 = new PdfPCell(new Paragraph("Name :", font9)); nameColumn2.setBorder(Rectangle.NO_BORDER); nameColumn2.setPaddingTop(0f); table.addCell(nameColumn); table.addCell(cell1); table.addCell(blankColumn); table.addCell(nameColumn2); table.addCell(cell2); table.setSpacingAfter(23.5f); return table; }
From source file:fxml.test.PDFService.java
public PdfPTable createFooter2() { PdfPTable table = new PdfPTable(8); table.setHorizontalAlignment(Element.ALIGN_LEFT); try {// w ww. ja v a2 s .c om table.setTotalWidth(new float[] { 192f, 144f, 5f, 144f, 5f, 144f, 5f, 144f }); table.setLockedWidth(true); } catch (DocumentException ex) { Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell underLine = new PdfPCell(new Paragraph("_____________________")); underLine.setBorder(Rectangle.NO_BORDER); PdfPCell blankColumn = new PdfPCell(new Paragraph(" ")); blankColumn.setBorder(Rectangle.NO_BORDER); PdfPCell blankColumn2 = new PdfPCell(new Paragraph(" ")); blankColumn2.setBorder(Rectangle.BOTTOM); PdfPCell nameColumn = new PdfPCell(new Paragraph("Name :", font9)); nameColumn.setBorder(Rectangle.NO_BORDER); nameColumn.setPaddingLeft(0f); PdfPCell cell3 = new PdfPCell(new Paragraph(inputs.get(7).trim(), font9)); cell3.setPaddingRight(2); cell3.setBorder(Rectangle.TOP); PdfPCell cell4 = new PdfPCell(new Paragraph(inputs.get(8).trim(), font9)); cell4.setBorder(Rectangle.TOP); PdfPCell cell5 = new PdfPCell(new Paragraph(inputs.get(9).trim(), font9)); cell5.setBorder(Rectangle.TOP); PdfPCell cell6 = new PdfPCell(new Paragraph(inputs.get(10).trim(), font9)); cell6.setBorder(Rectangle.TOP); PdfPCell memberSignature = new PdfPCell(new Paragraph("Signature of the Members:", font9)); memberSignature.setPaddingLeft(0f); memberSignature.setBorder(Rectangle.NO_BORDER); table.addCell(memberSignature); table.addCell(blankColumn); table.addCell(blankColumn); table.addCell(blankColumn); table.addCell(blankColumn); table.addCell(blankColumn); table.addCell(blankColumn); table.addCell(blankColumn); table.addCell(nameColumn); table.addCell(cell3); table.addCell(blankColumn); table.addCell(cell4); table.addCell(blankColumn); table.addCell(cell5); table.addCell(blankColumn); table.addCell(cell6); PdfPCell tabulatorSignature = new PdfPCell(new Paragraph("Signature of the Tabulators:", font9)); tabulatorSignature.setPaddingLeft(0f); tabulatorSignature.setPaddingTop(13f); tabulatorSignature.setBorder(Rectangle.NO_BORDER); table.addCell(tabulatorSignature); table.addCell(blankColumn2); table.addCell(blankColumn); table.addCell(blankColumn2); table.addCell(blankColumn); table.addCell(blankColumn2); table.addCell(blankColumn); table.addCell(blankColumn2); return table; }
From source file:fxml.test.PDFService.java
private PdfPTable createTableBody(int studentStart, int start, PdfPTable table) { int studentCount = 1; for (int j = studentStart; j < studentList.size(); j++) { Student student = (Student) studentList.get(j); PdfPCell regCell = getCellForString(student.getRegNo(), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); regCell.setPaddingTop(2f);/*from w w w. ja va2 s . co m*/ regCell.setPaddingBottom(3.85f); PdfPCell nameCell = getCellForString(student.getName(), 0, true, Element.ALIGN_MIDDLE, 0, font9, false); nameCell.setPaddingTop(1f); nameCell.setPaddingBottom(3.85f); nameCell.setPaddingLeft(5f); table.addCell(regCell); table.addCell(nameCell); int colCount = 1; //Getting student regestered courses for current semester. Map<String, CourseReg> regesteredCourse = student.getRegesteredCourse(); for (int k = start; k < list.size(); k++) { //checking if its a instance of Course then we will print the Course details if (list.get(k) instanceof Course) { Course course = (Course) list.get(k); if (regesteredCourse.containsKey(course.getCourseCode())) { CourseReg courseReg = regesteredCourse.get(course.getCourseCode()); PdfPTable table1 = new PdfPTable(2); table1.setTotalWidth(44f); table1.setLockedWidth(true); PdfPCell cell1 = getCellForString(String.format("%.02f", courseReg.getGpa()), 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); cell1.setPaddingTop(1f); cell1.setPaddingBottom(4f); PdfPCell cell2 = getCellForString(courseReg.getLetterGrade(), 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); cell2.setPaddingTop(1f); cell2.setPaddingBottom(4f); table1.addCell(cell1); table1.addCell(cell2); PdfPCell cell3 = new PdfPCell(table1); cell3.setPaddingTop(0f); cell3.setPaddingBottom(0f); table.addCell(cell3); } else { table.addCell(new PdfPCell()); } } //End checking if its a instance of Course then we will print the Course details else if (list.get(k).equals("Total Credit")) { PdfPCell creditCell = getCellForString(String.valueOf(student.getTotalCredit()), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); creditCell.setPaddingTop(1f); creditCell.setPaddingBottom(4f); table.addCell(creditCell); } else if (list.get(k).equals("Total GPA")) { PdfPCell gpaCell = getCellForString(String.format("%.02f", student.getGpa()), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); gpaCell.setPaddingTop(1f); gpaCell.setPaddingBottom(4f); table.addCell(gpaCell); } else if (list.get(k).equals("Letter Grade")) { PdfPCell gradeCell = getCellForString(student.getLetterGrade(), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); gradeCell.setPaddingTop(1f); gradeCell.setPaddingBottom(4f); table.addCell(gradeCell); } else if (list.get(k).equals("Cumulative")) { PdfPTable table1 = new PdfPTable(3); table1.setTotalWidth(88f); table1.setLockedWidth(true); PdfPCell cell1 = getCellForString(String.format("%.02f", student.getCumulativeCredit()), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); cell1.setPaddingTop(1f); cell1.setPaddingBottom(4f); PdfPCell cell2 = getCellForString(String.format("%.02f", student.getCumulativeGpa()), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); cell2.setPaddingTop(1f); cell2.setPaddingBottom(4f); PdfPCell cell3 = getCellForString(student.getCumulativeLetterGrade(), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); cell3.setPaddingTop(1f); cell3.setPaddingBottom(4f); table1.addCell(cell1); table1.addCell(cell2); table1.addCell(cell3); PdfPCell cell4 = new PdfPCell(table1); cell4.setPaddingTop(0f); cell4.setPaddingBottom(0f); table.addCell(cell4); } else { table.addCell(new PdfPCell()); } if (colCount == 12) { break; } colCount++; } if (studentCount == 15) { break; } studentCount++; } return table; }
From source file:gov.nih.nci.firebird.service.registration.AbstractPdfWriterGenerator.java
License:Open Source License
private PdfPCell createTableCell(String value) { Paragraph contents = new Paragraph(); contents.add(getValueChunk(value));/*from w w w.jav a 2 s. c o m*/ PdfPCell cell = createTableCell(contents); cell.setPaddingLeft(VALUE_CELL_INDENTATION); return cell; }
From source file:gov.nih.nci.firebird.service.registration.ProfileContentPdfHelper.java
License:Open Source License
private void addAddress(Address address, PdfPTable table, int index) { PdfPTable addressTable = pdfGenerator.createTable(AbstractPdfWriterGenerator.ONE_COLUMN); addressTable.addCell(/*from ww w .j a va2 s .c o m*/ pdfGenerator.createHeaderCell(index + ". " + pdfGenerator.getFromResources(ADDRESS_TITLE_KEY))); Paragraph contents = new Paragraph(); if (getOrganization() != null) { contents.add(pdfGenerator.getValueChunk(getOrganization().getName())); contents.add(Chunk.NEWLINE); } if (address != null) { addAddressContent(contents, address); } PdfPCell addressCell = pdfGenerator.createTableCell(contents); addressCell.setPaddingLeft(VALUE_CELL_INDENTATION); addressTable.addCell(addressCell); PdfPCell addressTableCell = pdfGenerator.createCell(addressTable); addressTableCell.setPaddingRight(PADDING_RIGHT); table.addCell(addressTableCell); }
From source file:net.digitstar.vanadio.helpers.PdfHelper.java
License:Apache License
public static PdfPCell newCell(CellStyle style) { PdfPCell cell = new PdfPCell(); if (style != null) { if (style.getNestedTable() != null) { cell = new PdfPCell(style.getNestedTable()); style.setNestedTable(null);// w w w. ja v a2s. c o m } else if (style.getImage() != null) { cell = new PdfPCell(style.getImage(), style.isFitImage()); style.setImage(null); } else if (style.getText() != null) { cell = new PdfPCell(style.getText()); style.setText((String) null); } cell.setColspan(style.getColspan()); cell.setRowspan(style.getRowspan()); cell.setMinimumHeight(style.getMinimumHeight()); cell.setFixedHeight(style.getFixedHeight()); cell.setNoWrap(style.isNoWrap()); cell.setRotation(style.getRotation().getValue()); style = Alignment.assign(style); cell.setHorizontalAlignment(style.getHorizAlign().getValue()); cell.setVerticalAlignment(style.getVertAlign().getValue()); cell.setUseVariableBorders(style.isUseVariableBorders()); cell.setUseBorderPadding(style.isUseBorderPadding()); if (!style.getBorderWidth().isAllSideEqual()) { cell.setBorderWidthBottom(style.getBorderWidth().getBottom()); cell.setBorderWidthLeft(style.getBorderWidth().getLeft()); cell.setBorderWidthRight(style.getBorderWidth().getRight()); cell.setBorderWidthTop(style.getBorderWidth().getTop()); } else { cell.setBorderWidth(style.getBorderWidth().getValue()); } cell.setPaddingBottom(style.getPadding().getBottom()); cell.setPaddingLeft(style.getPadding().getLeft()); cell.setPaddingRight(style.getPadding().getRight()); cell.setPaddingTop(style.getPadding().getTop()); cell.setBorderColorBottom(style.getBorderColor().getBottom()); cell.setBorderColorLeft(style.getBorderColor().getLeft()); cell.setBorderColorRight(style.getBorderColor().getRight()); cell.setBorderColorTop(style.getBorderColor().getTop()); cell.setBorder(style.getBorder().getValue()); cell.setBackgroundColor(style.getBackgroundColor()); if (style.getGreyFill() >= 0) { cell.setGrayFill(style.getGreyFill()); } } return cell; }
From source file:org.cidte.sii.negocio.PDFWriter.java
private void insertCell(PdfPTable table, String text, int align, int colspan, Font font) { // create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font)); // set the cell alignment cell.setHorizontalAlignment(align);/*w w w.ja v a2 s. c o m*/ // some padding cell.setPaddingLeft(10); // set the cell column span in case you want to merge two or more cells cell.setColspan(colspan); // in case there is no text and you wan to create an empty row if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } // add the call to the table table.addCell(cell); }
From source file:org.ganttproject.impex.htmlpdf.itext.ThemeImpl.java
License:GNU General Public License
private PdfPTable createTableHeader(ColumnList tableHeader, ArrayList<Column> orderedColumns) { for (int i = 0; i < tableHeader.getSize(); i++) { Column c = tableHeader.getField(i); if (c.isVisible()) { orderedColumns.add(c);/* w w w . j a va2s . c om*/ } } Collections.sort(orderedColumns, new Comparator<Column>() { @Override public int compare(Column lhs, Column rhs) { if (lhs == null || rhs == null) { return 0; } return lhs.getOrder() - rhs.getOrder(); } }); float[] widths = new float[orderedColumns.size()]; for (int i = 0; i < orderedColumns.size(); i++) { Column column = orderedColumns.get(i); widths[i] = column.getWidth(); } PdfPTable table = new PdfPTable(widths); table.setWidthPercentage(95); for (Column field : orderedColumns) { if (field.isVisible()) { PdfPCell cell = new PdfPCell(new Paragraph(field.getName(), getSansRegularBold(12f))); cell.setPaddingTop(4); cell.setPaddingBottom(4); cell.setPaddingLeft(5); cell.setPaddingRight(5); cell.setBorderWidth(0); cell.setBorder(PdfPCell.BOTTOM); cell.setBorderWidthBottom(1); cell.setBorderColor(SORTAVALA_GREEN); table.addCell(cell); } } table.setHeaderRows(1); return table; }
From source file:org.ganttproject.impex.htmlpdf.itext.ThemeImpl.java
License:GNU General Public License
private void writeProperties(ArrayList<Column> orderedColumns, Map<String, String> id2value, PdfPTable table, Map<String, PdfPCell> id2cell) { for (Column column : orderedColumns) { PdfPCell cell = id2cell.get(column.getID()); if (cell == null) { String value = id2value.get(column.getID()); if (value == null) { value = ""; }//from ww w . ja va2s. c o m Paragraph p = new Paragraph(value, getSansRegular(12)); cell = new PdfPCell(p); if (TaskDefaultColumn.COST.getStub().getID().equals(column.getID()) || ResourceDefaultColumn.STANDARD_RATE.getStub().getID().equals(column.getID()) || ResourceDefaultColumn.TOTAL_COST.getStub().getID().equals(column.getID()) || ResourceDefaultColumn.TOTAL_LOAD.getStub().getID().equals(column.getID())) { cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); } cell.setBorderWidth(0); cell.setPaddingLeft(5); } table.addCell(cell); } }