List of usage examples for com.itextpdf.text Phrase Phrase
public Phrase(final float leading, final String string)
Phrase
with a certain leading and a certain String
. From source file:com.solidmaps.webapp.report.EnableCompanyRequerimentFederalPDF.java
private void insertCellAlteracaoOption(PdfPTable table, String number, String text, Boolean selected) { String fullText = ""; if (selected) { fullText += number + " |X|" + " " + text; } else {//from w w w . j a va 2 s.co m fullText += number + " | |" + " " + text; } if (StringUtils.isBlank(number) && StringUtils.isBlank(text)) { fullText = ""; } // create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(fullText.trim(), FONT_PARAGRAPH)); // set the cell alignment // in case there is no text and you wan to create an empty row if (fullText.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.RIGHT); cell.setPaddingTop(10f); cell.setPaddingBottom(10f); cell.setPaddingLeft(10f); cell.setPaddingRight(10f); // add the call to the table table.addCell(cell); }
From source file:com.solidmaps.webapp.report.EnableCompanyRequerimentFederalPDF.java
private void insertHeaderCell(PdfPTable table, String text, Integer colSpan) { if (text == null) { text = ""; }/*from w w w . j a v a2 s. c om*/ // create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(text.trim(), FONT_HEADER)); // set the cell alignment // in case there is no text and you wan to create an empty row if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(colSpan); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorderWidth(2); cell.setPadding(3f); // add the call to the table table.addCell(cell); }
From source file:com.solidmaps.webapp.report.LicenseCivilIncludeProductPDF.java
License:Open Source License
private void insertCell(PdfPTable table, String text, int align, Font font, boolean border) { if (text == null) { text = ""; }/* w ww . ja v a 2 s . c o m*/ // create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font)); // set the cell alignment cell.setHorizontalAlignment(align); // in case there is no text and you wan to create an empty row if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } if (!border) { cell.setBorder(Rectangle.NO_BORDER); } // add the call to the table table.addCell(cell); }
From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java
private void insertCell(PdfPTable table, String text, Integer colSpan) { if (text == null) { text = ""; }/*from w ww .j a v a2 s . c om*/ // create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(text.trim(), FONT_PARAGRAPH)); // set the cell alignment // in case there is no text and you wan to create an empty row if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setColspan(colSpan); cell.setPadding(5f); // add the call to the table table.addCell(cell); }
From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java
private void insertCellAlteracao(PdfPTable table, String text) { if (text == null) { text = ""; }/*from w w w. j a v a 2s . c o m*/ // create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(text.trim(), FONT_HEADER)); // set the cell alignment // in case there is no text and you wan to create an empty row if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(2); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); // add the call to the table table.addCell(cell); }
From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java
private void insertCellAlteracaoOption(PdfPTable table, String number, String text, Boolean selected) { String fullText = ""; if (selected) { fullText += number + " |X|" + " " + text; } else {/* w w w .jav a2s. c o m*/ fullText += number + " | |" + " " + text; } if (StringUtils.isBlank(number) && StringUtils.isBlank(text)) { fullText = ""; } // create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(fullText.trim(), FONT_PARAGRAPH)); // set the cell alignment // in case there is no text and you wan to create an empty row if (fullText.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setColspan(2); cell.setBorder(Rectangle.RIGHT); cell.setPaddingTop(10f); cell.setPaddingBottom(10f); cell.setPaddingLeft(25f); cell.setPaddingRight(25f); // add the call to the table table.addCell(cell); }
From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java
private void insertHeaderCell(PdfPTable table, String text, Integer colSpan) { if (text == null) { text = ""; }/*from w w w . j ava 2 s.co m*/ // create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(text.trim(), FONT_HEADER)); // set the cell alignment // in case there is no text and you wan to create an empty row if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(colSpan); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorderWidth(2); cell.setPadding(3f); // add the call to the table table.addCell(cell); }
From source file:com.swayam.bhasha.engine.io.writers.impl.PDFGenerator.java
License:Apache License
private Paragraph getParagraph(Para para) throws DocumentException, IOException, DocGenerationException { int align = para.getAlignment(); int pdfAlign; switch (align) { case Para.CENTER: pdfAlign = Paragraph.ALIGN_CENTER; break;//from w w w. jav a 2 s . c o m case Para.RIGHT: pdfAlign = Paragraph.ALIGN_RIGHT; break; case Para.JUSTIFIED: pdfAlign = Paragraph.ALIGN_JUSTIFIED; break; case Para.LEFT: default: pdfAlign = Paragraph.ALIGN_LEFT; break; } List<ParaText> paraTextList = para.getParaTextList(); Paragraph paragraph = new Paragraph(); paragraph.setAlignment(pdfAlign); for (ParaText paraText : paraTextList) { int fontStyle = Font.NORMAL; if (paraText.isBold()) { fontStyle |= Font.BOLD; } if (paraText.isUnderline()) { fontStyle |= Font.UNDERLINE; } if (paraText.isItalic()) { fontStyle |= Font.ITALIC; } Font font = FontFactory.getFont(paraText.getFontFamily(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED, paraText.getFontSize(), fontStyle, new BaseColor(paraText.getColor().getRGB())); // its very important to set the leading every time the font is set // otherwise, the chunks/phrases overlap. // paragraph.setLeading(font.getSize() * 1.5f); paragraph.add(new Phrase(paraText.getText(), font)); } return paragraph; }
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 a va 2 s.co 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);//w w w . j a va2 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. }