List of usage examples for com.itextpdf.text.pdf PdfPCell setGrayFill
public void setGrayFill(final float value)
From source file:bestdeal.util.genererPdf.java
public static void main(String[] args) { // - Paramtres de connexion la base de donnes Connection connection;//from w w w . j a va2 s . co m String[][] data = new String[][] { { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " }, }; try { String requete = "select c.nom,c.prenom,c.email,k.nom,k.prenom,k.telephone,k.adresse,k.email,d.id_deal,d.nom_deal,v.quantite,v.prix_unitaire from client c INNER JOIN voucher v on v.id_client=c.id_client INNER JOIN deal d on v.id_deal=d.id_deal INNER JOIN vendeur k on d.id_vendeur=k.id_vendeur"; connection = MyConnection.getInstance(); mypdf = new Document(PageSize.A4, 50, 50, 50, 50); File di = new File("C:/Voucher"); File fl[] = di.listFiles(); try { OutputStream file = new FileOutputStream(new File("C:/Voucher\\Voucher.pdf")); PdfWriter.getInstance(mypdf, file); mypdf.open(); Statement stm; mypdf.addAuthor("Best Deal"); mypdf.addSubject("Voucher "); mypdf.add(new Paragraph("Socite BestDeal")); mypdf.add(new Paragraph("Adresse La Chotrana ESPRIT ")); mypdf.add(new Paragraph("TEL : xx xxx xxx")); mypdf.add(new Paragraph("FAX : xx xxx xxx")); mypdf.add(new Paragraph( " " + new Date().toString())); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" " + "Voucher N'01", FontFactory.getFont(FontFactory.HELVETICA, 21, Font.BOLDITALIC))); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph("CLIENT :", FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC))); try { stm = connection.createStatement(); ResultSet rs = stm.executeQuery(requete); while (rs.next()) { // add a country to the document as a Chunk //mypdf.add(new Chunk(rs.getString("quantite"))); Phrase p = new Phrase("Nom: "); Phrase p2 = new Phrase(new Chunk(rs.getString("nom"))); Paragraph pa = new Paragraph(); pa.add(p); pa.add(p2); mypdf.add(pa); Phrase p3 = new Phrase("Prenom: "); Phrase p4 = new Phrase(new Chunk(rs.getString("prenom"))); Paragraph pa1 = new Paragraph(); pa1.add(p3); pa1.add(p4); mypdf.add(pa1); Phrase p5 = new Phrase("Adresse: "); Phrase p6 = new Phrase(new Chunk(rs.getString("adresse"))); Paragraph pa2 = new Paragraph(); pa2.add(p5); pa2.add(p6); mypdf.add(pa2); Phrase p7 = new Phrase("Tlphone: "); Phrase p8 = new Phrase(new Chunk(rs.getString("telephone"))); Paragraph pa3 = new Paragraph(); pa3.add(p7); pa3.add(p8); mypdf.add(pa3); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph("Vendeur :", FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC))); Phrase p9 = new Phrase("Nom: "); Phrase p10 = new Phrase(new Chunk(rs.getString("nom"))); Paragraph pa4 = new Paragraph(); pa4.add(p9); pa4.add(p10); mypdf.add(pa4); Phrase p11 = new Phrase("Prnom: "); Phrase p12 = new Phrase(new Chunk(rs.getString("prenom"))); Paragraph pa5 = new Paragraph(); pa5.add(p11); pa5.add(p12); mypdf.add(pa5); Phrase p13 = new Phrase("Tlphone: "); Phrase p14 = new Phrase(new Chunk(rs.getString("telephone"))); Paragraph pa6 = new Paragraph(); pa6.add(p13); pa6.add(p14); mypdf.add(pa6); Phrase p15 = new Phrase("Adresse: "); Phrase p16 = new Phrase(new Chunk(rs.getString("adresse"))); Paragraph pa7 = new Paragraph(); pa7.add(p15); pa7.add(p16); mypdf.add(pa7); Phrase p17 = new Phrase("Email: "); Phrase p18 = new Phrase(new Chunk(rs.getString("email"))); Paragraph pa8 = new Paragraph(); pa8.add(p17); pa8.add(p18); mypdf.add(pa8); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); for (int i = 0; i < rs.getRow(); i++) { for (int j = 0; j < data[i].length - 1; j++) { data[i][j] = rs.getString(j + 9); // if (j==3) // data[i][4]= Float.parseFloat(data[i][3])*Integer.parseInt(data[i][2])+""; } } for (int i = 0; i < rs.getRow(); i++) { float s = Integer.parseInt(data[i][2].trim()) * Float.parseFloat(data[i][3].trim()); data[i][4] = s + ""; } //mypdf.add(new Phrase("nom")); //mypdf.add(new Chunk(rs.getString("nom"))); //mypdf.add( new Paragraph("nom:", new Chunk(rs.getString("nom")))); //mypdf.add(new Chunk(" ")); //Chunk id = new Chunk(rs.getString("id")); // with a background color //id.setBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f); // and a text rise //id.setTextRise(6); // mypdf.add(id); mypdf.add(Chunk.NEWLINE); } } catch (SQLException ex) { Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex); } // mypdf.add(new Paragraph("Nom ")); // mypdf.add(new Paragraph("Prenom ")); // mypdf.add(new Paragraph("Adresse ")); //mypdf.add(new Paragraph("Tlphone ")); // mypdf.add(new Paragraph("Nom ")); // mypdf.add(new Paragraph("Nom de la socit ")); // mypdf.add(new Paragraph("Adresse ")); // mypdf.add(new Paragraph("Tlphone ")); // mypdf.add(new Paragraph(" ")); String[] headers = new String[] { " Id_deal", " Nom Deal", " Quantit", " Prix unitaire", " Prix total" }; PdfPTable table = new PdfPTable(headers.length); for (int i = 0; i < headers.length; i++) { String header = headers[i]; PdfPCell cell = new PdfPCell(); cell.setGrayFill(0.9f); cell.setPhrase(new Phrase(header.toUpperCase())); table.addCell(cell); } table.completeRow(); for (int i = 0; i < data.length; i++) { for (int j = 0; j < data[i].length; j++) { String datum = data[i][j]; PdfPCell cell = new PdfPCell(); cell.setPhrase(new Phrase(datum.toUpperCase())); table.addCell(cell); } table.completeRow(); } mypdf.add(table); } catch (FileNotFoundException ex) { Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex); } mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph( "Pour toute question concernant cette facture,veuillez contacter Nom,numro de tlphone,adresse de messagerie ", FontFactory.getFont(null, 9, Font.NORMAL))); mypdf.add(new Paragraph( " Merci pour votre confiance", FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLDITALIC))); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.add(new Paragraph(" ")); mypdf.close(); } catch (DocumentException ex) { Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:domain.Pdfmaker.java
public void makePdf() { Document doc = new Document(); doc.setPageSize(PageSize.A4);/* w w w . j a va2s . co m*/ try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(test.getTitle() + ".pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_7); doc.open(); Font f = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.BOLD, new BaseColor(0, 0, 0)); Paragraph title = new Paragraph("TEST TITLE", f); title.setAlignment(Element.ALIGN_CENTER); doc.addCreator("Arne De Bremme"); //make table PdfPTable table = new PdfPTable(4); table.setTotalWidth(550f); table.setLockedWidth(true); table.setHeaderRows(1); Paragraph p = new Paragraph(test.getTitle()); p.setAlignment(Element.ALIGN_CENTER); PdfPCell cell = new PdfPCell(p); cell.setGrayFill(0.7f); cell.setColspan(4); table.addCell(cell); table.addCell(test.getClassGroup().getGroupName()); PdfPCell cell2 = new PdfPCell(new Paragraph(test.getDescription())); cell2.setColspan(2); cell2.setRowspan(2); table.addCell(cell2); PdfPCell cell3 = new PdfPCell(new Paragraph("DD " + test.getStartDate().getDay() + "/" + test.getStartDate().getMonth() + "/" + test.getStartDate().getYear())); cell3.setRowspan(2); table.addCell(cell3); table.addCell(new Paragraph("Test " + test.getTestId())); doc.add(table); doc.add(Chunk.NEWLINE); for (Exercise e : ex) { Paragraph par = new Paragraph(); par.add("Vraag " + counter); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(e.getPunten() + "/"); doc.add(par); doc.add(new Paragraph("Klimatogram " + e.getClimateChart().getLocation() + " " + e.getPunten())); Robot r = new Robot(); Desktop.getDesktop().browse(new URI( "http://climatechart.azurewebsites.net/ClimateChart/ShowExercises?selectedYear=1&continentId=" + e.getClimateChart().getCountry().getContinent().getId() + "&countryId=" + e.getClimateChart().getCountry().getContinent().getId() + "&climateId=" + e.getClimateChart().getId())); TimeUnit.SECONDS.sleep(6); BufferedImage bi = r.createScreenCapture( new Rectangle(Toolkit.getDefaultToolkit().getScreenSize().width * 7 / 10, Toolkit.getDefaultToolkit().getScreenSize().width * 8 / 14)); File file = new File("screenCapture" + counter + ".jpg"); ImageIO.write(bi, "jpg", file); Image img = Image.getInstance("screenCapture.jpg"); img.scaleAbsolute(400, 300); doc.add(img); doc.add(Chunk.NEWLINE); doc.add(new Paragraph(e.getNaam())); doc.add(Chunk.NEXTPAGE); counter++; } doc.close(); File filz = new File(test.getTitle() + ".pdf"); Desktop.getDesktop().open(filz); } catch (Exception e) { } }
From source file:net.digitstar.vanadio.helpers.PdfHelper.java
License:Apache License
public static PdfPCell newCell(CellStyle style) { PdfPCell cell = new PdfPCell(); if (style != null) { if (style.getNestedTable() != null) { cell = new PdfPCell(style.getNestedTable()); style.setNestedTable(null);/*from w ww. ja v a 2 s. c o m*/ } else if (style.getImage() != null) { cell = new PdfPCell(style.getImage(), style.isFitImage()); style.setImage(null); } else if (style.getText() != null) { cell = new PdfPCell(style.getText()); style.setText((String) null); } cell.setColspan(style.getColspan()); cell.setRowspan(style.getRowspan()); cell.setMinimumHeight(style.getMinimumHeight()); cell.setFixedHeight(style.getFixedHeight()); cell.setNoWrap(style.isNoWrap()); cell.setRotation(style.getRotation().getValue()); style = Alignment.assign(style); cell.setHorizontalAlignment(style.getHorizAlign().getValue()); cell.setVerticalAlignment(style.getVertAlign().getValue()); cell.setUseVariableBorders(style.isUseVariableBorders()); cell.setUseBorderPadding(style.isUseBorderPadding()); if (!style.getBorderWidth().isAllSideEqual()) { cell.setBorderWidthBottom(style.getBorderWidth().getBottom()); cell.setBorderWidthLeft(style.getBorderWidth().getLeft()); cell.setBorderWidthRight(style.getBorderWidth().getRight()); cell.setBorderWidthTop(style.getBorderWidth().getTop()); } else { cell.setBorderWidth(style.getBorderWidth().getValue()); } cell.setPaddingBottom(style.getPadding().getBottom()); cell.setPaddingLeft(style.getPadding().getLeft()); cell.setPaddingRight(style.getPadding().getRight()); cell.setPaddingTop(style.getPadding().getTop()); cell.setBorderColorBottom(style.getBorderColor().getBottom()); cell.setBorderColorLeft(style.getBorderColor().getLeft()); cell.setBorderColorRight(style.getBorderColor().getRight()); cell.setBorderColorTop(style.getBorderColor().getTop()); cell.setBorder(style.getBorder().getValue()); cell.setBackgroundColor(style.getBackgroundColor()); if (style.getGreyFill() >= 0) { cell.setGrayFill(style.getGreyFill()); } } return cell; }
From source file:org.apache.jmeter.visualizers.CreateReport.java
License:Apache License
/** * Creates a table; widths are set with setWidths(). * @return a PdfPTable/*from w w w . j a va 2 s. c om*/ * @throws DocumentException */ public PdfPTable createTable1() throws DocumentException { PdfPTable table = new PdfPTable(7); table.setWidthPercentage(570 / 5.23f); table.setWidths(new int[] { 4, 4, 3, 3, 3, 3, 5 }); PdfPCell cell = null; for (int k = 0; k < 10; k++) { if (k != 5 && k != 8 && k != 9) { cell = new PdfPCell(new Phrase(JMeterUtils.getResString(COLUMNS[k]), headerFont)); BaseColor BC = new BaseColor(164, 188, 196); cell.setBackgroundColor(BC); cell.setColspan(1); table.addCell(cell); } } for (int l = 0; l < model.getRowCount(); l++) //row count does not include table headers for (int k = 0; k < 10; k++) { if (k != 5 && k != 8 && k != 9) { cell = new PdfPCell(new Phrase(model.getValueAt(l, k).toString(), rowFont)); cell.setGrayFill(2); table.addCell(cell); } } return table; /* original basic statements PdfPTable table = new PdfPTable(3); table.setWidthPercentage(288 / 5.23f); table.setWidths(new int[]{2, 1, 1}); PdfPCell cell; cell = new PdfPCell(new Phrase("Table 1")); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Phrase("Cell with rowspan 2")); cell.setRowspan(2); table.addCell(cell); table.addCell("row 1; cell 1"); table.addCell("row 1; cell 2"); table.addCell("row 2; cell 1"); table.addCell("row 2; cell 2"); return table; */ }
From source file:org.apache.jmeter.visualizers.CreateReport.java
License:Apache License
public PdfPTable createTable2() throws DocumentException { PdfPTable table = new PdfPTable(4); table.setWidthPercentage(570 / 5.23f); table.setWidths(new int[] { 1, 2, 1, 3 }); PdfPCell cell = null; for (int k = 0; k < 4; k++) { {/*from w w w. j a v a 2 s . com*/ cell = new PdfPCell(new Phrase(model2.getColumnName(k), headerFont)); BaseColor BC = new BaseColor(164, 188, 196); cell.setBackgroundColor(BC); cell.setColspan(1); table.addCell(cell); } } for (int l = 0; l < model2.getRowCount(); l++) //row count does not include table headers for (int k = 0; k < 4; k++) { cell = new PdfPCell(new Phrase(model2.getValueAt(l, k).toString(), rowFont)); cell.setGrayFill(2); table.addCell(cell); } return table; }
From source file:org.qnot.passtab.PDFOutput.java
License:Open Source License
private void addCell(PdfPTable table, String str, boolean bold, boolean fill, boolean rightBorder, boolean bottomBorder) { Phrase phrase = withColor ? new Phrase(str, bold ? fontBold : font) : new Phrase(str, font); PdfPCell cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); cell.setPadding(0f);/* w w w .jav a 2s . c om*/ cell.setPaddingTop(2f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); if (rightBorder) { cell.setBorderWidthRight(1f); cell.setPaddingRight(3f); cell.setHorizontalAlignment(Element.ALIGN_LEFT); } if (bottomBorder) { cell.setBorderWidthBottom(1f); cell.setPaddingBottom(3f); } if (fill && this.withColor) { cell.setGrayFill(0.80f); } table.addCell(cell); }
From source file:pipe.PdfMaker.java
private Element thirdElement(String hersteller, String modell) { float leading = 9f; PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f);/*from ww w .ja va 2 s. c om*/ PdfPCell cell; cell = new PdfPCell(new Paragraph("Hersteller", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Modell", arialSmall)); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setGrayFill(0.85f); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph herstellerInfo = new Paragraph(hersteller, courier); herstellerInfo.setLeading(leading); cell.addElement(herstellerInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph modellInfo = new Paragraph(modell, courier); modellInfo.setLeading(leading); cell.addElement(modellInfo); table.addCell(cell); return table; }
From source file:pipe.PdfMaker.java
private Element fifthElement(String land, String edition, String jahr) { float leading = 9f; PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f);// ww w . ja v a 2 s. c o m PdfPCell cell; //Hier die Header zuerst cell = new PdfPCell(new Paragraph("Land", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Edition", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Jahr", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); //Ab hier die Werte cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph herkunftInfo = new Paragraph(land, courier); herkunftInfo.setLeading(leading); cell.addElement(herkunftInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph editionInfo = new Paragraph(edition, courier); editionInfo.setLeading(leading); cell.addElement(editionInfo); table.addCell(cell); cell = new PdfPCell(); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph yearInfo = new Paragraph(jahr, courier); yearInfo.setLeading(leading); cell.addElement(yearInfo); table.addCell(cell); return table; }
From source file:pipe.PdfMaker.java
private Element sixthElement(String grundform, String mundstck) { float leading = 9f; PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f);/*from w w w. j a va 2 s .co m*/ PdfPCell cell; cell = new PdfPCell(new Paragraph("Grundform", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Mundstck", arialSmall)); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setGrayFill(0.85f); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph herstellerInfo = new Paragraph(grundform, courier); herstellerInfo.setLeading(leading); cell.addElement(herstellerInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph modellInfo = new Paragraph(mundstck, courier); modellInfo.setLeading(leading); cell.addElement(modellInfo); table.addCell(cell); return table; }
From source file:pipe.PdfMaker.java
private Element seventhElement(String kopfmat, String mundmat) { float leading = 9f; PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f);//from w ww. ja v a2 s. c o m PdfPCell cell; cell = new PdfPCell(new Paragraph("Kopfmaterial", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Material Mundstck", arialSmall)); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setGrayFill(0.85f); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph mundMatInfo = new Paragraph(kopfmat, courier); mundMatInfo.setLeading(leading); cell.addElement(mundMatInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph modellInfo = new Paragraph(mundmat, courier); modellInfo.setLeading(leading); cell.addElement(modellInfo); table.addCell(cell); return table; }