List of usage examples for com.lowagie.text.pdf PdfPCell setVerticalAlignment
public void setVerticalAlignment(int verticalAlignment)
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);//from w w w .j a v a2 s.co m 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);/*from w ww. ja va 2 s . c o m*/ 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/* w w w . j a v a 2s . 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);//from w w w .j a v a 2 s. c o m 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;/* w w w. java2 s. 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);//www . j a v a2s.c o 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;/*w w w .j av a2 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;//from www. ja va2 s . c om 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.PdfWebTable.java
License:Open Source License
private PdfPCell createCell() { PdfPCell cell = new PdfPCell(); cell.setBorderColor(Color.BLACK); cell.setPadding(3);//from w w w .ja v a 2s . com cell.setBorderWidth(0); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); return cell; }
From source file:org.unitime.timetable.webutil.PdfWebTable.java
License:Open Source License
private float addImage(PdfPCell cell, String name) { try {// w ww . j av a2s. co m java.awt.Image awtImage = (java.awt.Image) iImages.get(name); if (awtImage == null) return 0; 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_CENTER); } else { cell.getPhrase().add(ck); } return awtImage.getWidth(null); } catch (Exception e) { return 0; } }