List of usage examples for com.itextpdf.text.pdf PdfPTable setWidthPercentage
public void setWidthPercentage(final float widthPercentage)
From source file:pipe.PdfMaker.java
private Element tenthElement(String verkaufspreis, String verkauft_an, String datum) { float leading = 9f; PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f); PdfPCell cell;/*w ww . ja va 2 s. co m*/ //Hier die Header zuerst cell = new PdfPCell(new Paragraph("Verkaufspreis", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Verkauft an", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Verkaufsdatum", 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(verkaufspreis, courier); herkunftInfo.setLeading(leading); cell.addElement(herkunftInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph editionInfo = new Paragraph(verkauft_an, courier); editionInfo.setLeading(leading); cell.addElement(editionInfo); table.addCell(cell); cell = new PdfPCell(); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph yearInfo = new Paragraph(datum, courier); yearInfo.setLeading(leading); cell.addElement(yearInfo); table.addCell(cell); return table; }
From source file:pipe.PdfMaker.java
private Element eleventhElement(String oberflaeche, String bohrung, String filter) { float leading = 9f; PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f); PdfPCell cell;/* w w w. jav a 2s. co m*/ //Hier die Header zuerst cell = new PdfPCell(new Paragraph("Oberflche", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Bohrung", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Filter", 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(oberflaeche, courier); herkunftInfo.setLeading(leading); cell.addElement(herkunftInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph editionInfo = new Paragraph(bohrung, courier); editionInfo.setLeading(leading); cell.addElement(editionInfo); table.addCell(cell); cell = new PdfPCell(); cell.setBorderWidth(0.3f); cell.setFixedHeight(18f); Paragraph yearInfo = new Paragraph(filter, courier); yearInfo.setLeading(leading); cell.addElement(yearInfo); table.addCell(cell); return table; }
From source file:pipe.PdfMaker.java
private Element twelvethElement(String laenge, String kopfhoehe, String kopfdurchmesser) { float leading = 9f; PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f); PdfPCell cell;//from w w w . ja va2 s . c o m //Hier die Header zuerst cell = new PdfPCell(new Paragraph("Lnge", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Kopfhhe", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Kopfdurchmesser", 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(laenge, courier); herkunftInfo.setLeading(leading); cell.addElement(herkunftInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph editionInfo = new Paragraph(kopfhoehe, courier); editionInfo.setLeading(leading); cell.addElement(editionInfo); table.addCell(cell); cell = new PdfPCell(); cell.setBorderWidth(0.3f); cell.setFixedHeight(18f); Paragraph yearInfo = new Paragraph(kopfdurchmesser, courier); yearInfo.setLeading(leading); cell.addElement(yearInfo); table.addCell(cell); return table; }
From source file:pipe.PdfMaker.java
private Element thirteenthElement(String gewicht, String farbe) { float leading = 9f; PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f); PdfPCell cell;/*from w ww . ja v a2s. c o m*/ cell = new PdfPCell(new Paragraph("Gewicht", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Farbe", 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(18f); Paragraph mundMatInfo = new Paragraph(gewicht, courier); mundMatInfo.setLeading(leading); cell.addElement(mundMatInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(18f); Paragraph modellInfo = new Paragraph(farbe, courier); modellInfo.setLeading(leading); cell.addElement(modellInfo); table.addCell(cell); return table; }
From source file:pipe.PdfMaker.java
private Element fourteenthElement(String zustand, String lagerort) { float leading = 9f; PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f); PdfPCell cell;/* www . j a v a 2 s .c o m*/ cell = new PdfPCell(new Paragraph("Zustand", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Lagerort", 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(18f); Paragraph mundMatInfo = new Paragraph(zustand, courier); mundMatInfo.setLeading(leading); cell.addElement(mundMatInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(18f); Paragraph modellInfo = new Paragraph(lagerort, courier); modellInfo.setLeading(leading); cell.addElement(modellInfo); table.addCell(cell); return table; }
From source file:pipe.PdfMaker.java
private Element fifteenthElement(String besonderes) { float leading = 9f; PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100f); PdfPCell cell;/*from ww w . ja va 2 s . c o m*/ cell = new PdfPCell(new Paragraph("Besonderes", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph herstellerInfo = new Paragraph(besonderes, courier); herstellerInfo.setLeading(leading); cell.addElement(herstellerInfo); table.addCell(cell); return table; }
From source file:platnosci.WyszukPlatnosciController.java
public void akcjaDrukuj() { Drukowanie drukPanel = new Drukowanie(null, true); drukPanel.setLocationRelativeTo(null); drukPanel.setVisible(true);//from w w w . j a va 2 s. co m if (!drukPanel.isDruk()) { return; } FileOutputStream file = null; File druk = null; try { Document document = new Document(); String userPath = System.getProperty("user.home"); druk = new File(userPath + "/Baks wydruki"); if (!druk.exists()) { druk.mkdirs(); } SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); String strdate = ""; Date calendardate = new Date(); strdate = sdf.format(calendardate.getTime()); File wydruk = new File(druk + "/Platnosci - " + strdate + ".pdf"); if (!wydruk.exists()) { try { wydruk.createNewFile(); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } file = new FileOutputStream(wydruk); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(wydruk)); document.open(); PdfPTable table = new PdfPTable(4); // 3 columns. table.setWidthPercentage(100); //Width 100% table.setSpacingBefore(10f); //Space before table table.setSpacingAfter(10f); //Space after table //Set Column widths float[] columnWidths = { 1f, 1f, 1f, 1f }; table.setWidths(columnWidths); BaseFont bf = BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); PdfPCell cell1 = new PdfPCell(new Paragraph("Lp", new com.itextpdf.text.Font(bf, 16))); cell1.setPaddingLeft(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setVerticalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(new Paragraph("Firma", new com.itextpdf.text.Font(bf, 16))); cell2.setPaddingLeft(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_LEFT); PdfPCell cell3 = new PdfPCell( new Paragraph("Data patnoci", new com.itextpdf.text.Font(bf, 16))); cell3.setPaddingLeft(10); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setVerticalAlignment(Element.ALIGN_LEFT); PdfPCell cell4 = new PdfPCell(new Paragraph("Kwota", new com.itextpdf.text.Font(bf, 16))); cell4.setPaddingLeft(10); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setVerticalAlignment(Element.ALIGN_LEFT); //To avoid having the cell border and the content overlap, if you are having thick cell borders cell1.setBorder(PdfPCell.NO_BORDER); cell2.setBorder(PdfPCell.NO_BORDER); cell3.setBorder(PdfPCell.NO_BORDER); cell4.setBorder(PdfPCell.NO_BORDER); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); TO_Invoice kryt = new TO_Invoice(); kryt.setDataDo(drukPanel.getDateDo()); kryt.setDataOd(drukPanel.getDateOd()); kryt.setStatus(TO_InvoiceStatus.ZAPLACONA); List<TO_Invoice> listaFaktur = getDaoFactory().getDaoInvoice().getListaInvoiceDruk(getConnection(), kryt); Integer i = 1; for (TO_Invoice item : listaFaktur) { table.addCell(getNewCell(i.toString() + ".")); table.addCell(getNewCell(item.getPaymentCompany().getName())); table.addCell(getNewCell(item.getDataZaplacenia().toString())); table.addCell(getNewCell(TO_Invoice.getWynikSumaKoszt(item.getKoszt()) + " z")); i++; } document.add(table); document.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); } } catch (FileNotFoundException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); BaksSessionBean.getInstance().fireMessage(widok, "Wydruk", "Pdf do ktrego chcesz zapisa wynik jest otwarty!\n Zamknij i sprbuj jeszcze raz."); } finally { try { file.close(); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); try { desktop.open(druk); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } BaksSessionBean.getInstance().fireMessage(widok, "Zapis", "Wydruk zapisany w folderze: " + System.getProperty("user.home") + "/Baks wydruki"); }
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 ww 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:Print.Print.java
public void printIndex(ArrayList<String> imagesPath, String customer) { try {/*from www .j a va2 s . c o m*/ //ArrayList<Image> images = new ArrayList<Image>(); Map<Image, String> dict = new HashMap<Image, String>(); for (String path : imagesPath) { try { System.out.println("path = /home/student" + path); int index = path.lastIndexOf("/"); String photoId = path.substring(index + 1, path.length()); Image newImage = Image.getInstance("/home/student" + path); //images.add(newImage); dict.put(newImage, photoId); } catch (BadElementException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } } System.out.println("Total images = " + dict.size()); Document index = new Document(PageSize.A4.rotate()); FileOutputStream fos = new FileOutputStream("/home/student/Pictures/index.pdf"); PdfWriter writer = PdfWriter.getInstance(index, fos); writer.open(); index.open(); PdfPTable adresTable = new PdfPTable(3); PdfPCell adresCell = new PdfPCell(new Paragraph(customer)); adresCell.setColspan(3); adresTable.addCell(adresCell); adresTable.setHorizontalAlignment(Element.ALIGN_CENTER); adresTable.setWidthPercentage(100); index.add(adresTable); PdfPTable table = new PdfPTable(imagesPath.size()); for (Map.Entry<Image, String> image : dict.entrySet()) { PdfPCell cell = new PdfPCell(); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(10); table.addCell(image.getValue()); cell.addElement(image.getKey()); table.addCell(cell); } index.add(table); //index.add(adresTable); index.close(); writer.close(); System.out.println("Index printed"); // // define pdfprinter and within try clause create // PdfWriter writer = null; // FileOutputStream fos = null; // Document index = new Document(PageSize.A4.rotate()); // File file; // try { // file = new File("/home/student/Pictures/index.pdf"); // if(!file.exists()){ // file.createNewFile(); // // } // String test = "test data"; // fos = new FileOutputStream(file); // fos.write(test.getBytes()); // fos.flush(); // } catch (FileNotFoundException ex) { // Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); // } catch (IOException ex) { // Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); // } // // for (BufferedImage image : bufferedImages) { // try { // writer = PdfWriter.getInstance(index, fos); // } catch (DocumentException ex) { // System.out.println(ex.getMessage()); // } // writer.open(); // index.open(); // try { // PdfContentByte pdfCB = new PdfContentByte(writer); // Image newImage = Image.getInstance(pdfCB, image, 1); // index.add(Image.getInstance(newImage)); // } catch (DocumentException ex) { // System.out.println(ex.getMessage()); // } catch (IOException ex) { // Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); // } // } // index.close(); // writer.close(); // System.out.println("Index done."); } catch (DocumentException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } }
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 w w w .jav a2s. 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); } }