List of usage examples for com.itextpdf.text Font BOLD
int BOLD
To view the source code for com.itextpdf.text Font BOLD.
Click Source Link
From source file:pdf.PDFDesign.java
private PdfPCell createEuroInnerInnerPrice(String price, String curr, boolean isFirst) throws DocumentException { Font bigPriceFont = new Font(droidsans, 40, Font.BOLD, color); Font smallPriceFont = new Font(droidsans, 18, Font.NORMAL, color); Font unitFont = new Font(droidsans, 12, Font.NORMAL, color); PdfPTable table = new PdfPTable(2); table.setWidths(new float[] { 3f, 1f }); PdfPCell cell;// w ww . j a v a2s. c om Paragraph para; para = new Paragraph(""); para.setFont(bigPriceFont); if (price.length() >= 4) { para.add(price.substring(0, price.length() - 3)); } cell = new PdfPCell(para); cell.setRowspan(2); cell.setFixedHeight(57f); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); para = new Paragraph(""); para.setFont(smallPriceFont); if (price.length() >= 4) { para.add(price.substring(price.length() - 2, price.length())); } cell = new PdfPCell(para); cell.setRowspan(1); cell.setFixedHeight(35f); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setBorder(0); table.addCell(cell); para = new Paragraph(); para.setFont(unitFont); para.add(curr); cell = new PdfPCell(para); cell.setRowspan(1); cell.setFixedHeight(22f); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorder(0); table.addCell(cell); PdfPCell finalCell = new PdfPCell(table); finalCell.setBorder(0); /*if (isFirst) { finalCell.setBorder(Rectangle.RIGHT); }*/ return finalCell; }
From source file:pdf.PDFDesign.java
private PdfPCell createEuro_6_InnerInnerPrice(String price, String curr, boolean isFirst) throws DocumentException { PdfPTable table = new PdfPTable(2); table.setWidths(new float[] { 3f, 1.2f }); PdfPCell cell;/*from w w w.j a va2s.c om*/ Paragraph para; para = new Paragraph(""); para.setFont(new Font(droidsans, 60, Font.BOLD, color)); if (price.length() >= 4) { para.add(price.substring(0, price.length() - 3)); } cell = new PdfPCell(para); cell.setRowspan(2); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setLeading(50f, 0f); cell.setBorder(0); table.addCell(cell); para = new Paragraph(""); para.setFont(new Font(droidsans, 28, Font.NORMAL, color)); if (price.length() >= 4) { para.add(price.substring(price.length() - 2, price.length())); } cell = new PdfPCell(para); cell.setRowspan(1); cell.setFixedHeight(32f); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setBorder(0); table.addCell(cell); para = new Paragraph(); para.setFont(new Font(droidsans, 16, Font.NORMAL, color)); para.add(curr); cell = new PdfPCell(para); cell.setRowspan(1); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorder(0); table.addCell(cell); PdfPCell finalCell = new PdfPCell(table); finalCell.setBorder(0); /*if (isFirst) { finalCell.setBorder(Rectangle.RIGHT); }*/ return finalCell; }
From source file:PDF.PDFTrackGenerator.java
License:Open Source License
/** * Metda generateTrackPDFA4 sli na samotn vygenerovanie PDF dokumentu trasy na formt A4. * @param lineWeight - hrbka ?iary trasy na mape * @param color - farba ?iary trasy na mape * @param width - rka mapy//from w ww . ja v a2 s . c o m * @param height - vka mapy * @param scale - klovacia kontanta mapy (n x rozlenie mapy) * @param startDate - dtum a ?as prvho bodu trasy * @param endDate - dtum a ?as poslednho bodu trasy * @param activity - aktivita trasy * @param user - pouvate (majite) trasy */ public void generateTrackPDFA4(int lineWeight, String color, int width, int height, int scale, String startDate, String endDate, String activity, String user) { try { Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream(path + fileName + ".pdf")); doc.open(); Font nadpisFont = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD); Font detailyFont = new Font(Font.FontFamily.HELVETICA, 9, Font.NORMAL); Paragraph nadpisPar = new Paragraph(); nadpisPar.setAlignment(Element.ALIGN_CENTER); Phrase nadpis = new Phrase(fileName, nadpisFont); nadpisPar.add(nadpis); nadpisPar.add(""); doc.add(nadpisPar); doc.add(Chunk.NEWLINE); PdfPTable tabulka = new PdfPTable(2); tabulka.setWidthPercentage(100); float[] columnWidth = { 6f, 4f }; tabulka.setWidths(columnWidth); StaticMapResolver res = new StaticMapResolver(loader); String mapUrl = res.getStaticMapTrackURLWithMultimedia(lineWeight, color, width, height, scale); Image img = Image.getInstance(new URL(mapUrl)); //img.scalePercent(50); PdfPCell riadokSObr = new PdfPCell(img, true); riadokSObr.setBorder(Rectangle.NO_BORDER); riadokSObr.setPaddingBottom(10f); PdfPCell riadokSText = new PdfPCell(new Phrase("Description: " + loader.getTrackDescription() + "\n\n\nTrack activity: " + activity.substring(4) + "\n\n\nStart place: " + loader.getStartAddress() + "\n\n\nEnd Place: " + loader.getEndAddress() + "\n\n\nTrack length: " + loader.getLength() + " km\n\n\nMin elevation: " + loader.getMinElevation() + " m\n\n\nMax elevation: " + loader.getMaxElevation() + " m\n\n\nHeight difference: " + loader.getHeightDiff() + " m\n\n\nStart: " + startDate + "\n\n\nEnd: " + endDate + "\n\n\nDuration: " + loader.getDuration(), detailyFont)); riadokSText.setBorder(Rectangle.NO_BORDER); riadokSText.setPaddingLeft(20f); riadokSText.setPaddingTop(5f); riadokSText.setPaddingBottom(10f); tabulka.addCell(riadokSObr); tabulka.addCell(riadokSText); doc.add(tabulka); //doc.add(new Phrase("\n", detailyFont)); PdfPTable obrTabulka = new PdfPTable(3); obrTabulka.setWidthPercentage(100); ArrayList<String> goodFiles = new ArrayList<String>(); for (int i = 0; i < loader.getMultimediaFiles().size(); i++) { if (!loader.getMultimediaFiles().get(i).getPath().startsWith("YTB")) { String extension = loader.getMultimediaFiles().get(i).getPath().substring( loader.getMultimediaFiles().get(i).getPath().lastIndexOf("."), loader.getMultimediaFiles().get(i).getPath().length()); String newPath = loader.getMultimediaFiles().get(i).getPath().substring(0, loader.getMultimediaFiles().get(i).getPath().lastIndexOf(".")) + "_THUMB" + extension; goodFiles.add(newPath); } } if (!goodFiles.isEmpty()) { int freeCount = 9; if (goodFiles.size() <= 9) { for (int i = 0; i < goodFiles.size(); i++) { Image tempImg = Image.getInstance(goodFiles.get(i)); tempImg.scalePercent(10f); PdfPCell tempCell = new PdfPCell(tempImg, true); tempCell.setPadding(3f); //tempCell.setPaddingTop(5f); tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE); tempCell.setHorizontalAlignment(Element.ALIGN_CENTER); tempCell.setFixedHeight(130f); tempCell.setBackgroundColor(BaseColor.BLACK); tempCell.setBorderColor(BaseColor.WHITE); tempCell.setBorderWidth(4f); //tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); } for (int i = 0; i < 9 - goodFiles.size(); i++) { PdfPCell tempCell = new PdfPCell(); tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); } } else if (goodFiles.size() <= 18) { for (int i = 0; i < 9; i++) { Image tempImg = Image.getInstance(goodFiles.get(i)); tempImg.scalePercent(10f); PdfPCell tempCell = new PdfPCell(tempImg, true); tempCell.setPadding(3f); //tempCell.setPaddingTop(5f); tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE); tempCell.setHorizontalAlignment(Element.ALIGN_CENTER); tempCell.setFixedHeight(130f); tempCell.setBackgroundColor(BaseColor.BLACK); tempCell.setBorderColor(BaseColor.WHITE); tempCell.setBorderWidth(4f); //tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); } } else { for (int i = 0; i < (goodFiles.size() % 9); i++) { goodFiles.remove(goodFiles.size() - 1 - i); } int counting = (goodFiles.size() / 9); for (int i = 0; i < goodFiles.size(); i = i + counting) { Image tempImg = Image.getInstance(goodFiles.get(i)); tempImg.scalePercent(10f); PdfPCell tempCell = new PdfPCell(tempImg, true); tempCell.setPadding(3f); //tempCell.setPaddingTop(5f); tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE); tempCell.setHorizontalAlignment(Element.ALIGN_CENTER); tempCell.setFixedHeight(130f); tempCell.setBackgroundColor(BaseColor.BLACK); tempCell.setBorderColor(BaseColor.WHITE); tempCell.setBorderWidth(4f); //tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); freeCount--; } for (int i = 0; i < freeCount; i++) { PdfPCell tempCell = new PdfPCell(); tempCell.setBorder(Rectangle.NO_BORDER); obrTabulka.addCell(tempCell); } } } doc.add(obrTabulka); Font lastFont = new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC); Phrase lastText = new Phrase("This PDF document was generated by gTrax app for user " + user, lastFont); doc.add(lastText); doc.close(); } catch (Exception ex) { FileLogger.getInstance() .createNewLog("ERROR: Cannot CREATE PDF for track " + fileName + " for user " + user + " !!!"); System.out.println("pruser"); } }
From source file:PdfCreation.PdfTableWriter.java
public Section addTable(JTable table) { DefaultTableModel model = (DefaultTableModel) table.getModel(); Section ourTableSection = new Chapter(0) .addSection(this.newParagraph("Information Table", true, false, false)); ourTableSection.add(new Paragraph(" ")); PdfPTable ourTable = new PdfPTable(model.getColumnCount() + 1); int count = 1; ourTable.addCell(new Phrase(" ", FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD))); for (int i = 0; i < model.getColumnCount(); i++) { Phrase phrase = new Phrase(model.getColumnName(i).toString(), FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD)); ourTable.addCell(new PdfPCell(phrase)); }/*from www. ja va 2s. c o m*/ for (int i = 0; i < model.getRowCount(); i++) { ourTable.addCell(new Phrase("" + count++, FontFactory.getFont(FontFactory.HELVETICA, 8))); for (int j = 0; j < model.getColumnCount(); j++) { Phrase phrase = new Phrase(model.getValueAt(i, j).toString(), FontFactory.getFont(FontFactory.HELVETICA, 8)); ourTable.addCell(phrase); } } ourTableSection.add(ourTable); return ourTableSection; }
From source file:pipe.PdfMaker.java
/** * Private constructor, since this is a singleton. Fonts are initialized in * the constructor./*w ww . j a v a 2 s. c om*/ */ public PdfMaker() { arial = FontFactory.getFont("Arial", 8); arial.setStyle(Font.BOLD); arialSmall = FontFactory.getFont("Arial", 6); arialSmall.setStyle(Font.BOLD); courier = FontFactory.getFont("Courier", 10); arialMini = FontFactory.getFont("Arial", 5); }
From source file:pkg412project.ReportPDF.java
public static void main(String args[]) throws ClassNotFoundException, SQLException, DocumentException, FileNotFoundException { try {/* ww w .java2 s . co m*/ //Class.forName("oracle.jdbc.OracleDriver"); int rowno = 0; String url = "jdbc:oracle:thin:@acaddb2.asu.edu:1521:orcl"; String username = "sbmohan1"; String password = "sbmohan1"; Connection conn = DriverManager.getConnection(url, username, password); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery("SELECT * FROM SBMOHAN1.ORDERTABLE"); ResultSetMetaData rsmd = rs.getMetaData(); int colno = rsmd.getColumnCount(); while (rs.next()) { rowno++; } rs.first(); Document d = new Document(); PdfWriter.getInstance(d, new FileOutputStream("report.pdf")); Font font1 = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD); Font font2 = new Font(Font.FontFamily.TIMES_ROMAN, 27); Font font3 = new Font(Font.FontFamily.COURIER, 12, Font.BOLD); float[] columnWidths = { 4f, 4f, 16f, 16f, 4f, 4f, 4f, 4f }; PdfPTable ptable = new PdfPTable(colno); ptable.setWidths(columnWidths); d.open(); Paragraph title = new Paragraph("Order Report", font1); title.setAlignment(Element.ALIGN_CENTER); d.add(title); Paragraph date = new Paragraph("December 10th, 2015", font2); date.setAlignment(Element.ALIGN_CENTER); d.add(date); //d.add(new Paragraph("Order Report")); //d.add(new Paragraph("Date: December 10th, 2015")); d.add(Chunk.NEWLINE); //d.add(Chunk.NEWLINE); ptable.addCell(new Paragraph("OrderID", font3)); ptable.addCell(new Paragraph("NumItems", font3)); ptable.addCell(new Paragraph("ItemsOrdered", font3)); ptable.addCell(new Paragraph("OrderStatus", font3)); ptable.addCell(new Paragraph("TotalPrice", font3)); ptable.addCell(new Paragraph("PaymentID", font3)); ptable.addCell(new Paragraph("TableID", font3)); ptable.addCell(new Paragraph("ChefID", font3)); //insertCell(ptable, "OrderID", Element.ALIGN_LEFT, 1, bfBold12); for (int i = 0; i < rowno; i++) { ptable.addCell("" + rs.getString(1)); ptable.addCell("" + rs.getString(2)); ptable.addCell("" + rs.getString(3)); ptable.addCell("" + rs.getString(4)); ptable.addCell("" + rs.getString(5)); ptable.addCell("" + rs.getString(6)); ptable.addCell("" + rs.getString(7)); ptable.addCell("" + rs.getString(8)); rs.next(); } d.add(ptable); d.close(); } catch (SQLException ex) { System.out.println(ex.toString()); } }
From source file:pkgfinal.viewTable.java
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed try {//w ww. j av a 2s.com Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(" " + jComboBox1.getSelectedItem() + ".pdf")); document.open(); // Image image = Image.getInstance("save.png"); // document.add(new Paragraph("image")); // document.add(image); document.add(new Paragraph("ECHO TRADERS", FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD, BaseColor.RED))); document.add(new Paragraph(" " + jComboBox1.getSelectedItem() + " Report ", FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD, BaseColor.BLUE))); document.add(new Paragraph(new java.util.Date().toString())); document.add(new Paragraph("--------------------------------------------------------")); PdfPTable table = new PdfPTable(7); PdfPCell cell = new PdfPCell(new Paragraph("Purcahse_Sale Report")); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.GREEN); table.addCell(cell); String sql = "select * from '" + jComboBox1.getSelectedItem() + "' "; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { String v1 = rs.getString("ID"); String add = rs.getString("Date"); String v2 = rs.getString("BrandName"); String v3 = rs.getString("ManufactureName"); String v4 = rs.getString("PurchaseQuantity"); String v5 = rs.getString("SaleQuantity"); String v6 = rs.getString("TotalQuantity"); // table.addCell("ID"); table.addCell(v1); // table.addCell(v/*.date_tf.getDateFormatString()*/); table.addCell(add); // table.addCell("Brand name"); table.addCell(v2); // table.addCell("Manyfacture Name"); table.addCell(v3); // table.addCell("purchase Quantity"); table.addCell(v4); table.addCell(v5); table.addCell(v6); } document.add(table); com.itextpdf.text.List list = new com.itextpdf.text.List(true, 20); list.add("Printed Date:_____________"); list.add("Signature:_______________"); document.add(list); document.close(); JOptionPane.showMessageDialog(null, "Saved Report"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:presentation.frmReportForm.java
private void btnGenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateActionPerformed Date dateNow = new Date(); SimpleDateFormat df = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss"); System.out.println(dtcMonthChooser.getMonth()); System.out.println(dtcYearChooser.getYear()); if (radInMonth.isSelected()) { List<Transfer> transferList = new ArrayList<>(); transferList = empObj.searchRecordByMonth(dtcMonthChooser.getMonth() + 1, dtcYearChooser.getYear()); Document document = new Document(); try {/*from w w w. j ava 2 s. c om*/ Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); Paragraph slashPara = new Paragraph( "Transfer records at " + (dtcMonthChooser.getMonth() + 1) + "/" + dtcYearChooser.getYear(), FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } if (radInDateRange.isSelected()) { try { List<Transfer> transferList = new ArrayList<>(); java.sql.Date fromDateSql = formatDateForSearching(dtcFromDate.getDate()); java.sql.Date toDateSql = formatDateForSearching(dtcToDate.getDate()); transferList = empObj.searchRecordByDate(fromDateSql, toDateSql); Document document = new Document(); try { Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yyyy"); String fromDate = df2.format(dtcFromDate.getDate()); String toDate = df2.format(dtcToDate.getDate()); Paragraph slashPara = new Paragraph("Transfer records from " + fromDate + " to " + toDate, FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } catch (ParseException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } if (radInProject.isSelected()) { String fromProjectId = (String) cbxFromProject.getSelectedItem(); String toProjectId = (String) cbxToProject.getSelectedItem(); List<Transfer> transferList = new ArrayList<>(); String andOr = ""; if (cbxAndOr.getSelectedItem().equals("And")) { andOr = "and"; transferList = empObj.searchRecordByFromAndToProject(fromProjectId, toProjectId, andOr); } else { andOr = "or"; transferList = empObj.searchRecordByFromAndToProject(fromProjectId, toProjectId, andOr); } Document document = new Document(); try { Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); Paragraph slashPara = new Paragraph( "Transfer records from Project ID " + fromProjectId + " " + andOr + " " + toProjectId, FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } if (radAllRecord.isSelected()) { List<Transfer> transferList = new ArrayList<>(); transferList = empObj.searchAllRecord(); Document document = new Document(); try { Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); Paragraph slashPara = new Paragraph("All transfer records", FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:printers.HojaDeFirmaPrinter.java
License:Open Source License
private void creaCabecera(Document doc, Aula aula, GregorianCalendar dia) throws DocumentException { AcademicCalendar cal = dp.getAcademicCalendar(); Font font = new Font(Font.FontFamily.HELVETICA, 16); Font fontbold = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD); String diaSemana = cal.nombreDiaSemana(dia); Paragraph par = new Paragraph(); par.add(new Phrase("Hoja de firma para aula ", font)); par.add(new Phrase(aula.getNombre(), fontbold)); par.add(new Phrase(" correspondiente al da ", font)); par.add(new Phrase(diaSemana + " " + cal.format(dia), fontbold)); par.setAlignment(Paragraph.ALIGN_CENTER); doc.add(par);//from w w w . jav a 2 s . co m par.setAlignment(Paragraph.ALIGN_CENTER); }
From source file:printers.HojaDeFirmaPrinter.java
License:Open Source License
private void creaCuerpo(Document doc, GregorianCalendar dia, ArrayList<HorarioItem> data) { Collections.sort(data, new ComparatorHorarioItems()); PdfPTable t = new PdfPTable(3); t.setSpacingBefore(15f);//from www . j ava2s . c om t.setSpacingAfter(10f); t.setWidthPercentage(100); Font fontbold = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD); PdfPCell c = new PdfPCell(new Paragraph("Asignatura", fontbold)); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setPadding(5); t.addCell(c); c = new PdfPCell(new Paragraph("Firma", fontbold)); c.setPadding(5); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setPadding(5); t.addCell(c); c = new PdfPCell(new Paragraph("Incidencias", fontbold)); c.setPadding(5); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); t.addCell(c); for (HorarioItem h : data) { creaFilaFirma(t, h); } try { doc.add(t); } catch (DocumentException ex) { Logger.getLogger(HojaDeFirmaPrinter.class.getName()).log(Level.SEVERE, null, ex); } }