List of usage examples for com.lowagie.text Paragraph Paragraph
public Paragraph(Phrase phrase)
Paragraph
with a certain Phrase
. From source file:corner.orm.tapestry.pdf.service.PdfResponseBuilder.java
License:Apache License
public void renderResponse(IRequestCycle cycle) throws IOException { // ??//from www .j a v a 2 s .c o m IPage pdfPage = cycle.getPage(); // PDF. OutputStream os = response.getOutputStream(IPdfPage.CONTENT_TYPE); // PDF _doc = new Document(); // PDF Writer PdfWriter pdfWriter = null; try { // PDF writer. pdfWriter = PdfWriter.getInstance(_doc, os); if (pdfPage instanceof IPdfPage) { // PDF Page?. // ? PdfOutputPageEvent event = new PdfOutputPageEvent((IPdfPage) pdfPage); pdfWriter.setPageEvent(event); // Pdf writer?. _writer = new PdfWriterDelegate(pdfWriter); // pdf _doc.open(); // PDF Writer??. cycle.setAttribute(PDF_DOCUMENT_ATTRIBUTE_NAME, _doc); // PDF? cycle.renderPage(this); // PDF??. cycle.removeAttribute(PDF_DOCUMENT_ATTRIBUTE_NAME); // PDF. _doc.close(); } else if (pdfPage instanceof org.apache.tapestry.pages.Exception) { // ??. ExceptionDescription[] exceptions = (ExceptionDescription[]) PropertyUtils.read(pdfPage, "exceptions"); if (exceptions == null) { throw new ApplicationRuntimeException("UNKOWN Exception!"); } else { // ???. StringBuffer sb = new StringBuffer(); for (int i = 0; i < exceptions.length; i++) { sb.append(exceptions[i].getMessage()).append("\n"); ExceptionProperty[] pros = exceptions[i].getProperties(); for (ExceptionProperty pro : pros) { sb.append(pro.getName()).append(" ").append(pro.getValue()).append("\n"); } String[] traces = exceptions[i].getStackTrace(); if (traces == null) { continue; } for (int j = 0; j < traces.length; j++) { sb.append(traces[j]).append("\n"); } } throw new Exception(sb.toString()); } } } catch (Throwable e) { // ?. if (pdfWriter == null) { e.printStackTrace(); return; } if (!_doc.isOpen()) { _doc.open(); } pdfWriter.setPageEvent(null); _doc.newPage(); // PDF???SO COOL! :) try { _doc.add(new Phrase("pdf?:", PdfUtils.createSongLightFont(12))); _doc.add(new Paragraph(e.getMessage())); _doc.add(new Paragraph(fetchStackTrace(e))); _doc.close(); } catch (DocumentException e1) { throw new ApplicationRuntimeException(e1); } } }
From source file:Cotizacion.ExportarPDF.java
private static void acomodarDatosTablaProductos(Paragraph subCatPart) throws BadElementException { numeroFilas = LogicaCotizacion.numero; cantidadTabla = new String[numeroFilas]; productoTabla = new String[numeroFilas]; precioTabla = new String[numeroFilas]; totalTabla = new String[numeroFilas]; descripcionTabla = new String[numeroFilas]; PdfPTable tabla = new PdfPTable(5); tabla.setWidthPercentage(100);/*from www .j a va 2s . com*/ PdfPCell celda = new PdfPCell(new Paragraph("Producto")); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBackgroundColor(new Color(0, 175, 239)); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Descripcin")); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBackgroundColor(new Color(0, 175, 239)); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("P/U")); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBackgroundColor(new Color(0, 175, 239)); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Cantidad")); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBackgroundColor(new Color(0, 175, 239)); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Total")); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBackgroundColor(new Color(0, 175, 239)); tabla.addCell(celda); for (int i = 0; i < numeroFilas; i++) { productoTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 0); tabla.addCell(" " + productoTabla[i]); descripcionTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 1); tabla.addCell("" + descripcionTabla[i]); precioTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 2); tabla.addCell("$ " + precioTabla[i]); cantidadTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 3); tabla.addCell(" " + cantidadTabla[i]); totalTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 4); tabla.addCell("$ " + totalTabla[i]); } agregarLineasEnBlanco(subCatPart, 1); subCatPart.add(tabla); }
From source file:Cotizacion.ExportarPDF.java
private static void agregarLineasEnBlanco(Paragraph parrafo, int nLineas) { for (int i = 0; i < nLineas; i++) { parrafo.add(new Paragraph(" ")); }/*from w w w . j a v a2 s .co m*/ }