List of usage examples for com.itextpdf.text.pdf PdfPTable PdfPTable
public PdfPTable(final PdfPTable table)
PdfPTable
. From source file:com.thelinh.gui.UpdateChap.java
private void btnPdfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPdfActionPerformed Document document = new Document() { };// w ww .j av a 2s . c o m try { JFileChooser jfc = new JFileChooser("Save File"); if (jfc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { jfc.setDialogTitle("Save File"); FileOutputStream fos = new FileOutputStream(jfc.getSelectedFile()); PdfWriter.getInstance(document, fos); document.open(); Font rfont = FontFactory.getFont("C:\\Windows\\Fonts\\Calibri.ttf", IDENTITY_H, true); document.add(new Paragraph( " TRNG ?I HC B?CH KHOA H NI", rfont)); document.add(new Paragraph( " KT QU TM KIM C?C CHNG CA MN HC\n", rfont)); document.add(new Paragraph( " Tm kim theo m mn h?c : " + txtSearch.getText() + "\n\n", rfont)); TableModel tableModel = tbChap.getModel(); for (int i = 0; i < tableModel.getRowCount(); i++) { String subject = (String) tableModel.getValueAt(i, 0) + " : " + (String) tableModel.getValueAt(i, 1) + "\n\n"; String id = (String) tableModel.getValueAt(i, 0); String id1 = id; document.add(new Paragraph(subject, rfont)); PdfPTable table = new PdfPTable(2); PdfPCell header1 = new PdfPCell(new Paragraph("Chapter", rfont)); PdfPCell header2 = new PdfPCell(new Paragraph("ChapterName", rfont)); table.addCell(header1); table.addCell(header2); while (id.equals(id1) && i < tableModel.getRowCount()) { table.addCell( new PdfPCell(new Paragraph(String.valueOf(tableModel.getValueAt(i, 2)), rfont))); table.addCell(new PdfPCell(new Paragraph((String) tableModel.getValueAt(i, 3), rfont))); i++; if (i < tableModel.getRowCount()) id1 = (String) tableModel.getValueAt(i, 0); } document.add(table); document.add(new Paragraph("\n")); } document.add(new Paragraph( "\n Ha Noi, November 4th, 2016\n", rfont)); document.add(new Paragraph( " Teacher\n", rfont)); document.add(new Paragraph( " (Signed and Sealed)\n", rfont)); document.close(); JOptionPane.showMessageDialog(null, "Save success"); } } catch (FileNotFoundException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.thelinh.gui.UpdateQuestion.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed Document document = new Document() { };/* w w w . j av a 2s . c om*/ try { JFileChooser jfc = new JFileChooser("Save File"); if (jfc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { jfc.setDialogTitle("Save File"); FileOutputStream fos = new FileOutputStream(jfc.getSelectedFile()); PdfWriter.getInstance(document, fos); document.open(); Font rfont = FontFactory.getFont("C:\\Windows\\Fonts\\Calibri.ttf", IDENTITY_H, true); document.add(new Paragraph( " TRNG ?I HC B?CH KHOA H NI", rfont)); document.add(new Paragraph( "\t\t KT QU TM KIM CU HI\n", rfont)); switch (k) { case 1: document.add(new Paragraph( " Tm kim theo QuestionId : " + txtSearch.getText() + "\n\n", rfont)); break; case 2: document.add(new Paragraph(" Tm kim theo ni dung cu h?i : " + txtSearch.getText() + "\n\n", rfont)); break; case 3: document.add(new Paragraph( " Tm kim theo level : " + txtSearch.getText() + "\n\n", rfont)); break; case 4: document.add(new Paragraph( " Tm kim theo m mn h?c : " + txtSearch.getText() + "\n\n", rfont)); break; case 5: document.add(new Paragraph( " Tm kim theo cu tr l?i : " + txtSearch.getText() + "\n\n", rfont)); break; } TableModel tableModel = tbQuestion.getModel(); int question = 1; for (int i = 0; i < tableModel.getRowCount(); i++) { String id = (String) tableModel.getValueAt(i, 0); document.add(new Paragraph("\nCu " + question + " : ", rfont)); document.add(new Paragraph((String) tableModel.getValueAt(i, 1) + "\n\n", rfont)); PdfPTable table = new PdfPTable(3); PdfPCell header1 = new PdfPCell(new Paragraph("?p n s", rfont)); PdfPCell header2 = new PdfPCell(new Paragraph("Ni dung p n", rfont)); PdfPCell header3 = new PdfPCell(new Paragraph("?ng sai", rfont)); table.addCell(header1); table.addCell(header2); table.addCell(header3); String id1 = id; char answer = 'A'; while (id.equals(id1) && i < tableModel.getRowCount()) { table.addCell(new PdfPCell(new Paragraph("" + answer))); table.addCell(new PdfPCell(new Paragraph((String) tableModel.getValueAt(i, 6), rfont))); table.addCell( new PdfPCell(new Paragraph(String.valueOf(tableModel.getValueAt(i, 7)), rfont))); i++; if (i < tableModel.getRowCount()) id1 = (String) tableModel.getValueAt(i, 0); answer++; } document.add(table); question++; } document.add(new Paragraph( "\n Ha Noi, November 4th, 2016\n", rfont)); document.add(new Paragraph( " Teacher\n", rfont)); document.add(new Paragraph( " (Signed and Sealed)\n", rfont)); document.close(); JOptionPane.showMessageDialog(null, "Save success"); } } catch (FileNotFoundException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.thelinh.gui.UpdateSubject.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed Document document = new Document() { };//from ww w . j ava2s.co m try { JFileChooser jfc = new JFileChooser("Save File"); if (jfc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { jfc.setDialogTitle("Save File"); FileOutputStream fos = new FileOutputStream(jfc.getSelectedFile()); PdfWriter.getInstance(document, fos); document.open(); Font rfont = FontFactory.getFont("C:\\Windows\\Fonts\\Calibri.ttf", IDENTITY_H, true); document.add(new Paragraph( " TRNG ?I HC B?CH KHOA H NI", rfont)); document.add(new Paragraph( "\t\t KT QU TM KIM MN HC\n", rfont)); switch (k) { case 1: document.add(new Paragraph( " Tm kim theo m mn h?c : " + txtSearch.getText() + "\n\n", rfont)); break; case 2: document.add(new Paragraph( " Tm kim theo tn mn h?c : " + txtSearch.getText() + "\n\n", rfont)); break; } PdfPTable table = new PdfPTable(2); PdfPCell header1 = new PdfPCell(new Paragraph("SubjectId", rfont)); PdfPCell header2 = new PdfPCell(new Paragraph("SubjectName", rfont)); table.addCell(header1); table.addCell(header2); TableModel tableModel = tbSubject.getModel(); for (int i = 0; i < tableModel.getRowCount(); i++) { table.addCell(new PdfPCell(new Paragraph((String) tableModel.getValueAt(i, 0), rfont))); table.addCell(new PdfPCell(new Paragraph((String) tableModel.getValueAt(i, 1), rfont))); } document.add(table); document.add(new Paragraph( "\n Ha Noi, November 4th, 2016\n", rfont)); document.add(new Paragraph( " Teacher\n", rfont)); document.add(new Paragraph( " (Signed and Sealed)\n", rfont)); document.close(); JOptionPane.showMessageDialog(null, "Save success"); } } catch (FileNotFoundException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.thelinh.gui.UpdateUser.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed Document document = new Document() { };/*from w w w . j av a 2 s . co m*/ try { JFileChooser jfc = new JFileChooser("Save File"); if (jfc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { jfc.setDialogTitle("Save File"); FileOutputStream fos = new FileOutputStream(jfc.getSelectedFile()); PdfWriter.getInstance(document, fos); document.open(); Font rfont = FontFactory.getFont("C:\\Windows\\Fonts\\Calibri.ttf", IDENTITY_H, true); document.add(new Paragraph( " TRNG ?I HC B?CH KHOA H NI", rfont)); document.add(new Paragraph( "\t\t KT QU TM KIM NGI DNG\n", rfont)); switch (k) { case 1: document.add(new Paragraph( " Tm kim theo m ng?i dng : " + txtSearch.getText() + "\n\n", rfont)); break; case 2: document.add(new Paragraph( " Tm kim theo mt khu : " + txtSearch.getText() + "\n\n", rfont)); break; case 3: document.add(new Paragraph(" Tm kim theo tn ng?i dng : " + txtSearch.getText() + "\n\n", rfont)); break; case 4: document.add(new Paragraph( " Tm kim theo lp :" + txtSearch.getText() + "\n\n", rfont)); break; } PdfPTable table = new PdfPTable(5); PdfPCell header1 = new PdfPCell(new Paragraph("UserId", rfont)); PdfPCell header2 = new PdfPCell(new Paragraph("Password", rfont)); PdfPCell header3 = new PdfPCell(new Paragraph("UserName", rfont)); PdfPCell header4 = new PdfPCell(new Paragraph("BirthDay", rfont)); PdfPCell header5 = new PdfPCell(new Paragraph("Class", rfont)); table.addCell(header1); table.addCell(header2); table.addCell(header3); table.addCell(header4); table.addCell(header5); TableModel tableModel = tbUser.getModel(); for (int i = 0; i < tableModel.getRowCount(); i++) { table.addCell(new PdfPCell(new Paragraph((String) tableModel.getValueAt(i, 0), rfont))); table.addCell(new PdfPCell(new Paragraph((String) tableModel.getValueAt(i, 1), rfont))); table.addCell(new PdfPCell(new Paragraph((String) tableModel.getValueAt(i, 2), rfont))); SimpleDateFormat sdf = new SimpleDateFormat(); table.addCell(new PdfPCell(new Paragraph(sdf.format(tableModel.getValueAt(i, 3)), rfont))); table.addCell(new PdfPCell(new Paragraph((String) tableModel.getValueAt(i, 4), rfont))); } document.add(table); document.add(new Paragraph( "\n Ha Noi, November 4th, 2016\n", rfont)); document.add(new Paragraph( " Teacher\n", rfont)); document.add(new Paragraph( " (Signed and Sealed)\n", rfont)); document.close(); JOptionPane.showMessageDialog(null, "Save success"); } } catch (FileNotFoundException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.thomasmore.service.PdfCreateServiceImpl.java
public void readPdf() { try {//w ww. ja v a 2 s . c o m OutputStream file = new FileOutputStream(new File("D:\\SamplePDFje.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); document.add(new Paragraph("First iText PDF")); document.add(new Paragraph(new Date().toString())); document.addAuthor("Krishna Sfsfsfsn"); document.addCreationDate(); document.addCreator("JavaBeat"); document.addTitle("Sample PDF"); //Create Paragraph Paragraph paragraph = new Paragraph("Title 1", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); //New line paragraph.add(new Paragraph(" ")); paragraph.add("Test Paragraph"); paragraph.add(new Paragraph(" ")); document.add(paragraph); //Create a table in PDF PdfPTable pdfTable = new PdfPTable(3); PdfPCell cell1 = new PdfPCell(new Phrase("Table Header 1")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdfTable.addCell(cell1); cell1 = new PdfPCell(new Phrase("Table Header 2")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdfTable.addCell(cell1); cell1 = new PdfPCell(new Phrase("Table Header 3")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdfTable.addCell(cell1); pdfTable.setHeaderRows(1); pdfTable.addCell("Row 1 Col 1"); pdfTable.addCell("Row 1 Col 2"); pdfTable.addCell("Row 1 Col 3"); pdfTable.addCell("Row 2 Col 1"); pdfTable.addCell("Row 2 Col 2"); pdfTable.addCell("Row 2 Col 3"); document.add(pdfTable); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.timesheet.export.PdfGenerator.java
@Override protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer, HttpServletRequest request, HttpServletResponse response) throws Exception { /* Add header*/ Font fontHeader = FontFactory.getFont(FontFactory.TIMES_ROMAN, 22, Font.BOLD); Paragraph headerPara = new Paragraph("Time sheet report", fontHeader); headerPara.setSpacingAfter(20f);/*from w w w . j a v a 2s . c o m*/ document.add(headerPara); /*Add user info*/ User userProfile = (User) model.get("userprofile"); Font fontUserInfo = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD); document.add(new Paragraph("Name : " + userProfile.getName(), fontUserInfo)); document.add(new Paragraph("User no. : " + userProfile.getUserIdentifier(), fontUserInfo)); document.add(new Paragraph("Department : " + userProfile.getDepartment(), fontUserInfo)); document.add(new Paragraph("Email : " + userProfile.getEmail(), fontUserInfo)); Paragraph spacing = new Paragraph(""); spacing.setSpacingAfter(20f); document.add(spacing); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100.0f); table.setWidths(new float[] { 5.0f, 3.0f, 3.0f, 3.0f, 10.0f }); table.setSpacingBefore(10); // define font for table header row Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD); //font.setColor(BaseColor.WHITE); // define table header cell PdfPCell cell = new PdfPCell(); //cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPadding(5); cell.setBorderWidth(2.0f); cell.setBorder(Rectangle.BOTTOM); // get data model which is passed by the Spring container List<Booking> bookings = (List<Booking>) model.get("bookings"); // write table header cell.setPhrase(new Phrase("Project", font)); table.addCell(cell); // write table header cell.setPhrase(new Phrase("Option", font)); table.addCell(cell); // write table header cell.setPhrase(new Phrase("Date", font)); table.addCell(cell); // write table header cell.setPhrase(new Phrase("Duration", font)); table.addCell(cell); // write table header cell.setPhrase(new Phrase("Description", font)); table.addCell(cell); int sum = 0; Font fontData = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11); for (Booking booking : bookings) { PdfPCell cell1 = new PdfPCell(new Phrase( booking.getProject().getProjectId() + "-" + booking.getProject().getName(), fontData)); cell1.setBorder(Rectangle.BOTTOM); cell1.setPadding(5); table.addCell(cell1); PdfPCell cell2 = new PdfPCell(new Phrase(booking.getBookingOption().getOptionLabel(), fontData)); cell2.setBorder(Rectangle.BOTTOM); cell2.setPadding(5); table.addCell(cell2); PdfPCell cell3 = new PdfPCell(new Phrase(formatDate(booking.getBookingDate()), fontData)); cell3.setBorder(Rectangle.BOTTOM); cell3.setPadding(5); table.addCell(cell3); int hh = booking.getDuration() / 60; int mm = booking.getDuration() % 60; PdfPCell cell4 = new PdfPCell(new Phrase(hh + ":" + mm, fontData)); cell4.setBorder(Rectangle.BOTTOM); cell4.setPadding(5); table.addCell(cell4); PdfPCell cell5 = new PdfPCell( new Phrase(StringEscapeUtils.escapeHtml(booking.getDescription()), fontData)); cell5.setBorder(Rectangle.BOTTOM); cell5.setPadding(5); table.addCell(cell5); sum += booking.getDuration(); } document.add(table); int sumHH = sum / 60; int sumMM = sum % 60; document.add(new Paragraph("Sum : " + sumHH + ":" + sumMM, fontUserInfo)); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
From source file:com.tomasz.drag.triballocommanderro.controller.MakerPDF.java
public static void printToPDFBoss(ArrayList<Person> workers, EventGig event) throws IOException, DocumentException { String filename = event.getName() + " Boss" + ".pdf"; String path = event.getData() + " " + event.getName() + "//"; //Rectangle rect = new Rectangle(0, 595, 8, 0); Document document = new Document(PageSize.A4.rotate(), 0, 0, 0, 0); //Document document = new Document(rect); //document.setMargins(0, 0, 0, 0); BaseFont bf;//from w w w. j ava 2 s .com //BaseFont bf2; // bf = BaseFont.createFont("arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); bf = BaseFont.createFont("src\\main\\resources\\font\\arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); //bf2 = BaseFont.createFont("src\\main\\resources\\font\\arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); com.itextpdf.text.Font ft = new com.itextpdf.text.Font(bf, 9); //com.itextpdf.text.Font ft2 = new com.itextpdf.text.Font(bf2,9); PdfWriter.getInstance(document, new FileOutputStream(path + filename)); document.open(); Paragraph p = new Paragraph(event.getName() + " " + event.getData(), ft); p.setAlignment(Element.ALIGN_CENTER); document.add(p); document.add(new Paragraph(" ")); PdfPTable table = new PdfPTable(workers.size() + 1); table.setWidthPercentage(98); PdfPCell cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); for (Person tempPerson : workers) { cell = new PdfPCell(new Paragraph(tempPerson.getName(), ft)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } if (event.isZaladunekScenaDach()) { cell = new PdfPCell(new Paragraph("Za. Sc./Dach", ft)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getZaladunekScenaDachWyplata() > 0) { cell = new PdfPCell( new Paragraph(String.format("%.2f", tempPerson.getZaladunekScenaDachWyplata()), ft)); cell.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isZaladunekTechniki()) { cell = new PdfPCell(new Phrase("Za. Tech.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getZaladunekTechnikiWyplata() > 0) { cell = new PdfPCell( new Paragraph(String.format("%.2f", tempPerson.getZaladunekTechnikiWyplata()), ft)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRozladunekScenaDach()) { cell = new PdfPCell(new Phrase("Roz Sc/Dach", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRozladunekScenaDachWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRozladunekScenaDachWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRozladunekTechniki()) { cell = new PdfPCell(new Phrase("Roz. Tech.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRozladunekTechnikiWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRozladunekTechnikiWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazDachu()) { cell = new PdfPCell(new Phrase("Mon. Dach", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazDachuWyplata() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getMontazDachuWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazDzwieku()) { cell = new PdfPCell(new Phrase("Mon. Dw.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazDzwiekuWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getMontazDzwiekuWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazSceny()) { cell = new PdfPCell(new Phrase("Mon. Sc.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazScenyWyplata() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getMontazScenyWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazSwiatla()) { cell = new PdfPCell(new Phrase("Mon. w.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazSwiatlaWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getMontazSwiatlaWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazTechniki()) { cell = new PdfPCell(new Phrase("Mon. Tech.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazTechnikiWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getMontazTechnikiWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazDachu()) { cell = new PdfPCell(new Phrase("Dem. Dach", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazDachuWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazDachuWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazDzwieku()) { cell = new PdfPCell(new Phrase("Dem. Dw.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazDzwiekuWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazDzwiekuWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazSceny()) { cell = new PdfPCell(new Phrase("Dem. Sc.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazScenyWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazScenyWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazSwiatla()) { cell = new PdfPCell(new Phrase("Dem. w.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazSwiatlaWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazSwiatlaWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazTechniki()) { cell = new PdfPCell(new Phrase("Dem. Tech.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazTechnikiWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazTechnikiWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDyzur()) { cell = new PdfPCell(new Phrase("Dyur", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDyzurWyplata() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getDyzurWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase("")); table.addCell(cell); } } } if (event.isTechnikSceny()) { cell = new PdfPCell(new Phrase("Technik Sc.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getTechnikScenyWyplata() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getTechnikScenyWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRealizacjaFOH()) { cell = new PdfPCell(new Phrase("Real. FOH", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRealizacjaFOHWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRealizacjaFOHWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRealizacjaMON()) { cell = new PdfPCell(new Phrase("Real. MON", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRealizacjaMONWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRealizacjaMONWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRealizacjaSwiatla()) { cell = new PdfPCell(new Phrase("Real. w.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRealizacjaSwiatlaWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (true) { cell = new PdfPCell(new Phrase("Premia", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getPremia() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getPremia()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } Paragraph ph = new Paragraph("Razem", ft); //cell = new PdfPCell(new Phrase(ph)); cell.addElement(ph); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getSumaWyplata() >= 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getSumaWyplata()) + " z", ft)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } // for (Object obj : table.getChunks()) { // if (obj instanceof PdfPCell) { // System.out.println("jest PdfCell"); // PdfPCell tempCell = (PdfPCell) obj; // tempCell.setVerticalAlignment(Element.ALIGN_CENTER); // //tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // } // // } table.setHorizontalAlignment(Element.ALIGN_CENTER); document.add(table); document.close(); }
From source file:com.tomasz.drag.triballocommanderro.controller.MakerPDF.java
public static PdfPTable createTable(Person person, EventGig event) throws DocumentException, IOException { int a = 0;/*from w ww . ja v a 2s. co m*/ if (person.getZaladunekScenaDachWyplata() > 0) { a++; } if (person.getZaladunekTechnikiWyplata() > 0) { a++; } if (person.getMontazDachuWyplata() > 0) { a++; } if (person.getMontazDzwiekuWyplata() > 0) { a++; } if (person.getMontazScenyWyplata() > 0) { a++; } if (person.getMontazSwiatlaWyplata() > 0) { a++; } if (person.getMontazTechnikiWyplata() > 0) { a++; } if (person.getDemontazDachuWyplata() > 0) { a++; } if (person.getDemontazDzwiekuWyplata() > 0) { a++; } if (person.getDemontazScenyWyplata() > 0) { a++; } if (person.getDemontazSwiatlaWyplata() > 0) { a++; } if (person.getDemontazTechnikiWyplata() > 0) { a++; } if (person.getRozladunekScenaDachWyplata() > 0) { a++; } if (person.getRozladunekTechnikiWyplata() > 0) { a++; } if (person.getDyzurWyplata() > 0) { a++; } if (person.getTechnikScenyWyplata() > 0) { a++; } if (person.getRealizacjaFOHWyplata() > 0) { a++; } if (person.getRealizacjaMONWyplata() > 0) { a++; } if (person.getRealizacjaSwiatlaWyplata() > 0) { a++; } if (person.getPremia() > 0) { a++; } System.out.println(a); BaseFont bf; bf = BaseFont.createFont("src\\main\\resources\\font\\arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // bf = BaseFont.createFont("arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); com.itextpdf.text.Font ft = new com.itextpdf.text.Font(bf); PdfPTable table = new PdfPTable(2); table.setTotalWidth(new float[] { 90, 190 }); table.setLockedWidth(true); PdfPCell cell; cell = new PdfPCell(new Phrase(person.getName() + " " + person.getSurName(), ft)); cell.setColspan(1); table.addCell(cell); cell = new PdfPCell(new Phrase(event.getName() + " " + event.getData(), ft)); cell.setColspan(2); table.addCell(cell); cell = new PdfPCell(new Phrase("")); cell.setRowspan(a); table.addCell(cell); if (person.getZaladunekScenaDachWyplata() > 0) { table.addCell(new Phrase("Zaadunek Scena/Dach", ft)); } if (person.getZaladunekTechnikiWyplata() > 0) { table.addCell(new Phrase("Zaadunek Techniki", ft)); } if (person.getMontazDachuWyplata() > 0) { table.addCell(new Phrase("Monta Dachu", ft)); } if (person.getMontazDzwiekuWyplata() > 0) { table.addCell(new Phrase("Monta Dwieku", ft)); } if (person.getMontazScenyWyplata() > 0) { table.addCell(new Phrase("Monta Sceny", ft)); } if (person.getMontazSwiatlaWyplata() > 0) { table.addCell(new Phrase("Monta wiata", ft)); } if (person.getMontazTechnikiWyplata() > 0) { table.addCell(new Phrase("Monta Techniki", ft)); } if (person.getDemontazDachuWyplata() > 0) { table.addCell(new Phrase("Demonta Dachu", ft)); } if (person.getDemontazDzwiekuWyplata() > 0) { table.addCell(new Phrase("Demonta Dwieku", ft)); } if (person.getDemontazScenyWyplata() > 0) { table.addCell(new Phrase("Demonta Sceny", ft)); } if (person.getDemontazSwiatlaWyplata() > 0) { table.addCell(new Phrase("Demonta wiata", ft)); } if (person.getDemontazTechnikiWyplata() > 0) { table.addCell(new Phrase("Demonta Techniki", ft)); } if (person.getRozladunekScenaDachWyplata() > 0) { table.addCell(new Phrase("Rozadunek Scena/Dach", ft)); } if (person.getRozladunekTechnikiWyplata() > 0) { table.addCell(new Phrase("Rozadunek Techniki", ft)); } if (person.getDyzurWyplata() > 0) { table.addCell(new Phrase("Dyur", ft)); } if (person.getTechnikScenyWyplata() > 0) { table.addCell(new Phrase("Technik Sceny", ft)); } if (person.getRealizacjaFOHWyplata() > 0) { table.addCell(new Phrase("Realizacja FOH", ft)); } if (person.getRealizacjaMONWyplata() > 0) { table.addCell(new Phrase("Realizacja MON", ft)); } if (person.getRealizacjaSwiatlaWyplata() > 0) { table.addCell(new Phrase("Realizacja wiata", ft)); } if (person.getPremia() > 0) { table.addCell(new Phrase("Premia", ft)); } cell = new PdfPCell(new Phrase("Suma: ")); cell.setColspan(1); table.addCell(cell); //cell = new PdfPCell(new Phrase(Double.toString(person.getSumaWyplata())));//String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata()) cell = new PdfPCell(new Phrase(String.format("%.2f", person.getSumaWyplata()) + " z", ft));//String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata()) table.addCell(cell); cell = new PdfPCell(new Phrase(" ")); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); //cell = new PdfPCell(new Phrase(Double.toString(person.getSumaWyplata())));//String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata()) cell = new PdfPCell(new Phrase(" "));//String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata()) cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); table.setBreakPoints(2 + a); return table; }
From source file:com.udec.utilidades.PdfTable.java
public PdfPTable tabla2(List<Nomina> no) throws DocumentException { //Instanciamos una tabla de 3 columnas PdfPTable tabla = new PdfPTable(4); tabla.setWidthPercentage(100);//from w w w .j av a 2 s . c o m tabla.setWidths(new float[] { 1, 1, 1, 3 }); //Declaramos un objeto para manejar las celdas PdfPCell celda; celda = new PdfPCell(new Phrase("Codigo:")); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase("" + no.get(0).getEmpleadoCodigo().getCodigo())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Nombre:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase(no.get(0).getEmpleadoCodigo().getNombre())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Cedula:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase(no.get(0).getEmpleadoCodigo().getCedula())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Cargo:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase(no.get(0).getEmpleadoCodigo().getCargoCargoid().getCargo())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Dias Lab:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { dt = dtC.findBySingle2("periodoIdperiodo", no.get(0).getPeriodoIdperiodo(), "empleadoCodigo", no.get(0).getEmpleadoCodigo()); celda = new PdfPCell(new Phrase("" + dt.getDias())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Sueldo:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase("" + no.get(0).getEmpleadoCodigo().getSalario())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } return tabla; }
From source file:com.udec.utilidades.PdfTable.java
public PdfPTable firma() throws DocumentException { PdfPTable tabla = new PdfPTable(3); tabla.setWidthPercentage(100);// w w w . j ava 2s.com tabla.setWidths(new float[] { 2, 1, 2 }); //Declaramos un objeto para manejar las celdas PdfPCell celda; celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.BOTTOM); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.BOTTOM); tabla.addCell(celda); celda = new PdfPCell(new Phrase("JEFE ADMINISTRATIVO")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("EMPLEADO")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); return tabla; }