List of usage examples for com.itextpdf.text Element ALIGN_CENTER
int ALIGN_CENTER
To view the source code for com.itextpdf.text Element ALIGN_CENTER.
Click Source Link
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private PdfPTable createOrderButton(Model model) throws IOException, BadElementException { final Chunk chunk = new Chunk("Order on taconic.com", iTextUtil.getFontButton()); chunk.setAction(// w ww . j a v a 2 s. c o m new PdfAction("http://www.taconic.com/start-an-order?modelNumber=" + model.getModelNumber())); final PdfPCell cell = cell(new Phrase(chunk)); cell.setBackgroundColor(iTextUtil.getTaconicRed()); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingTop(5); cell.setPaddingBottom(8); final PdfPTable button = new PdfPTable(new float[] { 80f, 20f }); button.addCell(cell(new Phrase(" "), 2)); button.addCell(cell); button.addCell(cell(new Phrase(" "))); button.addCell(cell(new Phrase(" "), 2)); return button; }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private PdfPCell cellD(Phrase p, boolean invert) { final PdfPCell cell = new PdfPCell(p); cell.setBorder(0);/* w w w. j av a 2s .co m*/ cell.setPadding(5f); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); if (invert) { cell.setBackgroundColor(iTextUtil.getSilver()); } return cell; }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private PdfPCell cellH(Phrase p) { final PdfPCell cell = new PdfPCell(p); cell.setBackgroundColor(iTextUtil.getPurple()); cell.setPadding(5f);//from w ww . j ava2 s . c o m cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); return cell; }
From source file:be.roots.taconic.pricingguide.util.iTextUtil.java
License:Open Source License
public static byte[] setPageNumbers(byte[] pdfDocument) throws IOException, DocumentException { final int numberOfPages = numberOfPages(pdfDocument); if (numberOfPages > 1) { try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { final PdfReader reader = new PdfReader(pdfDocument); final PdfStamper stamper = new PdfStamper(reader, baos); for (int pageNumber = 2; pageNumber <= numberOfPages; pageNumber++) { // get the first page final PdfContentByte canvas = stamper.getOverContent(pageNumber); // stamp the footer on the page final ColumnText ct = new ColumnText(canvas); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase(pageNumber + "", getFontPageNumber()), 550, 22, 0); ct.go();// w ww .jav a 2 s. c o m } // close out stamper.close(); reader.close(); return baos.toByteArray(); } } return pdfDocument; }
From source file:be.thomasmore.service.CreatePDFServiceImp.java
@Override public void createPDF(List<Score> scores) { try {/*from w ww. j a v a 2s .co m*/ OutputStream file = new FileOutputStream(new File("D:\\Desktop\\Scores.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); document.add(new Paragraph("Scores")); document.add(new Paragraph(new Date().toString())); document.addAuthor("Projectgroep 4"); document.addCreator("Projectgroep 4"); document.addTitle("ScoreTracker"); //Create Paragraph Paragraph paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); //New line paragraph.add(new Paragraph(" ")); paragraph.add("Scores"); paragraph.add(new Paragraph(" ")); document.add(paragraph); //Create a table in PDF PdfPTable pdftabel = new PdfPTable(4); PdfPCell cell1 = new PdfPCell(new Phrase("Student")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); cell1 = new PdfPCell(new Phrase("Vak")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); cell1 = new PdfPCell(new Phrase("Test")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); cell1 = new PdfPCell(new Phrase("Score")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); pdftabel.setHeaderRows(1); for (Score score : scores) { pdftabel.addCell(score.getStudent().getNaam()); pdftabel.addCell(score.getTest().getVak().getNaam()); pdftabel.addCell(score.getTest().getNaam()); int resultaat = score.getScore(); pdftabel.addCell(resultaat + " / " + score.getTest().getTotaal()); } document.add(pdftabel); document.addCreationDate(); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:be.thomasmore.service.CreatePDFServiceImp.java
@Override public void createPDFVoorStudent(ArrayList<ArrayList<Score>> puntenlijst, List<Double> gemiddeldelijst, Double totaalGemiddelde) { try {/*ww w . j a va 2s . c o m*/ OutputStream file = new FileOutputStream(new File("D:\\Desktop\\Scores.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); document.add(new Paragraph("Scores")); document.add(new Paragraph(puntenlijst.get(0).get(0).getStudent().getNaam())); document.add(new Paragraph(new Date().toString())); document.addAuthor("Projectgroep 4"); document.addCreator("Projectgroep 4"); document.addTitle("ScoreTracker"); //Create Paragraph Paragraph paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); //New line paragraph.add(new Paragraph(" ")); paragraph.add("Scores"); paragraph.add(new Paragraph(" ")); document.add(paragraph); for (int i = 0; i < puntenlijst.size(); i++) { //Create a table in PDF PdfPTable pdftabel = new PdfPTable(2); //vak invullen paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); paragraph.add(new Paragraph(puntenlijst.get(i).get(0).getTest().getVak().getNaam())); document.add(paragraph); PdfPCell cell1 = new PdfPCell(new Phrase("Test")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); cell1 = new PdfPCell(new Phrase("Score")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); pdftabel.setHeaderRows(1); for (Score score : puntenlijst.get(i)) { pdftabel.addCell(score.getTest().getNaam()); int resultaat = score.getScore(); pdftabel.addCell(resultaat + " / " + score.getTest().getTotaal()); } document.add(pdftabel); //gemmidelde per vak invoeren paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); paragraph.add(new Paragraph("Gemiddelde: " + gemiddeldelijst.get(i).toString())); document.add(paragraph); } paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); paragraph.add(new Paragraph("Algemeen gemiddelde: " + totaalGemiddelde)); document.add(paragraph); document.addCreationDate(); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:bemyguest.controller.ValidationResevation.java
@FXML private void handleButtonValiderAction(ActionEvent event) throws FileNotFoundException, DocumentException { Resrevation e = tab_reservation.getSelectionModel().getSelectedItem(); if (e == null) { Alert alert = new Alert(Alert.AlertType.WARNING); alert.setTitle("Warning Dialog"); alert.setHeaderText(null);/*from www . jav a 2s . co m*/ alert.setContentText("selectionner un demande de reservation a traiter svp!"); alert.showAndWait(); LoadData(); setCellTable(); } else { Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.setTitle("Confiramtion"); alert.setHeaderText(null); alert.setContentText("vous etes sur d'accepter cette demande de reservation"); Optional<ButtonType> answer = alert.showAndWait(); if (answer.get() == ButtonType.OK) { ResevationDAO dao = new ResevationDAO(); if (dao.ajouter_Reservation(e)) { LoadData(); setCellTable(); alert.setTitle("Success Dialog"); alert.setHeaderText(null); alert.setContentText("Demandes accepter avec success"); alert.showAndWait(); try { Document d = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(d, new FileOutputStream(e.getUser().getNom() + "Facture.pdf")); d.open(); d.add(new Paragraph("BeMyGuest Facture :", FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED))); d.add(new Paragraph(new Date().toString())); d.add(new Paragraph( "-------------------------------------------------------------------------------------------------------------")); d.add(new Paragraph(" ")); d.add(new Paragraph(" ")); PdfPTable pdt = new PdfPTable(7); PdfPCell cell = new PdfPCell(new Paragraph("Composant de facture")); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.RED); pdt.addCell(cell); pdt.addCell(new Paragraph("Nom:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Prenom:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Date Debut:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Date Fin:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("nbre chambre:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("nbre personne:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph("Prix:", FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getUserDemandant().getNom(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getUserDemandant().getPrenom(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getDateDebut().toString(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(e.getDateFin().toString(), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(e.getDateDebut().toString()); int nb = e.getPropriete().getNbrChambre(); float pr = e.getPropriete().getPrix(); int nbp = e.getPropriete().getNbrVoyageur(); pdt.addCell(new Paragraph(Integer.toString(nb), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(Integer.toString(nbp), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(new Paragraph(Float.toString(pr), FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK))); pdt.addCell(Float.toString(pr)); d.add(pdt); d.close(); } catch (Exception b) { JOptionPane.showMessageDialog(null, b); } } else { alert.setTitle("Error Dialog"); alert.setHeaderText(null); alert.setContentText("Cette Propriete Reserver pendant cette date "); alert.showAndWait(); LoadData(); setCellTable(); } } else { LoadData(); setCellTable(); } } }
From source file:bl.pdf.PDFFile.java
private PdfPTable getTable(EntityTableModel tModel) { String[] headers = tModel.getColumnNames(); PdfPTable table = new PdfPTable(headers.length); table.setHeaderRows(1);// w w w . jav a2 s . c om table.setWidthPercentage(100); for (String header : headers) { PdfPCell c1 = new PdfPCell(new Phrase(header)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } ArrayList<DBEntity> entries = tModel.getEntries(); if (entries.isEmpty()) { PdfPCell c = new PdfPCell(new Phrase("Keine Eintrge vorhanden")); c.setHorizontalAlignment(Element.ALIGN_CENTER); c.setColspan(headers.length); table.addCell(c); return table; } for (DBEntity entry : entries) { for (String header : headers) { Method method; Object a; try { method = entry.getClass().getMethod("get" + header, new Class<?>[0]); a = method.invoke(entry, new Object[0]); table.addCell(String.valueOf(a)); } catch (NoSuchMethodException e) { e.printStackTrace(); table.addCell(new String("")); } catch (SecurityException e) { e.printStackTrace(); table.addCell(new String("")); } catch (IllegalAccessException e) { e.printStackTrace(); table.addCell(new String("")); } catch (IllegalArgumentException e) { e.printStackTrace(); table.addCell(new String("")); } catch (InvocationTargetException e) { e.printStackTrace(); table.addCell(new String("")); } } } return table; }
From source file:bl.pdf.PDFFile.java
private PdfPTable getRechnungszeileTable(Rechnung r) throws DALException { String[] headers;/*w w w.j a va 2 s . c om*/ if (r instanceof Eingangsrechnung) { String[] h = { "Rechnungszeile", "Kommentar", "Steuersatz", "Betrag", "ohne Steuer" }; headers = h; } else { String[] h = { "Rechnungszeile", "Kommentar", "AngebotID", "Steuersatz", "Betrag", "ohne Steuer" }; headers = h; } PdfPTable table = new PdfPTable(headers.length); table.setHeaderRows(1); table.setWidthPercentage(100); for (String header : headers) { PdfPCell c1 = new PdfPCell(new Phrase(header)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } ArrayList<Rechnungszeile> rechnungszeilen = BL.getRechnungszeileListe(r.getRechnungID()); if (rechnungszeilen.isEmpty()) { PdfPCell c = new PdfPCell(new Phrase("Keine Rechnungszeilen vorhanden")); c.setHorizontalAlignment(Element.ALIGN_CENTER); if (r instanceof Ausgangsrechnung) { c.setColspan(6); } else { c.setColspan(5); } table.addCell(c); return table; } double summe = 0; double summeOhne = 0; for (Rechnungszeile rz : rechnungszeilen) { table.addCell(String.valueOf(rz.getRechnungszeileID())); table.addCell(String.valueOf(rz.getKommentar())); if (r instanceof Ausgangsrechnung) { table.addCell(String.valueOf(rz.getAngebotID())); } table.addCell(String.valueOf(rz.getSteuersatz())); table.addCell(String.valueOf(rz.getBetrag())); double betrag = rz.getBetrag(); double steuersatz = rz.getSteuersatz(); double betragOhne = betrag - (betrag / 100 * steuersatz); table.addCell(String.valueOf(betragOhne)); summe += rz.getBetrag(); summeOhne += betragOhne; } PdfPCell c = new PdfPCell(new Phrase("Summe")); c.setHorizontalAlignment(Element.ALIGN_RIGHT); if (r instanceof Ausgangsrechnung) { c.setColspan(4); } else { c.setColspan(3); } table.addCell(c); table.addCell(String.valueOf(summe)); table.addCell(String.valueOf(summeOhne)); return table; }
From source file:bl.pdf.PDFFile.java
private void createTable(Section subCatPart) throws BadElementException { PdfPTable table = new PdfPTable(3); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);/*from w w w. jav a2 s .c om*/ c1 = new PdfPCell(new Phrase("Table Header 2")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Table Header 3")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); table.addCell("1.0"); table.addCell("1.1"); table.addCell("1.2"); table.addCell("2.1"); table.addCell("2.2"); table.addCell("2.3"); subCatPart.add(table); }