List of usage examples for com.itextpdf.text.pdf PdfPCell setPhrase
public void setPhrase(Phrase phrase)
Phrase
for this cell. From source file:com.sapito.pdf.PDFView.PDFGeneratorDireccion.java
public void reportecompras(Map<String, Object> model, HttpServletResponse hsr1, List<OrdenCompra> ordenCompra) throws Exception { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open();//from w w w. ja v a 2 s.co m document.addTitle("Sapito PDFs"); document.addSubject("Pdf de sapito"); Font font1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 30); font1.setColor(BaseColor.BLACK); Font font2 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 24); font2.setColor(BaseColor.BLACK); document.add(new Paragraph("TAILS 2015", font1)); document.add(new Paragraph("Reportes Direccin\n", font2)); //------------------------ TAIS ______________________________ Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg")); document.add(tais); //--------------------- BODY --------------------------------------------------------- Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png")); body.setAlignment(Image.UNDERLYING); body.setTransparency(new int[] { 0x00, 0x10 }); body.setAbsolutePosition(50, 250); document.add(body); //------------------------------------------------------------------------------------------- Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg")); footer.setAbsolutePosition(50, 20); document.add(footer); //---------------------- TITLE --------------------------- String titulo = "Reporte de Compras"; //Cambiar el titulo del PDF aqui Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK); Chunk c = new Chunk(titulo + " \n ", f); c.setBackground(BaseColor.WHITE); Paragraph title = new Paragraph(c); title.setAlignment(Element.ALIGN_CENTER); //------------------------- CONTENIDO ------------------------------------------------------- document.add(title); //Titulo del PDF TextoPdf x = (TextoPdf) model.get("todoTexto"); document.add(new Paragraph(x.getTodoTexto())); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100.0f); table.setWidths(new float[] { 2.0f }); table.setSpacingBefore(10); // define font for table header row Font font = FontFactory.getFont(FontFactory.COURIER_BOLD); font.setColor(BaseColor.WHITE); // define table header cell PdfPCell cell = new PdfPCell(); cell.setBackgroundColor(BaseColor.BLUE); cell.setPadding(5); // write table header cell.setPhrase(new Phrase("Total de Compras en el dia", font)); table.addCell(cell); for (int i = 0; i < ordenCompra.size(); i++) { a = ordenCompra.get(i).getCostoTotal(); b = a + b; } String bla = b + " "; table.addCell(bla); document.add(table); //-------------------------- FIN CONTENIDO ----------------- document.close(); byte[] bytes = baos.toByteArray(); hsr1.setContentType("application/pdf"); hsr1.setContentLength(bytes.length); hsr1.getOutputStream().write(bytes); }
From source file:com.sapito.pdf.PDFView.PDFGeneratorDireccion.java
public void reporteinventario(Map<String, Object> model, HttpServletResponse hsr1, List<Inventario> inventario) throws Exception { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open();// ww w .j av a 2 s.c o m document.addTitle("Sapito PDFs"); document.addSubject("Pdf de sapito"); Font font1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 30); font1.setColor(BaseColor.BLACK); Font font2 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 24); font2.setColor(BaseColor.BLACK); document.add(new Paragraph("TAILS 2015", font1)); document.add(new Paragraph("Reportes Direccin\n", font2)); //------------------------ TAIS ______________________________ Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg")); document.add(tais); //--------------------- BODY --------------------------------------------------------- Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png")); body.setAlignment(Image.UNDERLYING); body.setTransparency(new int[] { 0x00, 0x10 }); body.setAbsolutePosition(50, 250); document.add(body); //------------------------------------------------------------------------------------------- Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg")); footer.setAbsolutePosition(50, 20); document.add(footer); //---------------------- TITLE --------------------------- String titulo = "Reporte de Inventarios"; //Cambiar el titulo del PDF aqui Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK); Chunk c = new Chunk(titulo + " \n ", f); c.setBackground(BaseColor.WHITE); Paragraph title = new Paragraph(c); title.setAlignment(Element.ALIGN_CENTER); //------------------------- CONTENIDO ------------------------------------------------------- document.add(title); //Titulo del PDF TextoPdf x = (TextoPdf) model.get("todoTexto"); document.add(new Paragraph(x.getTodoTexto())); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100.0f); table.setWidths(new float[] { 2.0f }); table.setSpacingBefore(10); // define font for table header row Font font = FontFactory.getFont(FontFactory.COURIER_BOLD); font.setColor(BaseColor.WHITE); // define table header cell PdfPCell cell = new PdfPCell(); cell.setBackgroundColor(BaseColor.BLUE); cell.setPadding(5); // write table header cell.setPhrase(new Phrase("Total de Inventarios", font)); table.addCell(cell); for (int i = 0; i < inventario.size(); i++) { a = inventario.get(i).getPrecioUnitario(); b = a + b; } String bla = b + " "; table.addCell(bla); document.add(table); //-------------------------- FIN CONTENIDO ----------------- document.close(); byte[] bytes = baos.toByteArray(); hsr1.setContentType("application/pdf"); hsr1.setContentLength(bytes.length); hsr1.getOutputStream().write(bytes); }
From source file:com.sapito.pdf.PDFView.PDFGeneratorDireccion.java
public void reporteRH(Map<String, Object> model, HttpServletResponse hsr1, int detalle) throws Exception { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open();// www . j a v a2 s. c o m document.addTitle("Sapito PDFs"); document.addSubject("Pdf de sapito"); Font font1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 30); font1.setColor(BaseColor.BLACK); Font font2 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 24); font2.setColor(BaseColor.BLACK); document.add(new Paragraph("TAILS 2015", font1)); document.add(new Paragraph("Reportes Direccin\n", font2)); //------------------------ TAIS ______________________________ Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg")); document.add(tais); //--------------------- BODY --------------------------------------------------------- Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png")); body.setAlignment(Image.UNDERLYING); body.setTransparency(new int[] { 0x00, 0x10 }); body.setAbsolutePosition(50, 250); document.add(body); //------------------------------------------------------------------------------------------- Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg")); footer.setAbsolutePosition(50, 20); document.add(footer); //---------------------- TITLE --------------------------- String titulo = "Reporte de Recursos Humanos"; //Cambiar el titulo del PDF aqui Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK); Chunk c = new Chunk(titulo + " \n ", f); c.setBackground(BaseColor.WHITE); Paragraph title = new Paragraph(c); title.setAlignment(Element.ALIGN_CENTER); //------------------------- CONTENIDO ------------------------------------------------------- document.add(title); //Titulo del PDF TextoPdf x = (TextoPdf) model.get("todoTexto"); document.add(new Paragraph(x.getTodoTexto())); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100.0f); table.setWidths(new float[] { 2.0f }); table.setSpacingBefore(10); // define font for table header row Font font = FontFactory.getFont(FontFactory.COURIER_BOLD); font.setColor(BaseColor.WHITE); // define table header cell PdfPCell cell = new PdfPCell(); cell.setBackgroundColor(BaseColor.BLUE); cell.setPadding(5); // write table header cell.setPhrase(new Phrase("Total de de Empleados en Vacaciones", font)); table.addCell(cell); String bla = detalle + " "; table.addCell(bla); document.add(table); //-------------------------- FIN CONTENIDO ----------------- document.close(); byte[] bytes = baos.toByteArray(); hsr1.setContentType("application/pdf"); hsr1.setContentLength(bytes.length); hsr1.getOutputStream().write(bytes); }
From source file:com.sapito.pdf.PDFView.PDFGeneratorDireccion.java
public void reportefinanzas(Map<String, Object> model, HttpServletResponse hsr1, List<CuentaBancaria> cuenta) throws Exception { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open();/*from w ww . ja va2 s . c o m*/ document.addTitle("Sapito PDFs"); document.addSubject("Pdf de sapito"); Font font1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 30); font1.setColor(BaseColor.BLACK); Font font2 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 24); font2.setColor(BaseColor.BLACK); document.add(new Paragraph("TAILS 2015", font1)); document.add(new Paragraph("Reportes Direccin\n", font2)); //------------------------ TAIS ______________________________ Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg")); document.add(tais); //--------------------- BODY --------------------------------------------------------- Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png")); body.setAlignment(Image.UNDERLYING); body.setTransparency(new int[] { 0x00, 0x10 }); body.setAbsolutePosition(50, 250); document.add(body); //------------------------------------------------------------------------------------------- Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg")); footer.setAbsolutePosition(50, 20); document.add(footer); //---------------------- TITLE --------------------------- String titulo = "Reporte de Finanzas"; //Cambiar el titulo del PDF aqui Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK); Chunk c = new Chunk(titulo + " \n ", f); c.setBackground(BaseColor.WHITE); Paragraph title = new Paragraph(c); title.setAlignment(Element.ALIGN_CENTER); //------------------------- CONTENIDO ------------------------------------------------------- document.add(title); //Titulo del PDF TextoPdf x = (TextoPdf) model.get("todoTexto"); document.add(new Paragraph(x.getTodoTexto())); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100.0f); table.setWidths(new float[] { 2.0f }); table.setSpacingBefore(10); // define font for table header row Font font = FontFactory.getFont(FontFactory.COURIER_BOLD); font.setColor(BaseColor.WHITE); // define table header cell PdfPCell cell = new PdfPCell(); cell.setBackgroundColor(BaseColor.BLUE); cell.setPadding(5); // write table header cell.setPhrase(new Phrase("Total de dinero que se tiene en CUENTAS BANCARIAS", font)); table.addCell(cell); for (int i = 0; i < cuenta.size(); i++) { a = cuenta.get(i).getHaber(); b = b + a; } String bla = b + " "; table.addCell(bla); document.add(table); //-------------------------- FIN CONTENIDO ----------------- document.close(); byte[] bytes = baos.toByteArray(); hsr1.setContentType("application/pdf"); hsr1.setContentLength(bytes.length); hsr1.getOutputStream().write(bytes); }
From source file:com.softwaremagico.tm.pdf.complete.fighting.ArmourTable.java
License:Open Source License
public ArmourTable(CharacterPlayer characterPlayer) throws InvalidXmlElementException { super(WIDTHS); getDefaultCell().setBorder(0);/*w ww.j a v a2s . co m*/ addCell(createLateralVerticalTitle(getTranslator().getTranslatedText("armor"), ROWS + 1)); PdfPCell nameCell; if (characterPlayer == null || characterPlayer.getArmour() == null) { nameCell = createEmptyElementLine(GAP); } else { nameCell = createElementLine(characterPlayer.getArmour().getName(), NAME_COLUMN_WIDTH, FadingSunsTheme.ARMOUR_CONTENT_FONT_SIZE); } nameCell.setColspan(WIDTHS.length); nameCell.setMinimumHeight(20); addCell(nameCell); PdfPCell protectionCell; if (characterPlayer == null || characterPlayer.getArmour() == null) { protectionCell = createEmptyElementLine(getTranslator().getTranslatedText("armorRating") + ": ____ " + getTranslator().getTranslatedText("diceAbbreviature")); } else { Paragraph paragraph = new Paragraph(); paragraph.add(new Paragraph(getTranslator().getTranslatedText("armorRating") + ": ", new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.TABLE_LINE_FONT_SIZE))); paragraph.add(new Paragraph(characterPlayer.getArmour().getProtection() + " ", new Font(FadingSunsTheme.getHandwrittingFont(), FadingSunsTheme.ARMOUR_CONTENT_FONT_SIZE))); paragraph.add(new Paragraph(getTranslator().getTranslatedText("diceAbbreviature"), new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.TABLE_LINE_FONT_SIZE))); protectionCell = createEmptyElementLine(""); protectionCell.setPhrase(paragraph); } protectionCell.setColspan(WIDTHS.length); addCell(protectionCell); PdfPCell malusCell; if (characterPlayer == null || characterPlayer.getArmour() == null) { malusCell = createEmptyElementLine(getTranslator().getTranslatedText("strengthAbbreviature") + ":__ " + getTranslator().getTranslatedText("dexterityAbbreviature") + ":__ " + getTranslator().getTranslatedText("enduranceAbbreviature") + ":__ " + getTranslator().getTranslatedText("iniciativeAbbreviature") + ":__"); } else { Paragraph paragraph = new Paragraph(); paragraph.add(new Paragraph(getTranslator().getTranslatedText("strengthAbbreviature") + ":", new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.TABLE_LINE_FONT_SIZE))); paragraph.add(new Paragraph( characterPlayer.getArmour().getStandardPenalizations().getStrengthModification() + " ", new Font(FadingSunsTheme.getHandwrittingFont(), FadingSunsTheme.ARMOUR_CONTENT_FONT_SIZE))); paragraph.add(new Paragraph(" " + getTranslator().getTranslatedText("dexterityAbbreviature") + ":", new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.TABLE_LINE_FONT_SIZE))); paragraph.add(new Paragraph( characterPlayer.getArmour().getStandardPenalizations().getDexterityModification() + " ", new Font(FadingSunsTheme.getHandwrittingFont(), FadingSunsTheme.ARMOUR_CONTENT_FONT_SIZE))); paragraph.add(new Paragraph(" " + getTranslator().getTranslatedText("enduranceAbbreviature") + ":", new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.TABLE_LINE_FONT_SIZE))); paragraph.add(new Paragraph( characterPlayer.getArmour().getStandardPenalizations().getEnduranceModification() + " ", new Font(FadingSunsTheme.getHandwrittingFont(), FadingSunsTheme.ARMOUR_CONTENT_FONT_SIZE))); paragraph.add(new Paragraph(" " + getTranslator().getTranslatedText("iniciativeAbbreviature") + ":", new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.TABLE_LINE_FONT_SIZE))); paragraph.add(new Paragraph( characterPlayer.getArmour().getStandardPenalizations().getEnduranceModification() + " ", new Font(FadingSunsTheme.getHandwrittingFont(), FadingSunsTheme.ARMOUR_CONTENT_FONT_SIZE))); malusCell = createEmptyElementLine(""); malusCell.setPhrase(paragraph); } malusCell.setColspan(WIDTHS.length); addCell(malusCell); if (characterPlayer == null || characterPlayer.getArmour() == null) { addCell(getArmourProperty(getTranslator().getTranslatedText("armorHardAbbreviature"), false)); addCell(getArmourProperty(getTranslator().getTranslatedText("armorFireAbbreviature"), false)); addCell(getArmourProperty(getTranslator().getTranslatedText("armorLaserAbbreviature"), false)); addCell(getArmourProperty(getTranslator().getTranslatedText("armorPlasmAbbreviature"), false)); addCell(getArmourProperty(getTranslator().getTranslatedText("armorShockAbbreviature"), false)); addCell(getArmourProperty(getTranslator().getTranslatedText("armorImpactAbbreviature"), false)); } else { addCell(getArmourProperty(getTranslator().getTranslatedText("armorHardAbbreviature"), characterPlayer.getArmour().getDamageTypes().contains( DamageTypeFactory.getInstance().getElement("hard", characterPlayer.getLanguage())))); addCell(getArmourProperty(getTranslator().getTranslatedText("armorFireAbbreviature"), characterPlayer.getArmour().getDamageTypes().contains( DamageTypeFactory.getInstance().getElement("fire", characterPlayer.getLanguage())))); addCell(getArmourProperty(getTranslator().getTranslatedText("armorLaserAbbreviature"), characterPlayer.getArmour().getDamageTypes().contains( DamageTypeFactory.getInstance().getElement("laser", characterPlayer.getLanguage())))); addCell(getArmourProperty(getTranslator().getTranslatedText("armorPlasmAbbreviature"), characterPlayer.getArmour().getDamageTypes().contains( DamageTypeFactory.getInstance().getElement("plasma", characterPlayer.getLanguage())))); addCell(getArmourProperty(getTranslator().getTranslatedText("armorShockAbbreviature"), characterPlayer.getArmour().getDamageTypes().contains( DamageTypeFactory.getInstance().getElement("shock", characterPlayer.getLanguage())))); addCell(getArmourProperty(getTranslator().getTranslatedText("armorImpactAbbreviature"), characterPlayer.getArmour().getDamageTypes().contains( DamageTypeFactory.getInstance().getElement("impact", characterPlayer.getLanguage())))); } }
From source file:com.softwaremagico.tm.pdf.complete.fighting.ShieldTable.java
License:Open Source License
public ShieldTable(CharacterPlayer characterPlayer) { super(WIDTHS); getDefaultCell().setBorder(0);/*from ww w. j av a 2 s .c om*/ addCell(createLateralVerticalTitle(getTranslator().getTranslatedText("shield"), ROWS + 1)); PdfPCell nameCell; if (characterPlayer == null || characterPlayer.getShield() == null) { nameCell = createEmptyElementLine(GAP, NAME_COLUMN_WIDTH); } else { nameCell = createElementLine(characterPlayer.getShield().getName(), NAME_COLUMN_WIDTH, FadingSunsTheme.SHIELD_CONTENT_FONT_SIZE); } nameCell.setColspan(WIDTHS.length); nameCell.setMinimumHeight(20); addCell(nameCell); addCell(getShieldRange(characterPlayer)); if (characterPlayer == null || characterPlayer.getShield() == null) { addCell(createEmptyElementLine(getTranslator().getTranslatedText("shieldHits") + ": " + GAP, HITS_COLUMN_WIDTH)); } else { Paragraph paragraph = new Paragraph(); paragraph.add(new Paragraph(getTranslator().getTranslatedText("shieldHits") + ": ", new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.TABLE_LINE_FONT_SIZE))); paragraph.add(new Paragraph(characterPlayer.getShield().getHits() + " ", new Font(FadingSunsTheme.getHandwrittingFont(), FadingSunsTheme.SHIELD_CONTENT_FONT_SIZE))); PdfPCell protectionCell = createEmptyElementLine(""); protectionCell.setPhrase(paragraph); addCell(protectionCell); } addCell(createEmptyElementLine("___________________")); addCell(createEmptyElementLine("___________________")); }
From source file:com.softwaremagico.tm.pdf.complete.info.DescriptionTable.java
License:Open Source License
private PdfPCell createLine(CharacterPlayer characterPlayer, String tag) { Paragraph paragraph = new Paragraph(); String text = getTranslatedTag(tag); // Spaces at the end are eliminated. For calculating width we can put // the characters in different order. float textWidth = FadingSunsTheme.getLineFont().getWidthPoint(text + " :", FadingSunsTheme.TABLE_LINE_FONT_SIZE); paragraph.add(new Paragraph(text + ": ", new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.TABLE_LINE_FONT_SIZE))); if (characterPlayer == null || characterPlayer.getInfo().getTranslatedParameter(tag) == null) { paragraph.add(new Paragraph( CellUtils.getSubStringFitsIn(GAP, FadingSunsTheme.getLineFont(), FadingSunsTheme.TABLE_LINE_FONT_SIZE, COLUMN_WIDTH - textWidth), new Font(FadingSunsTheme.getLineFont(), FadingSunsTheme.TABLE_LINE_FONT_SIZE))); } else {//from ww w.jav a2 s . c o m paragraph.add(new Paragraph( CellUtils.getSubStringFitsIn(characterPlayer.getInfo().getTranslatedParameter(tag), FadingSunsTheme.getHandwrittingFont(), FadingSunsTheme.INFO_CONTENT_FONT_SIZE, COLUMN_WIDTH - textWidth), new Font(FadingSunsTheme.getHandwrittingFont(), FadingSunsTheme.INFO_CONTENT_FONT_SIZE))); } PdfPCell cell = createEmptyElementLine(""); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setPhrase(paragraph); return cell; }
From source file:com.thelinh.gui.PreviewExam.java
private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrintActionPerformed if (this.txtExamCode.getText().equals("")) { JOptionPane.showMessageDialog(this, "Hy nhp m ?"); } else {//from w w w . j av a2 s. c o m JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF files (*.pdf)", "pdf"); fc.setFileFilter(filter); int rt = fc.showSaveDialog(this); if (rt == JFileChooser.APPROVE_OPTION) { String filepath = fc.getSelectedFile().getPath(); if (filepath.indexOf(".") == -1) { filepath = filepath + ".pdf"; } String dafilepath = (new StringBuffer(filepath)).insert(filepath.length() - 4, ".da").toString(); try { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(filepath)); document.open(); // Add title Paragraph p = new Paragraph("Tr?ng ?i h?c Bch Khoa H Ni", timesBold_25); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(5); document.add(p); p = new Paragraph("?? thi mn " + this.lbSubject.getText(), timesBold_25); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(25); document.add(p); p = new Paragraph( "Ng?i ra ?: " + Controller.getCurrentAdmin().getAdminName() + ", Ngy ra ?: " + (new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime())), times_15); p.setAlignment(Element.ALIGN_LEFT); p.setSpacingAfter(5); document.add(p); p = new Paragraph("M ?: " + this.txtExamCode.getText() + " Th?i gian lm bi: " + spTime.getValue().toString() + " pht", timesBold_15); p.setSpacingAfter(25); document.add(p); for (int i = 0; i < this.questionList.size(); i++) { Question question = this.questionList.get(i); ArrayList<Answer> answerList = AnswerSql .getAnswersByQuestionId(question.getQuestionId().trim()); Phrase questionNumber = new Phrase("Cu " + (i + 1) + ": ", timesBold_15); Phrase questionContent = new Phrase(question.getQuestion(), times_15); Paragraph questionTitle = new Paragraph(); questionTitle.add(questionNumber); questionTitle.add(questionContent); document.add(questionTitle); PdfPTable table = new PdfPTable(2); for (int j = 0; j < answerList.size(); j++) { Answer ans = answerList.get(j); Phrase cap = new Phrase(Character.toString((char) (j + 65)) + ". ", timesBold_15); Phrase answerContent = new Phrase(ans.getAnswer(), times_15); Phrase elem = new Phrase(); elem.add(cap); elem.add(answerContent); PdfPCell cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setPhrase(elem); cell.setFixedHeight(25); table.addCell(cell); } document.add(table); } document.close(); // if (Desktop.isDesktopSupported()) { // try { // File myFile = new File(filepath); // Desktop.getDesktop().open(myFile); // } catch (IOException ex) { // // no application registered for PDFs // System.out.println(ex.toString()); // } // } document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(dafilepath)); document.open(); // Add title p = new Paragraph("Tr?ng ?i h?c Bch Khoa H Ni", timesBold_25); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(5); document.add(p); p = new Paragraph("?? thi mn " + this.lbSubject.getText(), timesBold_25); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(25); document.add(p); p = new Paragraph( "Ng?i ra ?: " + Controller.getCurrentAdmin().getAdminName() + ", Ngy ra ?: " + (new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime())), times_15); p.setAlignment(Element.ALIGN_LEFT); p.setSpacingAfter(5); document.add(p); p = new Paragraph("M ?: " + this.txtExamCode.getText() + " Th?i gian lm bi: " + spTime.getValue().toString() + " pht", timesBold_15); p.setSpacingAfter(25); document.add(p); for (int i = 0; i < this.questionList.size(); i++) { Question question = this.questionList.get(i); ArrayList<Answer> answerList = AnswerSql .getAnswersByQuestionId(question.getQuestionId().trim()); Phrase questionNumber = new Phrase("Cu " + (i + 1) + ": ", timesBold_15); Phrase questionContent = new Phrase(question.getQuestion(), times_15); Paragraph questionTitle = new Paragraph(); questionTitle.add(questionNumber); questionTitle.add(questionContent); document.add(questionTitle); PdfPTable table = new PdfPTable(2); for (int j = 0; j < answerList.size(); j++) { Answer ans = answerList.get(j); Phrase cap = new Phrase(Character.toString((char) (j + 65)) + ". ", timesBold_15); Phrase answerContent = null; if (ans.getYesNo()) { answerContent = new Phrase(ans.getAnswer(), timesBold_15); } else { answerContent = new Phrase(ans.getAnswer(), times_15); } Phrase elem = new Phrase(); elem.add(cap); elem.add(answerContent); PdfPCell cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setPhrase(elem); cell.setFixedHeight(25); table.addCell(cell); } document.add(table); } document.close(); } catch (FileNotFoundException | DocumentException ex) { Logger.getLogger(PreviewExam.class.getName()).log(Level.SEVERE, null, ex); } } } }
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 ww w .j av a 2 s . co 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:de.alpharogroup.swing.img.ImageExtensions.java
License:Open Source License
/** * Factory method for create a new {@link PdfPTable} with the given count of columns and the * column header names/*w w w . j a v a2 s. co m*/ * * @param numColumns * the count of columns of the table * @param headerNames * the column header names * @return the new {@link PdfPTable} */ public static PdfPTable newPdfPTable(int numColumns, List<String> headerNames) { PdfPTable table = new PdfPTable(numColumns); headerNames.stream().forEach(columnHeaderName -> { PdfPCell header = new PdfPCell(); header.setBackgroundColor(BaseColor.LIGHT_GRAY); header.setBorderWidth(2); header.setPhrase(new Phrase(columnHeaderName)); table.addCell(header); }); return table; }