List of usage examples for com.lowagie.text.pdf PdfPCell setHorizontalAlignment
public void setHorizontalAlignment(int horizontalAlignment)
From source file:org.tellervo.desktop.util.labels.PDFLabelMaker.java
License:Open Source License
public void addLabelsForSamples(List<TridasSample> samples) { // Loop through samples in list for (TridasSample s : samples) { Barcode128 barcode = new LabBarcode(LabBarcode.Type.SAMPLE, UUID.fromString(s.getIdentifier().getValue().toString())); // if it's tiny, hide the label if (margins.getLabelHeight() * .80f < barcode.getBarHeight()) { barcode.setBarHeight(margins.getLabelHeight() * .45f); barcode.setX(1.8f);// ww w . ja v a 2 s . c om barcode.setN(10f); barcode.setSize(10f); barcode.setBaseline(10f); barcode.setBarHeight(50f); barcode.setFont(null); } else { barcode.setBarHeight(margins.getLabelHeight() * .45f); barcode.setX(0.6f); barcode.setSize(4.0f); } PdfPCell lbcell = new PdfPCell(); lbcell.setVerticalAlignment(Element.ALIGN_TOP); lbcell.setHorizontalAlignment(Element.ALIGN_RIGHT); Phrase p = new Phrase(); String labelText; TridasGenericField labcodeField = GenericFieldUtils.findField(s, "tellervo.internal.labcodeText"); if (labcodeField == null) { log.warn("labcode missing from sample. Can't print!"); continue; } labelText = (labcodeField != null) ? labcodeField.getValue() : s.getTitle(); p.add(new Chunk(labelText, labelfont)); //p.add(new Chunk("bbb", labelfont)); //p.add(new Chunk(s.getIdentifier().getValue().toString(), uuidfont)); //barcode.setFont(null); Image img = barcode.createImageWithBarcode(contentb, Color.black, Color.gray); PdfPCell labcell = new PdfPCell(); if (App.getLabName() != null) { labcell.setHorizontalAlignment(Element.ALIGN_RIGHT); labcell.setVerticalAlignment(Element.ALIGN_TOP); Phrase labPhrase = new Phrase(App.getLabName().toUpperCase(), tinyfont); labcell.addElement(labPhrase); } addCell(labcell); PdfPCell bccell = new PdfPCell(); bccell.setHorizontalAlignment(Element.ALIGN_MIDDLE); bccell.addElement(img); bccell.addElement(p); addCell(bccell); lbcell.setHorizontalAlignment(Element.ALIGN_RIGHT); lbcell.addElement(p); addCell(lbcell); //addCell(new PdfPCell()); /** PdfPTable tbl = new PdfPTable(2); tbl.addCell(bccell); tbl.addCell(lbcell);*/ } }
From source file:org.unitime.timetable.export.PDFPrinter.java
License:Open Source License
@Override public void printHeader(String... fields) { iTable = new PdfPTable(fields.length - iHiddenColumns.size()); iMaxWidth = new float[fields.length]; iTable.setHeaderRows(1);/* w ww .jav a2 s . c om*/ iTable.setWidthPercentage(100); for (int idx = 0; idx < fields.length; idx++) { if (iHiddenColumns.contains(idx)) continue; String f = fields[idx]; PdfPCell cell = new PdfPCell(); cell.setBorder(Rectangle.BOTTOM); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_LEFT); Font font = PdfFont.getFont(true); cell.addElement(new Chunk(f, font)); iTable.addCell(cell); float width = 0; if (f.indexOf('\n') >= 0) { for (StringTokenizer s = new StringTokenizer(f, "\n"); s.hasMoreTokens();) width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize())); } else width = Math.max(width, font.getBaseFont().getWidthPoint(f, font.getSize())); iMaxWidth[idx] = width; } }
From source file:org.unitime.timetable.export.PDFPrinter.java
License:Open Source License
@Override public void printLine(String... fields) { PdfPCellEvent setLineDashEvent = new PdfPCellEvent() { @Override/*from w w w . j a v a 2 s. c o m*/ public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) { PdfContentByte cb = canvas[PdfPTable.LINECANVAS]; cb.setLineDash(new float[] { 2, 2 }, 0); } }; for (int idx = 0; idx < fields.length; idx++) { if (iHiddenColumns.contains(idx)) continue; String f = fields[idx]; if (f == null || f.isEmpty() || (iCheckLast && f.equals(iLastLine == null || idx >= iLastLine.length ? null : iLastLine[idx]))) f = ""; boolean number = sNumber.matcher(f).matches(); Font font = PdfFont.getFont(); Phrase p = new Phrase(f, PdfFont.getSmallFont()); PdfPCell cell = new PdfPCell(p); cell.setBorder(iLastLine == null ? Rectangle.TOP : Rectangle.NO_BORDER); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(number ? Element.ALIGN_RIGHT : Element.ALIGN_LEFT); cell.setPaddingBottom(4f); cell.setCellEvent(setLineDashEvent); if (number) cell.setPaddingRight(10f); iTable.addCell(cell); float width = 0; if (f.indexOf('\n') >= 0) { for (StringTokenizer s = new StringTokenizer(f, "\n"); s.hasMoreTokens();) width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize())); } else width = Math.max(width, font.getBaseFont().getWidthPoint(f, font.getSize())); iMaxWidth[idx] = Math.max(iMaxWidth[idx], width + (number ? 10 : 0)); } iLastLine = fields; }
From source file:org.unitime.timetable.webutil.pdf.PdfEventTableBuilder.java
License:Open Source License
public PdfPCell createCell() { PdfPCell cell = new PdfPCell(); cell.setBorderColor(Color.BLACK); cell.setPadding(3);// w w w .j a v a 2s . c om cell.setBorderWidth(0); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(iBgColor); if (iUnderline) cell.setBorderWidthBottom(1); if (iOverline) cell.setBorderWidthTop(0.5f); return cell; }
From source file:org.unitime.timetable.webutil.pdf.PdfEventTableBuilder.java
License:Open Source License
public void addText(PdfPCell cell, String text, boolean bold, boolean italic, int orientation, Color color, boolean newLine) { if (text == null) return;//from w w w.j ava2s. c o m if (cell.getPhrase() == null) { Chunk ch = new Chunk(text, PdfFont.getSmallFont(bold, italic, color)); cell.setPhrase(new Paragraph(ch)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(orientation); } else { cell.getPhrase() .add(new Chunk((newLine ? "\n" : "") + text, PdfFont.getSmallFont(bold, italic, color))); } }
From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java
License:Open Source License
public PdfPCell createCell() { PdfPCell cell = new PdfPCell(); cell.setBorderColor(sBorderColor);//from w ww .jav a 2s . co m cell.setPadding(3); cell.setBorderWidth(0); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(iBgColor); return cell; }
From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java
License:Open Source License
public void addText(PdfPCell cell, String text, boolean bold, boolean italic, int orientation, Color color, boolean newLine) { if (text == null) return;//from ww w.j av a 2 s . c o m if (cell.getPhrase() == null) { Chunk ch = new Chunk(text, PdfFont.getFont(bold, italic, color)); cell.setPhrase(new Paragraph(ch)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(orientation); } else { cell.getPhrase().add(new Chunk((newLine ? "\n" : "") + text, PdfFont.getFont(bold, italic, color))); } }
From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java
License:Open Source License
private PdfPCell pdfBuildTimePrefCell(ClassAssignmentProxy classAssignment, PreferenceGroup prefGroup, boolean isEditable) { Color color = (isEditable ? sEnableColor : sDisableColor); Assignment a = null;/* w w w .j av a 2 s . c o m*/ if (getDisplayTimetable() && isShowTimetable() && classAssignment != null && prefGroup instanceof Class_) { try { a = classAssignment.getAssignment((Class_) prefGroup); } catch (Exception e) { Debug.error(e); } } PdfPCell cell = createCell(); for (Iterator i = prefGroup.effectivePreferences(TimePref.class).iterator(); i.hasNext();) { TimePref tp = (TimePref) i.next(); RequiredTimeTable rtt = tp.getRequiredTimeTable(a == null ? null : a.getTimeLocation()); if (getGridAsText()) { addText(cell, rtt.getModel().toString().replaceAll(", ", "\n"), false, false, Element.ALIGN_LEFT, color, true); } else { try { rtt.getModel().setDefaultSelection(getDefaultTimeGridSize()); if (rtt.getModel().isExactTime()) { addText(cell, rtt.exactTime(false), false, false, Element.ALIGN_LEFT, color, true); } else { java.awt.Image awtImage = rtt.createBufferedImage(getTimeVertival()); Image img = Image.getInstance(awtImage, Color.WHITE); Chunk ck = new Chunk(img, 0, 0); if (cell.getPhrase() == null) { cell.setPhrase(new Paragraph(ck)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_LEFT); } else { cell.getPhrase().add(ck); } } } catch (Exception e) { e.printStackTrace(); } } } return cell; }
From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java
License:Open Source License
private PdfPCell pdfBuildPrefGroupDemand(PreferenceGroup prefGroup, boolean isEditable) { if (prefGroup instanceof Class_) { Class_ c = (Class_) prefGroup; if (StudentClassEnrollment.sessionHasEnrollments(c.getSessionId())) { PdfPCell tc = createCell(); if (c.getEnrollment() != null) { addText(tc, c.getEnrollment().toString()); } else { addText(tc, "0"); }//from w ww . j a v a2 s. co m tc.setHorizontalAlignment(Element.ALIGN_RIGHT); return (tc); } } return createCell(); }
From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java
License:Open Source License
private PdfPCell pdfBuildPrefGroupProjectedDemand(PreferenceGroup prefGroup, boolean isEditable) { PdfPCell cell = createCell(); if (prefGroup instanceof Class_) { Class_ c = (Class_) prefGroup; SectioningInfo i = c.getSectioningInfo(); if (i != null && i.getNbrExpectedStudents() != null) { addText(cell,/*from www. j a v a2s . c o m*/ String.valueOf(Math.round(Math.max(0.0, c.getEnrollment() + i.getNbrExpectedStudents())))); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } } return cell; }