List of usage examples for com.itextpdf.text.pdf PdfPCell setRowspan
public void setRowspan(int rowspan)
From source file:basiclayout.ReportFrame.java
public ReportFrame(DefaultTableModel subtotal_model, String st1_date, String e1_date) throws DocumentException, IOException { this();/* ww w.j a va2s . c om*/ report_model = (DefaultTableModel) reportTable.getModel(); reportTable.setRowSelectionAllowed(true); reportTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); document = new Document(); try { initialize_connection(); PdfWriter.getInstance((com.itextpdf.text.Document) document, new FileOutputStream("C:\\Users\\jaina_000\\Desktop\\test.pdf")); document.open(); table = new PdfPTable(5); table.setWidthPercentage(300 / 3f); table.setWidths(new int[] { 3, 3, 3, 3, 3 }); PdfPCell cell; cell = new PdfPCell(new Phrase("Category")); table.addCell(cell); cell = new PdfPCell(new Phrase("Title")); table.addCell(cell); cell = new PdfPCell(new Phrase("Date")); table.addCell(cell); cell = new PdfPCell(new Phrase("Amount")); table.addCell(cell); cell = new PdfPCell(new Phrase("Details")); table.addCell(cell); cell.setRowspan(5); final_total = 0; for (int i = 0; i < subtotal_model.getRowCount(); i++) { String subt_cat = subtotal_model.getValueAt(i, 0).toString(); resultset1 = statement1 .executeQuery("Select * from " + tableC + " WHERE CategoryName='" + subt_cat + "'"); resultset1.next(); resultset2 = statement2 .executeQuery("Select * from " + tableE + " WHERE CategoryId= '" + resultset1.getString(1) + "' " + "AND (Date BETWEEN '" + st1_date + "' AND '" + e1_date + "')"); sub_amt = 0; System.out.print("\n\nCategory: " + resultset1.getString(2)); rep_row[0] = resultset1.getString(2); for (int z = 1; z < 5; z++) { rep_row[z] = null; } report_model.addRow(rep_row); table.addCell(new PdfPCell(new Phrase((String) rep_row[0]))); table.addCell(new PdfPCell(new Phrase(""))); table.addCell(new PdfPCell(new Phrase(""))); table.addCell(new PdfPCell(new Phrase(""))); table.addCell(new PdfPCell(new Phrase(""))); cell.setRowspan(5); while (resultset2.next()) { rep_row[0] = null; System.out.print("\nTitle : " + resultset2.getString(5)); // Title rep_row[1] = resultset2.getString(5); System.out.print("\tDate : " + resultset2.getString(2)); // Date rep_row[2] = resultset2.getString(2); System.out.print("\tAmount: " + Math.abs(Integer.parseInt(resultset2.getString(4)))); rep_row[3] = Math.abs(Integer.parseInt(resultset2.getString(4))); System.out.print("\tDescription : " + resultset2.getString(6)); // Description rep_row[4] = resultset2.getString(6); table.addCell(new PdfPCell(new Phrase((String) rep_row[0]))); table.addCell(new PdfPCell(new Phrase((String) rep_row[1]))); table.addCell(new PdfPCell(new Phrase((String) rep_row[2]))); table.addCell(new PdfPCell(new Phrase(String.valueOf(rep_row[3])))); table.addCell(new PdfPCell(new Phrase((String) rep_row[4]))); sub_amt += Integer.parseInt(resultset2.getString(4)); report_model.addRow(rep_row); cell.setRowspan(5); } final_total += sub_amt; for (int z = 0; z < 5; z++) { rep_row[z] = null; } rep_row[2] = "Subtotal"; rep_row[3] = Math.abs(sub_amt); System.out.println("\nCategory Subtotal : " + Math.abs(sub_amt)); table.addCell(new PdfPCell(new Phrase((String) rep_row[0]))); table.addCell(new PdfPCell(new Phrase((String) rep_row[1]))); table.addCell(new PdfPCell(new Phrase((String) rep_row[2]))); table.addCell(new PdfPCell(new Phrase(String.valueOf(rep_row[3])))); table.addCell(new PdfPCell(new Phrase((String) rep_row[4]))); report_model.addRow(rep_row); cell.setRowspan(5); } for (int z = 0; z < 5; z++) { rep_row[z] = null; } report_model.addRow(rep_row); report_model.addRow(rep_row); System.out.print("\n\nFinal total: " + Math.abs(final_total)); rep_row[2] = "Final Total"; rep_row[3] = Math.abs(final_total); if (final_total < 0) { System.out.println(" (Expense)"); rep_row[4] = "(Expense)"; } else { System.out.println(" (Income)"); rep_row[4] = "(Income)"; } table.addCell(new PdfPCell(new Phrase((String) rep_row[0]))); table.addCell(new PdfPCell(new Phrase((String) rep_row[1]))); table.addCell(new PdfPCell(new Phrase((String) rep_row[2]))); table.addCell(new PdfPCell(new Phrase(String.valueOf(rep_row[3])))); table.addCell(new PdfPCell(new Phrase((String) rep_row[4]))); report_model.addRow(rep_row); cell.setRowspan(5); } catch (ClassNotFoundException | SQLException e) { } catch (FileNotFoundException ex) { Logger.getLogger(ReportFrame.class.getName()).log(Level.SEVERE, null, ex); } finally { close_connection(); } }
From source file:be.kcbj.placemat.Placemat.java
License:Open Source License
private PdfPCell generateCell(Sponsor sponsor, float cellHeight) throws IOException, BadElementException { int numLines = 0; Paragraph p = new Paragraph(); if (sponsor.image != null) { Image image = Image.getInstance(SponsorManager.getImageUrl(sponsor.image)); if (sponsor.imageWidth != 0) { image.scaleToFit(sponsor.imageWidth, 1000); } else if (sponsor.imageHeight != 0) { image.scaleToFit(1000, sponsor.imageHeight); }/*w ww . java 2 s. com*/ Chunk imageChunk = new Chunk(image, 0, 0, true); p.add(imageChunk); } if (sponsor.twoColumns) { StringBuilder sb = new StringBuilder(); if (sponsor.name != null) { sb.append(sponsor.name); } if (sponsor.name2 != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.name2); } if (sponsor.address != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.address); } if (sponsor.address2 != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.address2); } p.add(Chunk.NEWLINE); p.add(new Chunk(sb.toString(), new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))); numLines++; } else { if (sponsor.twoRows && sponsor.image != null) { p.add(Chunk.NEWLINE); } if (sponsor.name != null) { p.add(generateFittedChunk(sponsor.name, Font.BOLD)); numLines++; } if (sponsor.name2 != null) { p.add(Chunk.NEWLINE); p.add(generateFittedChunk(sponsor.name2, Font.BOLD)); numLines++; } if (sponsor.address != null) { p.add(new Chunk("\n\n", new Font(Font.FontFamily.HELVETICA, 2, Font.NORMAL))); p.add(new Chunk(sponsor.address, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); numLines++; } if (sponsor.address2 != null) { p.add(Chunk.NEWLINE); p.add(new Chunk(sponsor.address2, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); numLines++; } } p.setPaddingTop(0); p.setSpacingBefore(0); p.setAlignment(Element.ALIGN_CENTER); p.setMultipliedLeading(numLines <= 3 ? 1.3f : 1.1f); PdfPCell cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setFixedHeight(cellHeight); if (sponsor.twoColumns) { cell.setColspan(2); } if (sponsor.twoRows) { cell.setRowspan(2); if (sponsor.image == null) { p.setMultipliedLeading(p.getMultipliedLeading() * 1.5f); } } cell.setBorder(PdfPCell.NO_BORDER); cell.setCellEvent(CELL_EVENT); cell.setPaddingBottom(4); cell.addElement(p); if (sponsor.isTodo()) { cell.setBackgroundColor(BaseColor.ORANGE); } return cell; }
From source file:be.rheynaerde.poolsheets.AbstractPufPoolSheet.java
License:Open Source License
protected PdfPCell getCellWithBorder(PdfPCell prototype, int border, int rowspan, int colspan) { PdfPCell cell = new PdfPCell(prototype); cell.setBorder(border);// w ww . j a v a 2s .c o m cell.setColspan(colspan); cell.setRowspan(rowspan); return cell; }
From source file:be.rheynaerde.poolsheets.PufTeamPoolSheet.java
License:Open Source License
protected PdfPTable getScoreTable() throws DocumentException { //table for scores final int columnCount = configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2) + 2; //one column for each player, an extra column for the numbers and a column for the team marks PdfPTable table = new PdfPTable(columnCount); table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); table.setTotalWidth((columnCount) * configuration.getSquareCellSize()); table.setLockedWidth(true);/* w ww .j a v a 2s. co m*/ float[] widths = new float[columnCount]; for (int i = 0; i < widths.length; i++) { widths[i] = 1f; } table.setWidths(widths); PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2); topCell.setFixedHeight(configuration.getSquareCellSize()); table.addCell(topCell); table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(1))); table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(2))); table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1)); { table.addCell(getSolidCell()); for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); } } table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(1), 1)); for (int i = 0; i < configuration.getNrOfPlayers(1); i++) { table.addCell(getHeaderCell(Integer.toString(i + 1))); if (i == 0) { PdfPCell blackCell = getSolidCell(); blackCell.setColspan(configuration.getNrOfPlayers(1)); blackCell.setRowspan(configuration.getNrOfPlayers(1)); table.addCell(blackCell); } for (int j = 0; j < configuration.getNrOfPlayers(2); j++) { table.addCell(configuration.getResult(0, i, 1, j)); } } table.addCell( getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(2), 1)); for (int i = 0; i < configuration.getNrOfPlayers(2); i++) { table.addCell(getHeaderCell(Integer.toString(configuration.getNrOfPlayers(1) + i + 1))); for (int j = 0; j < configuration.getNrOfPlayers(1); j++) { table.addCell(configuration.getResult(1, i, 0, j)); } if (i == 0) { PdfPCell blackCell = getSolidCell(); blackCell.setColspan(configuration.getNrOfPlayers(2)); blackCell.setRowspan(configuration.getNrOfPlayers(2)); table.addCell(blackCell); } } table.setHorizontalAlignment(Element.ALIGN_RIGHT); return table; }
From source file:cimav.restrh.services.JustificacionREST.java
private Response tablaMercado(Integer id_param) { Justificacion justif = (Justificacion) JustificacionREST.this.find(id_param); StreamingOutput streamingOutput = new StreamingOutput() { public void write(OutputStream outputStream) throws IOException, WebApplicationException { try { //Create Document instance. Document document = new Document(); PdfWriter.getInstance(document, outputStream); document.addAuthor("Generador adquisiciones | " + justif.getEmpleado().getCuentaCimav()); String fileName1 = (justif.getRequisicion() + "-" + justif.getEmpleado().getCuentaCimav()) .replace(" ", "").replace(",", ""); document.addTitle("Justificacin: " + fileName1); document.addSubject("Justificacin de Requisicin"); document.open();//from w ww .ja v a2 s . c o m //Titulo del documento Paragraph parrafo = new Paragraph("Centro de Investigacin en Materiales Avanzados S. C.", new Font(Font.FontFamily.TIMES_ROMAN, 17, Font.BOLD)); parrafo.setAlignment(Element.ALIGN_CENTER); parrafo.setSpacingAfter(20); document.add(parrafo); PdfPTable table = new PdfPTable(3); // 3 columns. table.setWidths(new int[] { 30, 50, 100 }); PdfPCell cell0 = new PdfPCell( new Paragraph("Fecha:", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); PdfPCell cell1 = new PdfPCell(new Paragraph( justif.getFechaInicio().getDayOfMonth() + " de " + justif.getFechaInicio().getMonth().getDisplayName(TextStyle.FULL, new Locale("es", "ES")) + " de " + justif.getFechaInicio().getYear(), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); PdfPCell cell2 = new PdfPCell( new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell0.setBorder(PdfPCell.BOX); cell1.setBorder(PdfPCell.BOX); cell2.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell0); table.addCell(cell1); table.addCell(cell2); cell0 = new PdfPCell(new Paragraph("No. de Requisicin:", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell1 = new PdfPCell(new Paragraph(justif.getRequisicion(), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell2 = new PdfPCell(new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell0.setBorder(PdfPCell.BOX); cell1.setBorder(PdfPCell.BOX); cell2.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell0); table.addCell(cell1); table.addCell(cell2); cell0 = new PdfPCell(new Paragraph("Procedimiento:", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell1 = new PdfPCell(new Paragraph("Adjudicacin Directa", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell2 = new PdfPCell(new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell0.setBorder(PdfPCell.BOX); cell1.setBorder(PdfPCell.BOX); cell2.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell0); table.addCell(cell1); table.addCell(cell2); cell0 = new PdfPCell(new Paragraph("Origen de los bienes:", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell1 = new PdfPCell(new Paragraph(justif.esNacional(), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell2 = new PdfPCell(new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell0.setBorder(PdfPCell.BOX); cell1.setBorder(PdfPCell.BOX); cell2.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell0); table.addCell(cell1); table.addCell(cell2); document.add(table); parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)); parrafo.setSpacingAfter(20); parrafo.setIndentationLeft(30); parrafo.setLeading(15); parrafo.setSpacingBefore(20); parrafo.setAlignment(Element.ALIGN_JUSTIFIED); document.add(parrafo); table = new PdfPTable(5);// 5 columns. table.setWidthPercentage(90); //table size % table.setWidths(new int[] { 'a', 'a', 'a', 'a', 'a' }); cell0 = new PdfPCell( new Paragraph("PARTIDA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); cell1 = new PdfPCell( new Paragraph("DESCIPCIMAV", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); cell2 = new PdfPCell( new Paragraph("PROVEEDOR No. 1", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); PdfPCell cell3 = new PdfPCell( new Paragraph("PROVEEDOR No.2", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); PdfPCell cell4 = new PdfPCell( new Paragraph("PROVEEDOR No.3", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); cell0.setBorder(PdfPCell.BOX); cell1.setBorder(PdfPCell.BOX); cell2.setBorder(PdfPCell.BOX); cell3.setBorder(PdfPCell.BOX); cell4.setBorder(PdfPCell.BOX); cell0.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell0); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); cell0 = new PdfPCell( new Paragraph("Partida #1", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); cell1 = new PdfPCell(new Paragraph(justif.getDescripcion(), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell0.setBorder(PdfPCell.BOX); cell1.setBorder(PdfPCell.BOX); cell0.setHorizontalAlignment(Element.ALIGN_CENTER); cell0.setVerticalAlignment(Element.ALIGN_MIDDLE); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); cell0.setRowspan(2); cell1.setRowspan(2); table.addCell(cell0); table.addCell(cell1); cell2 = new PdfPCell(new Paragraph(justif.getProveedorUno(), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell(new Paragraph(justif.getProveedorDos(), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell(new Paragraph(justif.getProveedorTres(), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell2.setBorder(PdfPCell.BOX); cell3.setBorder(PdfPCell.BOX); cell4.setBorder(PdfPCell.BOX); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); if (justif.getMontoUno() <= 1 && justif.getMontoDos() <= 1 && justif.getMontoTres() <= 1) { cell2 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } else if (justif.getMontoUno() <= 1 && justif.getMontoDos() <= 1) { cell2 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } else if (justif.getMontoUno() <= 1 && justif.getMontoTres() <= 1) { cell2 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } else if (justif.getMontoDos() <= 1 && justif.getMontoTres() <= 1) { cell2 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoUno(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } else if (justif.getMontoUno() <= 1) { cell2 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } else if (justif.getMontoDos() <= 1) { cell2 = new PdfPCell(new Paragraph( "Subtotal: " + justif.getSubTotal() + "\n" + "IVA: " + justif.getIva() + "\n" + "Total:" + "\n" + montoFormatComas(justif.getImporte(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } else if (justif.getMontoTres() <= 1) { cell2 = new PdfPCell(new Paragraph( "Subtotal: " + justif.getSubTotal() + "\n" + "IVA: " + justif.getIva() + "\n" + "Total:" + "\n" + montoFormatComas(justif.getImporte(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } else { cell2 = new PdfPCell(new Paragraph( "Subtotal: " + justif.getSubTotal() + "\n" + "IVA: " + justif.getIva() + "\n" + "Total:" + "\n" + montoFormatComas(justif.getImporte(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } cell2.setBorder(PdfPCell.BOX); cell3.setBorder(PdfPCell.BOX); cell4.setBorder(PdfPCell.BOX); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); document.add(table); parrafo = new Paragraph( "Tal como lo establece el artculo 29 " + "del Reglamento de la Ley de Adquisiciones, " + "Arrendamientos y Servicios del Sector Pblico," + " la investigacin de mercado arrojo los siguientes resultados:\n", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)); parrafo.setSpacingAfter(20); parrafo.setIndentationLeft(30); parrafo.setLeading(15); parrafo.setSpacingBefore(10); parrafo.setAlignment(Element.ALIGN_JUSTIFIED); document.add(parrafo); parrafo = new Paragraph( "Fraccin I, determinamos la existencia de oferta de los bienes requeridos.\n" + "Fraccin II, verificamos existencias de los mismos con los proveedores que nos proporcionaron cotizacin formal.\n" + "Fraccin III, conocimos los precios que prevalecan en el mercado nacional.\n", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)); parrafo.setIndentationLeft(50); parrafo.setLeading(15); parrafo.setAlignment(Element.ALIGN_JUSTIFIED); document.add(parrafo); parrafo = new Paragraph( "A travs de la investigacin de mercado realizada, " + "concluimos que la mejor opcin de compra es la oferta del proveedor" + " " + justif.getProveedorUno(), new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)); parrafo.setSpacingAfter(10); parrafo.setIndentationLeft(30); parrafo.setLeading(15); parrafo.setSpacingBefore(20); parrafo.setAlignment(Element.ALIGN_JUSTIFIED); document.add(parrafo); document.close(); outputStream.close(); } catch (DocumentException ex) { Logger.getLogger(JustificacionREST.class.getName()).log(Level.SEVERE, null, ex); } } }; ResponseBuilder response = Response.ok(streamingOutput); String fileName = ("inline; filename=" + justif.getRequisicion() + "-" + justif.getEmpleado().getCuentaCimav() + ".pdf").replace(" ", "").replace(",", "-"); response.header("Content-Disposition", fileName); return response.build(); }
From source file:cn.afterturn.easypoi.pdf.export.PdfExportServer.java
License:Apache License
private PdfPCell createStringCell(PdfPTable table, String text, ExcelExportEntity entity, int rowHeight, int colspan, int rowspan) { PdfPCell iCell = new PdfPCell(new Phrase(text, styler.getFont(entity, text))); styler.setCellStyler(iCell, entity, text); iCell.setFixedHeight((int) (rowHeight * 2.5)); if (colspan > 1) { iCell.setColspan(colspan);/*from w ww . ja v a 2s .c o m*/ } if (rowspan > 1) { iCell.setRowspan(rowspan); } table.addCell(iCell); return iCell; }
From source file:com.deadormi.servlet.CreaPdfServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from ww w . j a va 2 s. com * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url = request.getQueryString(); Integer gruppo_id = Integer.parseInt(url.substring(url.indexOf("=") + 1, url.length())); List<Utente> iscritti = null; List<Post> posts = null; Gruppo gruppo = null; Utente utente = null; String imageUrl = null; String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort(); try { iscritti = UtenteController.getUserByGroupId(request, gruppo_id); gruppo = GruppoController.getGruppoById(request, gruppo_id); } catch (SQLException ex) { log.error(ex); } // step 1: creation of a document-object Document document = new Document(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); String incipit = "Report del " + CurrentDate.getCurrentDate() + "\n"; Paragraph pIncipit = new Paragraph(incipit, FontFactory.getFont(FontFactory.HELVETICA, 14, BaseColor.BLACK)); pIncipit.setAlignment(Element.ALIGN_CENTER); pIncipit.setSpacingAfter(10); document.add(pIncipit); String title = "Gruppo " + gruppo.getNome(); Paragraph pTitle = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, 18, BaseColor.BLUE)); pTitle.setAlignment(Element.ALIGN_CENTER); pTitle.setSpacingAfter(40); document.add(pTitle); PdfPCell labelNome = new PdfPCell(new Paragraph("Nome utente")); PdfPCell labelNumPost = new PdfPCell(new Paragraph("Num. post")); PdfPCell labelData = new PdfPCell(new Paragraph("Data ultimo post")); labelNome.setBorder(Rectangle.NO_BORDER); labelNumPost.setBorder(Rectangle.NO_BORDER); labelData.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < iscritti.size(); i++) { utente = iscritti.get(i); try { posts = PostController.getPostByGruppoIdAndUserId(request, gruppo_id, utente.getId_utente()); } catch (SQLException ex) { Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex); } if (utente.getNome_avatar() != null) { imageUrl = baseUrl + request.getContextPath() + AVATAR_RESOURCE_PATH + "/" + utente.getId_utente() + "_" + utente.getNome_avatar(); ; } else { imageUrl = baseUrl + request.getContextPath() + "/res/images/user_avatar.png"; } Image image = Image.getInstance(new URL(imageUrl)); image.scaleToFit(50, 50); PdfPTable table = new PdfPTable(3); PdfPCell cellAvatar = new PdfPCell(image); cellAvatar.setHorizontalAlignment(Element.ALIGN_CENTER); cellAvatar.setBorder(Rectangle.NO_BORDER); cellAvatar.setRowspan(3); PdfPCell cellNome = new PdfPCell(new Paragraph(utente.getUsername() + "")); cellNome.setBorder(Rectangle.NO_BORDER); PdfPCell cellNumPost = new PdfPCell(new Paragraph(posts.size() + "")); cellNumPost.setBorder(Rectangle.NO_BORDER); //L'ultimo sempre il piu recente siccome la query ORDER BY data_creazione PdfPCell cellData; if (posts.size() != 0) { cellData = new PdfPCell(new Paragraph(posts.get(posts.size() - 1).getData_creazione())); } else { cellData = new PdfPCell(new Paragraph("N/A")); } cellData.setBorder(Rectangle.NO_BORDER); PdfPCell cellVoidBottom = new PdfPCell(new Paragraph(" ")); cellVoidBottom.setBorder(Rectangle.BOTTOM); cellVoidBottom.setPaddingBottom(10); cellVoidBottom.setColspan(3); PdfPCell cellVoidTop = new PdfPCell(new Paragraph(" ")); cellVoidTop.setBorder(Rectangle.NO_BORDER); cellVoidTop.setPaddingTop(10); cellVoidTop.setColspan(3); table.addCell(cellVoidTop); table.addCell(cellAvatar); table.addCell(labelNome); table.addCell(cellNome); table.addCell(labelNumPost); table.addCell(cellNumPost); table.addCell(labelData); table.addCell(cellData); table.addCell(cellVoidBottom); document.add(table); } document.close(); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "inline; filename=ahahah.pdf"); OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } catch (DocumentException ex) { Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.devox.GUI.PDF.CrearReporteApto.java
@Override public PdfPTable configurarInformacion() { PdfPTable table = new PdfPTable(2); PdfPCell cell; cell = new PdfPCell(getPhraseFromChunks("FACTURA ", factura)); cell.setBorder(PdfPCell.NO_BORDER);/*from w w w. j a va 2s .c o m*/ table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("FECHA FACTURA", "")); cell.setBorder(PdfPCell.NO_BORDER); cell.setRowspan(2); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("FOLIO CLIENTE ", folioCliente)); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("CLIENTE ", clienteSucursal)); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("MOTIVO ", motivo)); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); table.setTotalWidth(400); return table; }
From source file:com.devox.GUI.PDF.CrearReporteDestruccion.java
@Override public PdfPTable configurarInformacion() { PdfPTable table = new PdfPTable(2); try {/*from w ww. j ava2 s . c o m*/ PdfPCell cell; Phrase folio = new Phrase(); folio.add(new Chunk("FOLIO DHL ", FUENTE_FOLIO_CHICA)); folio.add(new Chunk(contenido.getFolioDHL(), FUENTE_FOLIO_CHICA_ROJA)); cell = new PdfPCell(folio); cell.setRowspan(8); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("Cliente ", contenido.getNombreCliente())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("Nmero de cliente ", contenido.getClaveCliente())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("Folio del cliente ", contenido.getFolioCliente())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("Folio Abbott ", contenido.getFolioAbbott())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("Motivo de devolucin ", contenido.getMotivo().getCodigo() + " - " + contenido.getMotivo().getDescripcion())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("Factura ", contenido.getFactura())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("Almacn ", contenido.getAlmacen())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell( getPhraseFromChunks("Fecha de captura ", Funciones.getOtherDate(contenido.getFechaCaptura()))); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); table.setWidthPercentage(100); table.setWidths(new int[] { 1, 3 }); } catch (DocumentException ex) { Log.print(ex); } return table; }
From source file:com.devox.GUI.PDF.CrearReporteTarimas.java
@Override public PdfPTable configurarInformacion() { PdfPTable table = new PdfPTable(2); try {//w w w . j av a 2 s .c o m PdfPCell cell; Phrase tarima = new Phrase(); tarima.add(new Chunk("TARIMA\n", FUENTE_TARIMA_NEGRO)); tarima.add(new Chunk(datosTarima.getNombreTarima(), FUENTE_TARIMA_ROJO)); cell = new PdfPCell(tarima); cell.setRowspan(5); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); cell.setFixedHeight(200f); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("DIVISIN ", datosTarima.getDivision())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("ALMACN ", datosTarima.getAlmacen())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("FECHA DE APERTURA ", Funciones.getOtherDate(datosTarima.getFecha_Apertura()))); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("FECHA DE CIERRE ", (datosTarima.getFecha_Cierra() == null ? "TARIMA ABIERTA" : Funciones.getOtherDate(datosTarima.getFecha_Cierra())))); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("DESTRUCCIN FISCAL ", Integer.toString(datosTarima.getDestruccionFiscal()))); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); table.setWidthPercentage(100); table.setWidths(new int[] { 2, 1 }); } catch (DocumentException de) { Log.print(de); } return table; }