List of usage examples for com.itextpdf.text Anchor setReference
public void setReference(final String reference)
Anchor
. From source file:PDF.GenerateReportActivities.java
private PdfPTable dospuntoonce() throws Exception { PdfPTable Dos_once = new PdfPTable(5); Dos_once.setWidths(new int[] { 2, 2, 3, 2, 3 }); PdfPCell Titulo_tabla = new PdfPCell( new Phrase("Actividad 2.11" + " - Direcciones y Codirecciones", encabezadost)); PdfPCell Num_Actividad = new PdfPCell(new Phrase("Nmero de Actividad")); PdfPCell Tipo_Actividad = new PdfPCell(new Phrase("Identificador de TT o tesis")); PdfPCell Ruta_alm = new PdfPCell(new Phrase("Evidencia")); PdfPCell Puntos = new PdfPCell(new Phrase("Puntos obtenidos")); PdfPCell Observaciones = new PdfPCell(new Phrase("Observaciones")); PdfPCell celda = new PdfPCell(); Titulo_tabla.setHorizontalAlignment(Element.ALIGN_CENTER); Titulo_tabla.setVerticalAlignment(Element.ALIGN_MIDDLE); Titulo_tabla.setBackgroundColor(new BaseColor(153, 0, 76)); Titulo_tabla.setColspan(5);//from ww w . ja v a 2 s . c o m Titulo_tabla.setExtraParagraphSpace(15f); Dos_once.addCell(Titulo_tabla); Num_Actividad.setHorizontalAlignment(Element.ALIGN_CENTER); Num_Actividad.setVerticalAlignment(Element.ALIGN_MIDDLE); Dos_once.addCell(Num_Actividad); Tipo_Actividad.setHorizontalAlignment(Element.ALIGN_CENTER); Tipo_Actividad.setVerticalAlignment(Element.ALIGN_MIDDLE); Dos_once.addCell(Tipo_Actividad); Ruta_alm.setHorizontalAlignment(Element.ALIGN_CENTER); Ruta_alm.setVerticalAlignment(Element.ALIGN_MIDDLE); Dos_once.addCell(Ruta_alm); Puntos.setHorizontalAlignment(Element.ALIGN_CENTER); Puntos.setVerticalAlignment(Element.ALIGN_MIDDLE); Dos_once.addCell(Puntos); Observaciones.setHorizontalAlignment(Element.ALIGN_CENTER); Observaciones.setVerticalAlignment(Element.ALIGN_MIDDLE); Dos_once.addCell(Observaciones); /*Aqui van las consultas de las Actividades del profesor*/ int periodo = 0; ResultSet rperiodo = lb.executeQuery("SELECT * FROM profesor WHERE id_usuario = " + getUsername()); if (rperiodo.next()) periodo = rperiodo.getInt("periodo"); /**Get actual period***/ String id_tt = null, puntaje = null, comenta = null; ResultSet rb = lb.executeQuery("SELECT * FROM profesor_tiene_tt WHERE " + "id_usuario = '" + getUsername() + "' AND (validado = 1 OR validado = 0) AND periodo = " + periodo); while (rb.next()) { Dos_once.addCell("2.11"); id_tt = rb.getString("id_TT"); Dos_once.addCell(id_tt); Anchor anchor = new Anchor("Constancia"); //anchor.setReference("file:///"+rb.getString("ruta_alm")); anchor.setReference(rb.getString("ruta_alm")); Dos_once.addCell(anchor); puntaje = rb.getString("puntaje"); Dos_once.addCell(puntaje); comenta = rb.getString("comentarios"); Dos_once.addCell(comenta); } return Dos_once; }
From source file:PDF.GenerateReportActivities.java
private PdfPTable dospuntodoce() throws Exception { PdfPTable Dos_doce = new PdfPTable(5); Dos_doce.setWidths(new int[] { 2, 2, 3, 2, 3 }); PdfPCell Titulo_tabla = new PdfPCell(new Phrase( "Actividad 2.12" + " - Coordinacin o Participacin en la elaboracin o actualizacin" + "de un plan de estudios", encabezadost));/*w ww . j a v a 2 s . co m*/ //PdfPCell Num_Actividad = new PdfPCell(new Phrase("Nmero de Actividad")); PdfPCell Tipo_Actividad = new PdfPCell(new Phrase("Identificador de Plan de estudios")); PdfPCell Tipo_parti = new PdfPCell(new Phrase("Tipo de participacin** (Ver parte de abajo)")); PdfPCell Ruta_alm = new PdfPCell(new Phrase("Evidencia")); PdfPCell Puntos = new PdfPCell(new Phrase("Puntos obtenidos")); PdfPCell Observaciones = new PdfPCell(new Phrase("Observaciones")); //PdfPCell celda=new PdfPCell(); Titulo_tabla.setHorizontalAlignment(Element.ALIGN_CENTER); Titulo_tabla.setVerticalAlignment(Element.ALIGN_MIDDLE); Titulo_tabla.setBackgroundColor(new BaseColor(153, 0, 76)); Titulo_tabla.setColspan(5); Titulo_tabla.setExtraParagraphSpace(15f); Dos_doce.addCell(Titulo_tabla); /*Num_Actividad.setHorizontalAlignment(Element.ALIGN_CENTER); Num_Actividad.setVerticalAlignment(Element.ALIGN_MIDDLE); Dos_doce.addCell(Num_Actividad);*/ Tipo_Actividad.setHorizontalAlignment(Element.ALIGN_CENTER); Tipo_Actividad.setVerticalAlignment(Element.ALIGN_MIDDLE); Dos_doce.addCell(Tipo_Actividad); Tipo_parti.setHorizontalAlignment(Element.ALIGN_CENTER); Tipo_parti.setVerticalAlignment(Element.ALIGN_MIDDLE); Dos_doce.addCell(Tipo_parti); Ruta_alm.setHorizontalAlignment(Element.ALIGN_CENTER); Ruta_alm.setVerticalAlignment(Element.ALIGN_MIDDLE); Dos_doce.addCell(Ruta_alm); Puntos.setHorizontalAlignment(Element.ALIGN_CENTER); Puntos.setVerticalAlignment(Element.ALIGN_MIDDLE); Dos_doce.addCell(Puntos); Observaciones.setHorizontalAlignment(Element.ALIGN_CENTER); Observaciones.setVerticalAlignment(Element.ALIGN_MIDDLE); Dos_doce.addCell(Observaciones); /*Aqui van las consultas de las Actividades del profesor*/ int periodo = 0; ResultSet rperiodo = lb.executeQuery("SELECT * FROM profesor WHERE id_usuario = " + getUsername()); if (rperiodo.next()) periodo = rperiodo.getInt("periodo"); /**Get actual period***/ String id_part = null, id_tipo = null, puntaje = null, comenta = null; ResultSet rb = lb.executeQuery("SELECT * FROM profesor_participa_en_plan WHERE " + "id_usuario = '" + getUsername() + "' AND (validado = 1 OR validado = 0) AND periodo = " + periodo /*AND periodo = que el que tiene registrado el profesor*/); while (rb.next()) { //Dos_doce.addCell("2.12"); id_part = rb.getString("id_part"); Dos_doce.addCell(id_part); id_tipo = rb.getString("id_tipo_part"); Dos_doce.addCell(id_tipo);//Agregar a la parte de abajo el tipo de prticicin Anchor anchor = new Anchor("Constancia"); //anchor.setReference("file:///"+rb.getString("ruta_alm")); anchor.setReference("file:///" + rb.getString("ruta_alm")); anchor.setReference("Constancia"); Dos_doce.addCell(anchor); puntaje = rb.getString("puntaje"); Dos_doce.addCell(puntaje); comenta = rb.getString("comentarios"); Dos_doce.addCell(comenta); } return Dos_doce; }
From source file:ro.nextreports.engine.exporter.PdfExporter.java
License:Apache License
private PdfPCell renderPdfCell(BandElement bandElement, Object value, int gridRow, int rowSpan, int colSpan, boolean image, int column) { Map<String, Object> style = buildCellStyleMap(bandElement, value, gridRow, column, colSpan); FontFactoryImp fact = new FontFactoryImp(); com.itextpdf.text.Font fnt;/*from w ww. jav a 2 s .c o m*/ if (bandElement != null) { fontName = (String) style.get(StyleFormatConstants.FONT_NAME_KEY); int size = ((Float) style.get(StyleFormatConstants.FONT_SIZE)).intValue(); fnt = getFont(size); } else { fnt = getFont(10); } PdfPCell cell; if (image) { if (value == null) { cell = new PdfPCell(new Phrase(IMAGE_NOT_FOUND)); } else { ImageBandElement ibe = (ImageBandElement) bandElement; try { byte[] imageBytes = getImage((String) value); cell = getImageCell(ibe, imageBytes, column, colSpan); } catch (Exception e) { cell = new PdfPCell(new Phrase(IMAGE_NOT_LOADED)); } } } else if (bandElement instanceof HyperlinkBandElement) { Hyperlink hyperlink = ((HyperlinkBandElement) bandElement).getHyperlink(); Anchor anchor = new Anchor(hyperlink.getText(), fnt); anchor.setReference(hyperlink.getUrl()); Phrase ph = new Phrase(); ph.add(anchor); cell = new PdfPCell(ph); } else if (bandElement instanceof ReportBandElement) { Report report = ((ReportBandElement) bandElement).getReport(); ExporterBean eb = null; try { eb = getSubreportExporterBean(report); PdfExporter subExporter = new PdfExporter(eb); subExporter.export(); PdfPTable innerTable = subExporter.getTable(); cell = new PdfPCell(innerTable); } catch (Exception e) { cell = new PdfPCell(); e.printStackTrace(); } finally { if ((eb != null) && (eb.getResult() != null)) { eb.getResult().close(); } } } else if ((bandElement instanceof VariableBandElement) && (VariableFactory .getVariable(((VariableBandElement) bandElement).getVariable()) instanceof TotalPageNoVariable)) { try { cell = new PdfPCell(Image.getInstance(total)); } catch (BadElementException e) { cell = new PdfPCell(new Phrase("NA")); } } else if (bandElement instanceof ImageColumnBandElement) { try { String v = StringUtil.getValueAsString(value, null); if (StringUtil.BLOB.equals(v)) { cell = new PdfPCell(new Phrase(StringUtil.BLOB)); } else { byte[] bytes = StringUtil.decodeImage(v); cell = getImageCell(bandElement, bytes, column, colSpan); } } catch (Exception e) { e.printStackTrace(); cell = new PdfPCell(new Phrase(IMAGE_NOT_LOADED)); } } else { String stringValue; if (style.containsKey(StyleFormatConstants.PATTERN)) { stringValue = StringUtil.getValueAsString(value, (String) style.get(StyleFormatConstants.PATTERN), getReportLanguage()); } else { stringValue = StringUtil.getValueAsString(value, null, getReportLanguage()); } if (stringValue == null) { stringValue = ""; } if (stringValue.startsWith("<html>")) { StringReader reader = new StringReader(stringValue); List<Element> elems = new ArrayList<Element>(); try { elems = HTMLWorker.parseToList(reader, new StyleSheet()); Phrase ph = new Phrase(); for (int i = 0; i < elems.size(); i++) { Element elem = (Element) elems.get(i); ph.add(elem); } cell = new PdfPCell(ph); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Phrase ph = new Phrase(stringValue, fnt); cell = new PdfPCell(ph); } } else { Phrase ph = new Phrase(stringValue, fnt); cell = new PdfPCell(ph); } } cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setUseDescender(true); // needed for a cell without padding cell.setMinimumHeight(MINIMUM_HEIGHT); // needed if there is a row in which all cells are empty if (bandElement != null) { cell.setRotation(bandElement.getTextRotation()); } if (colSpan > 1) { cell.setColspan(colSpan); } if (rowSpan > 1) { cell.setRowspan(rowSpan); } if (style != null) { updateFont(style, fnt); if (style.containsKey(StyleFormatConstants.BACKGROUND_COLOR)) { Color val = (Color) style.get(StyleFormatConstants.BACKGROUND_COLOR); cell.setBackgroundColor(new BaseColor(val)); } if (style.containsKey(StyleFormatConstants.HORIZONTAL_ALIGN_KEY)) { if (StyleFormatConstants.HORIZONTAL_ALIGN_LEFT .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); } if (StyleFormatConstants.HORIZONTAL_ALIGN_RIGHT .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); } if (StyleFormatConstants.HORIZONTAL_ALIGN_CENTER .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); } } if (style.containsKey(StyleFormatConstants.VERTICAL_ALIGN_KEY)) { if (StyleFormatConstants.VERTICAL_ALIGN_TOP .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { cell.setVerticalAlignment(Element.ALIGN_TOP); } if (StyleFormatConstants.VERTICAL_ALIGN_MIDDLE .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { cell.setVerticalAlignment(Element.ALIGN_MIDDLE); } if (StyleFormatConstants.VERTICAL_ALIGN_BOTTOM .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { cell.setVerticalAlignment(Element.ALIGN_BOTTOM); } } if (style.containsKey(StyleFormatConstants.PADDING_LEFT)) { Float val = (Float) style.get(StyleFormatConstants.PADDING_LEFT); cell.setPaddingLeft(val); } if (style.containsKey(StyleFormatConstants.PADDING_RIGHT)) { Float val = (Float) style.get(StyleFormatConstants.PADDING_RIGHT); cell.setPaddingRight(val); } if (style.containsKey(StyleFormatConstants.PADDING_TOP)) { Float val = (Float) style.get(StyleFormatConstants.PADDING_TOP); cell.setPaddingTop(val); } if (style.containsKey(StyleFormatConstants.PADDING_BOTTOM)) { Float val = (Float) style.get(StyleFormatConstants.PADDING_BOTTOM); cell.setPaddingBottom(val); } cell.setBorderWidth(0); if (style.containsKey(StyleFormatConstants.BORDER_LEFT)) { Float val = (Float) style.get(StyleFormatConstants.BORDER_LEFT); cell.setBorderWidthLeft(val / 2); Color color = (Color) style.get(StyleFormatConstants.BORDER_LEFT_COLOR); cell.setBorderColorLeft(new BaseColor(color)); } if (style.containsKey(StyleFormatConstants.BORDER_RIGHT)) { Float val = (Float) style.get(StyleFormatConstants.BORDER_RIGHT); cell.setBorderWidthRight(val / 2); Color color = (Color) style.get(StyleFormatConstants.BORDER_RIGHT_COLOR); cell.setBorderColorRight(new BaseColor(color)); } if (style.containsKey(StyleFormatConstants.BORDER_TOP)) { Float val = (Float) style.get(StyleFormatConstants.BORDER_TOP); cell.setBorderWidthTop(val / 2); Color color = (Color) style.get(StyleFormatConstants.BORDER_TOP_COLOR); cell.setBorderColorTop(new BaseColor(color)); } if (style.containsKey(StyleFormatConstants.BORDER_BOTTOM)) { Float val = (Float) style.get(StyleFormatConstants.BORDER_BOTTOM); cell.setBorderWidthBottom(val / 2); Color color = (Color) style.get(StyleFormatConstants.BORDER_BOTTOM_COLOR); cell.setBorderColorBottom(new BaseColor(color)); } // for subreports we use default no wrap if (cell.getTable() == null) { cell.setNoWrap(true); if (bandElement != null) { if (bandElement.isWrapText()) { cell.setNoWrap(false); } } } // to see a background image all cells must not have any background! if (bean.getReportLayout().getBackgroundImage() != null) { cell.setBackgroundColor(null); } } return cell; }