List of usage examples for com.itextpdf.text.pdf PdfPCell setBackgroundColor
public void setBackgroundColor(final BaseColor backgroundColor)
From source file:gov.nih.nci.firebird.service.registration.AbstractPdfWriterGenerator.java
License:Open Source License
private void addMainHeaderCell(PdfPTable table, int index, String mainHeadingKey, int colspan) { PdfPCell headerCell = createCell(); headerCell.setBackgroundColor(TABLE_HEADER_COLOR); headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); headerCell.setColspan(colspan);/*www.ja v a 2s . co m*/ Phrase headerContents = new Phrase(getHeadingChunk(index, mainHeadingKey)); headerCell.setPhrase(headerContents); addToTable(table, headerCell); }
From source file:gov.nih.nci.firebird.service.registration.AbstractPdfWriterGenerator.java
License:Open Source License
private void addColumnHeadingCell(PdfPTable table, String columnHeadingKey) { Paragraph contents = new Paragraph(); contents.setAlignment(Element.ALIGN_BOTTOM); PdfPCell cell = createCell(); cell.setBackgroundColor(TABLE_CELL_COLOR); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setPhrase(contents);//w ww. ja va 2 s . c o m contents.add(getColumnHeaderChunk(columnHeadingKey)); addToTable(table, cell); }
From source file:gov.nih.nci.firebird.service.registration.AbstractPdfWriterGenerator.java
License:Open Source License
void addCellAndCompleteRow(PdfPTable table, String value) { PdfPCell cell = createTableCell(value); cell.setBackgroundColor(TABLE_CELL_COLOR); addCellAndCompleteRow(table, cell);/* w w w. j av a 2s . c om*/ }
From source file:gov.nih.nci.firebird.service.registration.AbstractPdfWriterGenerator.java
License:Open Source License
private void addToTable(PdfPTable table, Phrase contents) { PdfPCell cell = createCell(contents); cell.setBackgroundColor(TABLE_CELL_COLOR); addToTable(table, cell);/* w w w. ja v a 2 s . c o m*/ }
From source file:Gui.admin.NouveauConsulterinfoAdherent.java
private void RapportBouttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RapportBouttonActionPerformed String value1 = idadherenttxt.getText(); String value2 = nomadherentTxt.getText(); String value3 = prenomAdhrentTxt.getText(); String value4 = adresseAdherentTxt.getText(); String value5 = mdpAdherentTXT.getText(); String value6 = telAdherentTXT.getText(); String value7 = nbrReclamationsTxt.getText(); try {/*from ww w . j a v a 2 s. c om*/ // pagesize.A4.rotate() pour voir le rapport dans IDE com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.A4.rotate()); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("rapport.pdf")); if ((new File("rapport.pdf")).exists()) { Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler rapport.pdf"); p.waitFor(); } else { System.out.println("File is not exists"); } document.open(); // Date document.add(new Paragraph(new Date().toString())); document.add(new Paragraph("Rapport Statistiques", FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED))); document.add(new Paragraph( "--------------------------------------------------------------------------------------------------------------------------------------------------------------------")); // ajoute un tableau dans le rapport // PdfPTable table = new PdfPTable(4); // // PdfPCell cell = new PdfPCell(new Paragraph("Informations Adhrents")); // // le titre du tableau // cell.setColspan(10); // cell.setBackgroundColor(BaseColor.GREEN); // table.addCell(cell); // table.addCell("Id Adhrent"); // table.addCell("Nom de l'adhrent"); // table.addCell("Prnom de l'adhrent"); // table.addCell("Numro de l'adhrent"); // document.add(table); // le titre du tableau // ajouter l'image dans le fichier pdf Image image = Image.getInstance("statistiques.png"); document.add(new Paragraph("statistiques.png")); document.add(image); // document.add(new Paragraph("Salut sindoud", FontFactory.getFont(FontFactory.TIMES_BOLD,18,Font.BOLD, BaseColor.BLUE))); //document.add(new Paragraph (new Date().toString())); PdfPTable table = new PdfPTable(6); PdfPCell cell = new PdfPCell(new Paragraph("Titre")); cell.setColspan(4); // cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.GREEN); table.addCell("id de l'adherent"); table.addCell(value1); table.addCell("Nom de l'adhrent"); table.addCell(value2); table.addCell("Prnom de l'adhrent"); table.addCell(value3); table.addCell("adresse de l'adhrent"); table.addCell(value4); table.addCell("mot de passe de l'adherent"); table.addCell(value5); table.addCell("tel de l'adherent "); table.addCell(value6); table.addCell("nombre de reclamations"); table.addCell(value7); document.add(table); document.close(); //com.itextpdf.text.Image image1= com.itextpdf.text.Image.getInstance("statistiques.png"); // image1.scaleAbsolute(400,300); //document.add(image1); //PdfContentByte cb= writer.getDirectContent(); JOptionPane.showMessageDialog(null, "rapport enregistr"); } catch (DocumentException | IOException | InterruptedException | HeadlessException e) { JOptionPane.showMessageDialog(null, e); } // }
From source file:GUI.FrameUserPanier.java
private void BtnValiderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnValiderActionPerformed jLabel8.setText("" + CalculSomme()); String val1 = TFidpan.getText(); String val2 = TFnomut.getText(); String val3 = TFNomprod.getText(); String val4 = TFnombreprod.getText(); String val5 = TFdescription.getText(); try {/*from w ww .j a va 2 s . c o m*/ Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("Report.pdf")); document.open(); document.add(new Paragraph("VotrePanier", FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.BLUE))); document.add(new Paragraph(new Date().toString())); PdfPTable table = new PdfPTable(5); PdfPCell cell = new PdfPCell(new Paragraph("Mes achats")); cell.setColspan(5); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.BLUE); table.addCell(cell); table.addCell("IdPanier"); table.addCell("NomUtilsateur"); table.addCell("Nomprod"); table.addCell("Nombreprod"); table.addCell("Description"); cell.setBackgroundColor(BaseColor.BLUE); int i = TablePanier.getRowCount(); TableModel model = TablePanier.getModel(); for (int j = 0; j < i; j++) { val1 = model.getValueAt(j, 0).toString(); val2 = model.getValueAt(j, 2).toString(); val3 = model.getValueAt(j, 4).toString(); val4 = model.getValueAt(j, 5).toString(); val5 = model.getValueAt(j, 6).toString(); table.addCell(val1); table.addCell(val2); table.addCell(val3); table.addCell(val4); table.addCell(val5); } int z = TablePanier.getRowCount(); model = TablePanier.getModel(); float sum = 0; int bonus = 0; float net = 0; for (int j = 0; j < z; j++) { String x = model.getValueAt(j, 3).toString(); int idprod = Integer.parseInt(x); String q = model.getValueAt(j, 5).toString(); int qu = Integer.parseInt(q); Produit p = pdao.findByprodId(idprod); sum += p.getPrix() * qu; bonus += (p.getPtbonus() * qu); net += sum - (p.getReduction() * qu); } table.addCell("Somme: " + sum); table.addCell(""); table.addCell("Net: " + net); table.addCell(""); table.addCell("Bonus :" + bonus); document.add(table); document.close(); JOptionPane.showMessageDialog(null, "Report Saved"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:htmlparser.pdf.PDFFile.java
public void createScoreTable(Color oddrow_color, Color title_bg_color, Color title_font_color, int highlight) { if (this.opened) { int columnNumber = 0; for (String s : this.parser.getTeams().get(0).getData()) { columnNumber++;/*from w w w .ja v a 2 s . c om*/ } PdfPTable table = new PdfPTable(columnNumber + 1); Font f = new Font(this.fonttype, 13); int row = 1; Font headline = new Font(f); headline.setStyle("bold"); headline.setSize(16); headline.setColor(new BaseColor(title_bg_color.getRGB())); PdfPCell headcell = new PdfPCell(new Paragraph(this.parser.getCompetitionName(), headline)); headcell.setColspan(columnNumber + 1); headcell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(headcell); Font title = new Font(f); title.setStyle("bold"); title.setColor(new BaseColor(title_font_color.getRGB())); for (String s : this.shColNms) { PdfPCell cell = new PdfPCell(new Paragraph(s, title)); cell.setBackgroundColor(new BaseColor(title_bg_color.getRGB())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } row++; int order = 1; Font tfont = f; Font bold = new Font(f); bold.setStyle("bold"); for (Team t : this.parser.getTeams()) { if (highlight >= 0) { if (order == highlight + 1) { tfont = bold; } else { tfont = f; } } PdfPCell ordercell = new PdfPCell(new Paragraph(Integer.toString(order), tfont)); ordercell.setHorizontalAlignment(Element.ALIGN_CENTER); if (row % 2 == 0) { ordercell.setBackgroundColor(new BaseColor(oddrow_color.getRGB())); } table.addCell(ordercell); for (String s : t.getData()) { PdfPCell cell = new PdfPCell(new Paragraph(s, tfont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); if (row % 2 == 0) { cell.setBackgroundColor(new BaseColor(oddrow_color.getRGB())); } table.addCell(cell); } order++; row++; } try { float[] widths = { 12f, 40f, 13f, 5f, 5f, 5f, 10f, 10f }; table.setWidths(widths); this.document.add(table); } catch (DocumentException ex) { System.out.println("Content exception"); } } }
From source file:htmlparser.pdf.PDFFile.java
public void createMatchTable(Color oddrow_color, Color title_bg_color, Color title_font_color) { if (this.opened) { this.document.newPage(); int columnNumber = 0; for (String s : this.parser.getMatches().get(0).getData()) { columnNumber++;//from w ww .java 2 s . co m } PdfPTable table = new PdfPTable(columnNumber); Font f = new Font(this.fonttype, 13); int row = 1; Font headline = new Font(f); headline.setStyle("bold"); headline.setSize(16); headline.setColor(new BaseColor(title_bg_color.getRGB())); PdfPCell headcell = new PdfPCell(new Paragraph(this.parser.getTeamName(), headline)); headcell.setColspan(columnNumber); headcell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(headcell); Font title = new Font(f); title.setStyle("bold"); title.setColor(new BaseColor(title_font_color.getRGB())); for (String s : this.mhColNms) { PdfPCell cell = new PdfPCell(new Paragraph(s, title)); cell.setBackgroundColor(new BaseColor(title_bg_color.getRGB())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } row++; for (Match t : this.parser.getMatches()) { for (String s : t.getData()) { PdfPCell cell = new PdfPCell(new Paragraph(s, f)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); if (row % 2 == 0) { cell.setBackgroundColor(new BaseColor(oddrow_color.getRGB())); } table.addCell(cell); } row++; } try { float[] widths = { 26f, 26f, 20f, 8f, 20f }; table.setWidths(widths); this.document.add(table); } catch (DocumentException ex) { } } }
From source file:info.toegepaste.controller.PdfController.java
public void CreatePdf(long studentId) { //Fonts//from w w w. jav a2s . c o m Font header = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD); Font normal = new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL); //Declaration Student student = new Student(); List<Course> courses; List<Exam> exams = null; Score score; int totaal = 0; //totaal van een vak berekenen int maxScore = 0; //max soore van een test int aantalVakken = 0; //aantal vakken waaraan student heeft deelgenomen int klasgemiddelde = 0; //hulpvariabele om klasgemiddelde op te vragen Double totaalGemiddelde = 0.0; //eindpercentage Double vermenigvuldigfactor = 0.0; //om score op 20 weer te geven ArrayList<Integer> gemiddeldes = new ArrayList<Integer>(); //gemiddeldes per vak ArrayList<Integer> gemiddeldesKlas = new ArrayList<Integer>(); //gemiddelde klas per vak PdfPCell cell; //Document Document document = new Document(); //student opvullen student = pdfService.getStudent(studentId); //Tempfix //student.getClassgroup(); //cursussen opvullen courses = courseService.getWithClassgroup(student.getClassgroup()); for (int i = 0; i < courses.size(); i++) { //testen opvullen exams = pdfService.getExamsByCourse(courses.get(i)); for (int j = 0; j < exams.size(); j++) { score = pdfService.getScoreByExamAndStudent(exams.get(j), student); //nagaan of de student heeft deelgenomen aan de test if (score != null) { // score op 20 weergeven vermenigvuldigfactor = 20 / (double) exams.get(j).getTotal(); totaal += (int) (score.getScore() * vermenigvuldigfactor); } //klasgemiddelde voor een vak klasgemiddelde = pdfService.getAverageScoreByExam(exams.get(j)); gemiddeldesKlas.add(klasgemiddelde); } if (exams.size() > 0) { gemiddeldes.add(totaal / exams.size()); totaalGemiddelde += totaal / exams.size(); aantalVakken++; } totaal = 0; exams.clear(); } totaalGemiddelde = totaalGemiddelde / aantalVakken * 5; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { PdfWriter.getInstance(document, outputStream); document.open(); //header document.add(new Paragraph("Studenten Rapport", header)); document.add(new Paragraph("Student:" + student.getFirstname() + " " + student.getLastname(), normal)); document.add(new Paragraph("Klas:" + student.getClassgroup(), normal)); document.add(new Paragraph("Alle scores worden op 20 weergegeven", normal)); //table PdfPTable table = new PdfPTable(3); //create tableheaders PdfPCell c1 = new PdfPCell(new Phrase("Vak")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Score")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Gemiddelde")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < aantalVakken; i++) { cell = new PdfPCell(new Phrase(gemiddeldes.get(i).toString())); if (gemiddeldes.get(i) < 10) { cell.setBackgroundColor(BaseColor.RED); } table.addCell(courses.get(i).getName()); table.addCell(cell); table.addCell(gemiddeldesKlas.get(i).toString()); } document.add(table); //end document.add(new Paragraph("Totaal behaald percentage:" + totaalGemiddelde, normal)); document.close(); } catch (DocumentException e) { e.printStackTrace(); // } catch (FileNotFoundException e) { // e.printStackTrace(); } MultiPartEmail email = new MultiPartEmail(); email.setHostName("smtp.googlemail.com"); email.setSmtpPort(587); email.setSSLOnConnect(true); email.setAuthenticator(new DefaultAuthenticator("bitmescoretracker@gmail.com", "bitmeScore")); try { email.addTo(student.getEmail()); email.setFrom("bitmescoretracker@gmail.com"); email.setSubject("Requested scores , scoretracker"); email.setMsg("Here are the scores you requested!"); // EmailAttachment attachment = new EmailAttachment(); //attachment.setDescription("PDF met uw punten"); // attachment.setName(student.getFirstname() + " " + student.getLastname() + " scores"); byte[] bytes = outputStream.toByteArray(); DataSource source = new javax.mail.util.ByteArrayDataSource(bytes, "application/pdf"); System.out.println("Stuff"); /* try{ source = outputStream.write(bytes); }catch(IOException e){ e.printStackTrace(); }*/ email.attach(source, student.getFirstname() + " " + student.getLastname() + " scores", "stuff"); email.send(); } catch (EmailException ex) { ex.printStackTrace(); } }
From source file:Integral.PDF.java
/** * crea una celda con una imagen adentro para una tabla * @param img imagen a incluir en la celda * @param color fondo de la celda//from w w w .j a v a 2s. c o m * @param alineacion alineacion del contenido de la celda * @param expandirCol expandir la celda x columnas ej:3 junta la celda y 2 mas a la derecha * @param expandirRow Expandir la celda x renglones ej: 3 junta la celda y 2 mas hacia abajo * @param borde tipo de borde de la celda * @return */ public PdfPCell celda(Image img, BaseColor color, int alineacion, int expandirCol, int expandirRow, int borde) { PdfPCell c1 = new PdfPCell(img); c1.setColspan(expandirCol); c1.setRowspan(expandirRow); c1.setBackgroundColor(color); c1.setHorizontalAlignment(alineacion); c1.setBorder(borde); return c1; }