List of usage examples for com.itextpdf.text.pdf PdfPTable setSpacingAfter
public void setSpacingAfter(final float spacing)
From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * /*from ww w . j ava 2s . c om*/ * Table * * @param section table? section ? * @param e table element * @throws Exception */ public static void setTable(Section section, Element e) throws Exception { int colSize = Integer.parseInt(e.getAttributeValue("size")); PdfPTable t = new PdfPTable(colSize); if (e.getAttributeValue("width") != null) t.setTotalWidth(Float.parseFloat(e.getAttributeValue("width"))); t.setSpacingAfter(12); t.getDefaultCell().setLeading(0.0F, 1.3F); t.getDefaultCell().setMinimumHeight(22); t.getDefaultCell().setPaddingBottom(8); t.getDefaultCell().setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); setTableHeader(e, t, colSize); setTableRow(e, t); section.add(t); }
From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * /*w ww . jav a 2 s .c o m*/ * box * * @param section box section ? * @param e box element * @throws Exception */ public static void setBox(Section section, Element e) throws Exception { PdfPTable t = new PdfPTable(1); t.setSpacingBefore(1); t.setSpacingAfter(12); if (e.getAttributeValue("width") != null) t.setTotalWidth(Float.parseFloat(e.getAttributeValue("width"))); PdfPCell cell = new PdfPCell(); if (e.getAttributeValue("option") != null) { ColumnText col = new ColumnText(null); for (Element e1 : e.getChildren()) { if (e1.getAttributeValue("type").equals("red")) col.addText(new Phrase(e1.getText(), fnBoxRed)); else col.addText(new Phrase(e1.getText(), fnBox)); } cell.setColumn(col); } else { cell.setPhrase(new Phrase(e.getText(), fnBox)); } cell.setPaddingLeft(10); cell.setLeading(0.0F, 1.8F); cell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); cell.setBackgroundColor(new BaseColor(238, 236, 225)); t.addCell(cell); section.add(t); }
From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * // w ww. j a v a 2s .co m * box (Backgroud : Black) * * @param section box section ? * @param e box element * @throws Exception */ public static void setBoxB(Section section, Element e) throws Exception { PdfPTable t = new PdfPTable(1); t.setSpacingBefore(1); t.setSpacingAfter(12); if (e.getAttributeValue("width") != null) t.setTotalWidth(Float.parseFloat(e.getAttributeValue("width"))); PdfPCell cell = new PdfPCell(); if (e.getAttributeValue("option") != null) { ColumnText col = new ColumnText(null); for (Element e1 : e.getChildren()) { if (e1.getAttributeValue("type").equals("red")) col.addText(new Phrase(e1.getText(), fnBoxRed)); else col.addText(new Phrase(e1.getText(), fnBoxWhite)); } cell.setColumn(col); } else { cell.setPhrase(new Phrase(e.getText(), fnBoxWhite)); } cell.setPaddingLeft(10); cell.setLeading(0.0F, 1.8F); cell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); cell.setBackgroundColor(new BaseColor(0, 0, 0)); t.addCell(cell); section.add(t); }
From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * /* w w w.ja va 2 s .co m*/ * box (Backgroud : White) * * @param section box section ? * @param e box element * @throws Exception */ public static void setBoxW(Section section, Element e) throws Exception { PdfPTable t = new PdfPTable(1); t.setSpacingBefore(1); t.setSpacingAfter(12); if (e.getAttributeValue("width") != null) t.setTotalWidth(Float.parseFloat(e.getAttributeValue("width"))); PdfPCell cell = new PdfPCell(); if (e.getAttributeValue("option") != null) { ColumnText col = new ColumnText(null); for (Element e1 : e.getChildren()) { if (e1.getAttributeValue("type").equals("red")) col.addText(new Phrase(e1.getText(), fnBoxRed)); else col.addText(new Phrase(e1.getText(), fnBoxBlack)); } cell.setColumn(col); } else { cell.setPhrase(new Phrase(e.getText(), fnBoxBlack)); } cell.setPaddingLeft(10); cell.setLeading(0.0F, 1.8F); cell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); cell.setBackgroundColor(new BaseColor(255, 255, 255)); t.addCell(cell); section.add(t); }
From source file:com.bougsid.printers.PrintMission.java
public void printMission(Mission mission) { Document document = new Document(PageSize.A4); try {/*from w ww . ja v a2 s. c om*/ File downloadDir = new File(msg.getMessage("application.mission.downloaddir")); if (!downloadDir.exists()) { downloadDir.mkdir(); } System.out.println("Dir =" + downloadDir.getPath()); PdfWriter.getInstance(document, new FileOutputStream(downloadDir.getPath() + "/" + mission.getUuid() + ".pdf")); document.open(); Paragraph p = new Paragraph(); p.setSpacingAfter(60); document.add(p); //header Paragraph paragraph = new Paragraph( msg.getMessage("mission.pdf.school") + " " + mission.getIdMission() + " ", DEFAULT_FONT); Phrase phrase = new Phrase(msg.getMessage("mission.pdf.city") + " " + LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); paragraph.add(phrase); paragraph.setSpacingAfter(50); document.add(paragraph); //title PdfPTable table = new PdfPTable(1); table.setWidthPercentage(40); PdfPCell cell = new PdfPCell(new Phrase(msg.getMessage("mission.pdf.title"), FontFactory.getFont(FontFactory.HELVETICA, 18))); cell.setBorderWidth(1); cell.setPadding(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setSpacingAfter(40); document.add(table); //content table = new PdfPTable(2); table.setWidthPercentage(100); //line 1 cell = new PdfPCell(new Paragraph(mission.getEmploye().getCivilite().getLabel(), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFullName(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 2 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.matricule"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getMatricule(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 3 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.grade"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFonction(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); if (mission.getEntreprise() != null) { //line 4 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1_2"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 5 cell = new PdfPCell(new Paragraph(" ", DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(" - " + mission.getEntreprise().getNom(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); } //line 6 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.lieu"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); p = new Paragraph(); p.setFont(DEFAULT_FONT); for (Ville ville : mission.getVilles()) { p.add(ville.getNom() + "\n"); } cell = new PdfPCell(p); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 7 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.startdate"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph( ": " + mission.getStartDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + " Heure : " + mission.getStartDate().format(DateTimeFormatter.ofPattern("HH:mm")), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 8 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.enddate"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph( ": " + mission.getEndDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + " Heure : " + mission.getEndDate().format(DateTimeFormatter.ofPattern("HH:mm")), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 9 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.transport"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); switch (mission.getTransportType()) { case PERSONNEL: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.perso") + " " + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; case Accompagnement: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.accomp") + " " + mission.getAccompEmploye().getCivilite() + " " + mission.getAccompEmploye().getFullName() + " " + msg.getMessage("mission.pdf.accomp.voitue") + " " + mission.getAccompEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getAccompEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; case Service: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.service") + " " + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; default: { cell = new PdfPCell(new Paragraph( ": " + mission.getTransportType().getLabel() + " " + msg.getMessage("mission.pdf.taxi"), DEFAULT_FONT)); } } cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); table.setSpacingAfter(40); document.add(table); //note document.add(new Paragraph(msg.getMessage("mission.pdf.TEXT_2"), DEFAULT_FONT)); //signature if (mission.getEmploye().getGrade().getType() == GradeType.DG) { } else { Employe dir = employeService.getDG(); if (dir != null) paragraph = new Paragraph(dir.getFullName(), DEFAULT_FONT); paragraph.setAlignment(Element.ALIGN_RIGHT); paragraph.setSpacingBefore(40); document.add(paragraph); paragraph = new Paragraph(msg.getMessage("mission.pdf.DG"), DEFAULT_FONT); paragraph.setAlignment(Element.ALIGN_RIGHT); document.add(paragraph); } } catch (DocumentException ex) { ex.printStackTrace(); } catch (FileNotFoundException ex) { ex.printStackTrace(); } document.close(); // try { // Desktop.getDesktop().open(new File("./order.pdf")); // } catch (IOException ex) { // JOptionPane.showMessageDialog(null, "Fichier gner mais ne peut pas etre ouvert vrifier le dossier"); // } }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
private PdfPTable getTableDeItens(List<ItemDeVenda> itens) throws DocumentException { PdfPTable table = new PdfPTable(4); table.setWidths(new int[] { 5, 1, 1, 1 }); table.setWidthPercentage(100f);// w w w . j a v a2s. com table.setSpacingBefore(10f); table.setSpacingAfter(10f); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell("Produto"); table.addCell("Quantidade"); table.addCell("Valor UN"); table.addCell("Total"); table.getDefaultCell().setBackgroundColor(null); for (ItemDeVenda it : itens) { table.addCell(it.getDescricaoProduto()); table.addCell(new DecimalFormat("0.000").format(it.getQuantidade())); table.addCell(new DecimalFormat("0.00").format(it.getValorProduto())); table.addCell(new DecimalFormat("0.00").format(it.getTotal())); } return table; }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
private PdfPTable getTableEstoqueProdutos(boolean valoresNegativos) throws DocumentException { double total_requisitado = 381624.18; Map<String, Double[]> saida = GeradorRelatorio.getRelatorioEstoqueProdutos(valoresNegativos); PdfPTable table = new PdfPTable(4); table.setWidths(new int[] { 5, 2, 1, 1 }); table.setWidthPercentage(100f);//from w w w . j a v a 2 s . c o m table.setSpacingBefore(10f); table.setSpacingAfter(10f); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell("Produto"); table.addCell("Quantidade em Estoque"); table.addCell("Valor de Compra"); table.addCell("SubTotal"); table.getDefaultCell().setBackgroundColor(null); double quantidade = 0, total = 0; List<String> c = new ArrayList<String>(); c.addAll(saida.keySet()); Collections.sort(c); for (String produto : c) { Double[] val = saida.get(produto); double qt, vc, sub; qt = val[0]; vc = val[1]; sub = val[0] * val[1]; if (qt > 0 && qt < 10000) { quantidade += qt; total += (qt * vc); table.addCell(produto); table.addCell(new DecimalFormat("0.000").format(qt)); table.addCell(new DecimalFormat("0.00").format(vc)); table.addCell(new DecimalFormat("0.00").format(qt * vc)); } else { continue; //table.addCell(new DecimalFormat("0.00").format(val[1])); //table.addCell(new DecimalFormat("0.000").format(0)); //table.addCell(new DecimalFormat("0.00").format(vc)); //table.addCell(new DecimalFormat("0.00").format(0)); } if (total_requisitado - 10 <= total && total <= total_requisitado + 10) { break; } } table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); PdfPCell cell = new PdfPCell(new Paragraph("Total")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell(cell); //table.addCell(OperacaoStringUtil.formatarStringValorIntegerEPonto( // saida.size()) + " Produtos"); //table.addCell(OperacaoStringUtil.formatarStringQuantidadeEPonto(quantidade) // + " Itens"); String tot = OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(381624.18); PdfPCell cel2 = new PdfPCell(new Paragraph(tot)); cel2.setColspan(2); cel2.setHorizontalAlignment(Element.ALIGN_CENTER); cel2.setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell(cel2); //table.addCell(OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(total)); //System.out.println(total); return table; }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
private PdfPTable getTableEstoqueProdutos(boolean valoresNegativos, boolean paraLista, List<String> codigos_retirados, double total_requisitado) throws DocumentException { //double total_requisitado = 381624.18; Map<String, Double[]> saida = GeradorRelatorio.getRelatorioEstoqueProdutos(valoresNegativos, codigos_retirados);// w w w .j a v a 2 s . co m PdfPTable table = new PdfPTable(4); table.setWidths(new int[] { 5, 2, 1, 1 }); table.setWidthPercentage(100f); table.setSpacingBefore(10f); table.setSpacingAfter(10f); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell("Produto"); table.addCell("Quantidade em Estoque"); table.addCell("Valor de Compra"); table.addCell("SubTotal"); table.getDefaultCell().setBackgroundColor(null); double quantidade = 0, total = 0; List<String> c = new ArrayList<String>(); c.addAll(saida.keySet()); Collections.sort(c); for (String produto : c) { if (paraLista && total_requisitado <= total) { break; } Double[] val = saida.get(produto); double qt, vc, sub; qt = val[0]; vc = val[1]; sub = val[0] * val[1]; if (qt > 0 && qt < 10000) { quantidade += qt; total += (qt * vc); table.addCell(produto); table.addCell(new DecimalFormat("0.000").format(qt)); table.addCell(new DecimalFormat("0.00").format(vc)); table.addCell(new DecimalFormat("0.00").format(qt * vc)); } else { continue; //table.addCell(new DecimalFormat("0.00").format(val[1])); //table.addCell(new DecimalFormat("0.000").format(0)); //table.addCell(new DecimalFormat("0.00").format(vc)); //table.addCell(new DecimalFormat("0.00").format(0)); } } table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); PdfPCell cell = new PdfPCell(new Paragraph("Total")); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell(cell); //table.addCell(OperacaoStringUtil.formatarStringValorIntegerEPonto( // saida.size()) + " Produtos"); //table.addCell(OperacaoStringUtil.formatarStringQuantidadeEPonto(quantidade) // + " Itens"); String tot = OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(total_requisitado); PdfPCell cel2 = new PdfPCell(new Paragraph(tot)); cel2.setColspan(2); cel2.setHorizontalAlignment(Element.ALIGN_CENTER); cel2.setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell(cel2); //table.addCell(OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(total)); //System.out.println(total); return table; }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
private PdfPTable getTableBalancoProdutos(Date inicio, Date fim) throws DocumentException { Map<String, Double[]> saida = GeradorRelatorio.getRelatorioDetalhadoSaidaProduto(inicio, fim); PdfPTable table = new PdfPTable(5); table.setWidths(new int[] { 5, 1, 1, 1, 1 }); table.setWidthPercentage(100f);/*w ww.ja v a2 s. com*/ table.setSpacingBefore(10f); table.setSpacingAfter(10f); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell("Produto"); table.addCell("Estoque"); table.addCell("Compra"); table.addCell("Venda"); table.addCell("Lucro"); table.getDefaultCell().setBackgroundColor(null); double compra = 0, venda = 0, lucro = 0, qt = 0; List<String> c = new ArrayList<String>(); c.addAll(saida.keySet()); Collections.sort(c); for (String produto : c) { table.addCell(produto); Double[] val = saida.get(produto); compra += val[0]; venda += val[1]; lucro += val[3]; qt += val[2]; table.addCell(new DecimalFormat("0.000").format(val[2])); table.addCell(new DecimalFormat("0.00").format(val[0])); table.addCell(new DecimalFormat("0.00").format(val[1])); table.addCell(new DecimalFormat("0.00").format(val[3])); } table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); PdfPCell cell = new PdfPCell(new Paragraph("Total")); cell.setColspan(5); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell(cell); table.addCell(saida.size() + " Produtos"); table.addCell(new DecimalFormat("0.000").format(qt)); table.addCell(new DecimalFormat("0.00").format(compra)); table.addCell(new DecimalFormat("0.00").format(venda)); table.addCell(new DecimalFormat("0.00").format(lucro)); return table; }
From source file:com.cs.sis.controller.gerador.GeradorPDF.java
private PdfPTable getTableDebitoClientes(double maiorQue) throws DocumentException { List<Object[]> debitos = GeradorRelatorio.getRelatorioClientesComDebitoMaiorQue(maiorQue); PdfPTable table = new PdfPTable(2); table.setWidths(new int[] { 5, 2 }); table.setWidthPercentage(100f);/*w ww . j ava 2 s . c om*/ table.setSpacingBefore(10f); table.setSpacingAfter(10f); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell("Cliente"); table.addCell("Dbito"); table.getDefaultCell().setBackgroundColor(null); double total = 0; for (Object[] d : debitos) { table.addCell((String) d[0]); double val = (double) d[1]; table.addCell(OperacaoStringUtil.formatarStringValorMoedaEPonto(val)); total += val; } table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198)); PdfPCell cell = new PdfPCell(new Paragraph("Total")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(60, 171, 198)); table.addCell(cell); table.addCell(OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(total)); table.addCell("Quantidade de Clientes"); table.addCell(OperacaoStringUtil.formatarStringValorInteger(debitos.size())); return table; }