List of usage examples for com.lowagie.text FontFactory getFont
public static Font getFont(String fontname, float size, int style)
Font
-object. From source file:org.sakaiproject.evaluation.tool.reporting.EvalPDFReportBuilder.java
License:Educational Community License
public EvalPDFReportBuilder(OutputStream outputStream) { document = new Document(); try {/*ww w. j a v a 2 s . com*/ pdfWriter = PdfWriter.getInstance(document, outputStream); pdfWriter.setStrictImageSequence(true); document.open(); // attempting to handle i18n chars better // BaseFont evalBF = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.IDENTITY_H, // BaseFont.EMBEDDED); // paragraphFont = new Font(evalBF, 9, Font.NORMAL); // paragraphFont = new Font(Font.TIMES_ROMAN, 9, Font.NORMAL); titleTextFont = new Font(Font.TIMES_ROMAN, 22, Font.BOLD); boldTextFont = new Font(Font.TIMES_ROMAN, 10, Font.BOLD); questionTextFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.BOLD); paragraphFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.NORMAL); paragraphFontBold = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD); frontTitleFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, frontTitleSize, Font.NORMAL); frontAuthorFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.NORMAL); frontInfoFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.NORMAL); } catch (Exception e) { throw UniversalRuntimeException.accumulate(e, "Unable to start PDF Report"); } }
From source file:questions.tables.TableHeaderAlternateBackground.java
public static void main(String[] args) { // step 1: creation of a document-object Document document = new Document(PageSize.A4.rotate()); try {//ww w. ja v a2 s . c o m // step 2: // we create a writer PdfWriter.getInstance( // that listens to the document document, // and directs a PDF-stream to a file new FileOutputStream(RESULT)); // step 3: we open the document document.open(); // step 4: we add a table to the document PdfPTable datatable = new PdfPTable(10); datatable.setTableEvent(new AlternateBackground()); int headerwidths[] = { 10, 24, 12, 12, 7, 7, 7, 7, 7, 7 }; datatable.setWidths(headerwidths); datatable.setWidthPercentage(100); datatable.getDefaultCell().setPadding(5); // The header starts with a cell that spans 10 columns PdfPCell cell = new PdfPCell(new Phrase("Administration - System Users Report", FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLD))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(2); cell.setColspan(10); cell.setBackgroundColor(Color.YELLOW); cell.setUseDescender(true); datatable.addCell(cell); // We need 4 cells with rowspan 2 datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setBackgroundColor(Color.YELLOW); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell("User Id"); datatable.addCell("Name\nAddress"); datatable.addCell("Company"); datatable.addCell("Department"); datatable.getDefaultCell().setBackgroundColor(null); // we use a nested table to fake this PdfPTable permissions = new PdfPTable(6); permissions.getDefaultCell().setBackgroundColor(Color.YELLOW); permissions.getDefaultCell().setBorderWidth(2); permissions.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); permissions.getDefaultCell().setColspan(6); permissions.addCell("Permissions"); permissions.getDefaultCell().setColspan(1); permissions.addCell("Admin"); permissions.addCell("Data"); permissions.addCell("Expl"); permissions.addCell("Prod"); permissions.addCell("Proj"); permissions.addCell("Online"); PdfPCell permission = new PdfPCell(permissions); permission.setColspan(6); datatable.addCell(permission); // this is the end of the table header // as far as PdfPTable is concerned there are 2 rows in the header datatable.setHeaderRows(2); // we add the data to the table datatable.getDefaultCell().setBorderWidth(1); for (int i = 1; i < 50; i++) { datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell("myUserId"); datatable.addCell("Person " + i); datatable.addCell("No Name Company"); datatable.addCell("D" + i); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (int j = 0; j < 6; j++) datatable.addCell(Math.random() > .5 ? "Yes" : "No"); } document.add(datatable); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5: we close the document document.close(); }
From source file:se.kth.ict.iv1201.recsys.controller.PdfServlet.java
/** * Servlet GET, returns a PDF with inforation specified as * parameters if the user is logged in and of right user role * /*from w ww .j a v a2 s . co m*/ * @param request * @param response * @throws ServletException * @throws IOException */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { Principal user = request.getUserPrincipal(); if (user == null || !request.isUserInRole("recruiter")) throw new ServletException("Not logged in"); String name = request.getParameter("name"); String surname = request.getParameter("surname"); String submitDate = request.getParameter("submitdate"); String[] competences = request.getParameter("comp").split("_"); String[] availabilities = request.getParameter("avail").split("_"); Font titleFont = FontFactory.getFont("Times-Roman", 18, Font.BOLD); response.setContentType("application/pdf"); response.setHeader("Content-disposition", "attachment; filename=" + name + surname + "-application.pdf"); response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate"); Document doc = new Document(); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); PdfWriter docWriter = PdfWriter.getInstance(doc, baosPDF); doc.open(); doc.add(new Paragraph("Application", titleFont)); doc.add(new Paragraph( "Name: " + name + "\nSurname: " + surname + "\nApplication submit date: " + submitDate)); doc.add(new Paragraph("Competences", titleFont)); StringBuilder sb = new StringBuilder(); for (String comp : competences) { sb.append(comp + "\n"); } doc.add(new Paragraph(sb.toString())); doc.add(new Paragraph("Availabilities", titleFont)); sb = new StringBuilder(); for (String avail : availabilities) { sb.append(avail + "\n"); } doc.add(new Paragraph(sb.toString())); doc.close(); docWriter.close(); response.setContentLength(baosPDF.size()); ServletOutputStream sos = response.getOutputStream(); baosPDF.writeTo(sos); sos.flush(); } catch (DocumentException ex) { Logger.getLogger(PdfServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:sms.ReportForms.java
public PdfPCell creatTextCellHeader(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD)); p.add(text);//from w w w.ja v a 2 s . c om cell.addElement(p); cell.setBorder(Rectangle.NO_BORDER); return cell; }
From source file:sms.ReportForms.java
public PdfPCell creatTextCellChart(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD)); p.add(text);//from www .j av a 2 s. c o m cell.addElement(p); cell.setRowspan(2); cell.setBorder(Rectangle.NO_BORDER); return cell; }
From source file:sms.ReportForms.java
public PdfPCell createTextCell(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 16, Font.BOLD)); // p.setFont(Font.BOLD); p.setAlignment(Element.ALIGN_CENTER); p.add(text);//from w ww.j av a2 s . c o m cell.addElement(p); cell.setBorder(Rectangle.NO_BORDER); cell.setVerticalAlignment(Rectangle.NO_BORDER); return cell; }
From source file:sms.ViewResults.java
private void itextPrint() { // String searchQuery = "SELECT * FROM `exam` WHERE `yearid` ='" + yearid + "'AND `termid`='"+termid+"'AND `examid`='"+yearid+"'" // + "AND CONCAT(`class`) LIKE '%" + stream + "%'AND YEAR(updated_at)='"+yearchooser.getYear()+"'"; methods nn = new methods(); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(",")); chooser.setDialogTitle("Save at"); chooser.setApproveButtonText("save"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { try {/*from w w w . ja v a 2 s.c o m*/ Form1Exams n = new Form1Exams(); Document pdfp = new Document(); PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(), "report.pdf"))); pdfp.open(); Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_CENTER); p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD)); Paragraph po = new Paragraph(); po.setAlignment(Element.ALIGN_CENTER); po.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 16, Font.BOLD)); Paragraph pd = new Paragraph(); pd.setAlignment(Element.ALIGN_CENTER); pd.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 14, Font.BOLD)); p.add("ITHANGA SECONDARY SCHOOL"); po.add("PO.BOX 238 ITHANGA THIKA"); pd.add(new Date().toString()); pdfp.add(p); pdfp.add(po); pdfp.add(pd); pdfp.add(new Paragraph("\n.................................................................." + ".................................................................................\n")); String[] names = n.findSubjectname(); PdfPTable tbl = new PdfPTable(names.length + 6); tbl.setWidths(new float[] { 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); // tbl.setWidthPercentage(100); tbl.setTotalWidth(575); tbl.setLockedWidth(true); PdfPTable tbl1 = new PdfPTable(names.length + 6); tbl1.setWidths(new float[] { 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); // tbl.setWidthPercentage(100); tbl1.setTotalWidth(575); tbl1.setLockedWidth(true); PdfPCell cell = new PdfPCell(new Paragraph("RESULTS")); cell.setColspan((names.length + 4) * 2); cell.setBackgroundColor(Color.CYAN); tbl1.addCell(cell); tbl1.addCell("Pos"); tbl1.addCell("id"); tbl1.addCell("Name"); int a; for (a = 0; a < names.length; a++) { String s = names[a]; tbl1.addCell(s.substring(0, Math.min(s.length(), 3))); } tbl1.addCell("Tot"); tbl1.addCell("Ave"); tbl1.addCell("Agg"); pdfp.add(tbl1); try { String[] Subjects = n.findSubjectid(); String[] Subjectsnames = n.findSubjectname(); int subjectCount = Subjects.length; ArrayList<ExamDbDataHolder> users = ListUsers(this.sid.getText()); for (int i = 0; i < users.size(); i++) { tbl.addCell(String.valueOf(i + 1)); String id = ((ExamDbDataHolder) users.get(i)).getSid(); String nam = nn.getStudentName(id); String name = "Eric"; tbl.addCell(id); tbl.addCell(nam); int c = 2; for (int s = 0; s < Subjects.length; s++) { if (Subjects[s].equals("s1")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getMathematics()); // JOptionPane.showMessageDialog(null,((ExamDbDataHolder)users.get(i)).getMathematics()); // String maths = ((ExamDbDataHolder)users.get(i)).getMathematics(); c++; } else if (Subjects[s].equals("s2")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getEnglish()); //row[c] = ((ExamDbDataHolder)users.get(i)).getEnglish(); c++; } else if (Subjects[s].equals("s3")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getKiswahili()); // row[c] = ((ExamDbDataHolder)users.get(i)).getKiswahili(); c++; } else if (Subjects[s].equals("s4")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getPhysics()); // row[c] = ((ExamDbDataHolder)users.get(i)).getPhysics(); c++; } else if (Subjects[s].equals("s5")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getChemistry()); // row[c] = ((ExamDbDataHolder)users.get(i)).getChemistry(); c++; } else if (Subjects[s].equals("s6")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getBiology()); // row[c] = ((ExamDbDataHolder)users.get(i)).getBiology(); c++; } else if (Subjects[s].equals("s7")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getHistory()); // row[c] = ((ExamDbDataHolder)users.get(i)).getHistory(); c++; } else if (Subjects[s].equals("s8")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getGeography()); // row[c] = ((ExamDbDataHolder)users.get(i)).getGeography(); c++; } else if (Subjects[s].equals("s9")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getCre()); // row[c] = ((ExamDbDataHolder)users.get(i)).getCre(); c++; } else if (Subjects[s].equals("s10")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getIre()); // row[c] = ((ExamDbDataHolder)users.get(i)).getIre(); c++; } else if (Subjects[s].equals("s11")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getHre()); // row[c] = ((ExamDbDataHolder)users.get(i)).getHre(); c++; } else if (Subjects[s].equals("s12")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getAgriculture()); // row[c] = ((ExamDbDataHolder)users.get(i)).getAgriculture(); c++; } else if (Subjects[s].equals("s13")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getHomescience()); // row[c] = ((ExamDbDataHolder)users.get(i)).getHomescience(); c++; } else if (Subjects[s].equals("s14")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getArtdesign()); // row[c] = ((ExamDbDataHolder)users.get(i)).getArtdesign(); c++; } else if (Subjects[s].equals("s15")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getComputer()); // row[c] = ((ExamDbDataHolder)users.get(i)).getComputer(); c++; } else if (Subjects[s].equals("s16")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getBuilding()); // row[c] = ((ExamDbDataHolder)users.get(i)).getBuilding(); c++; } else if (Subjects[s].equals("s17")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getWoodwork()); // row[c] = ((ExamDbDataHolder)users.get(i)).getWoodwork(); c++; } else if (Subjects[s].equals("s18")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getMetalwork()); // row[c] = ((ExamDbDataHolder)users.get(i)).getMetalwork(); c++; } else if (Subjects[s].equals("s19")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getMusic()); // row[c] = ((ExamDbDataHolder)users.get(i)).getMusic(); c++; } else if (Subjects[s].equals("s20")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getFrench()); // row[c] = ((ExamDbDataHolder)users.get(i)).getFrench(); c++; } else if (Subjects[s].equals("s21")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getGerman()); // row[c] = ((ExamDbDataHolder)users.get(i)).getGerman(); c++; } else if (Subjects[s].equals("s22")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getArabic()); // row[c] = ((ExamDbDataHolder)users.get(i)).getArabic(); c++; } else if (Subjects[s].equals("s23")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getBusiness()); // row[c] = ((ExamDbDataHolder)users.get(i)).getBusiness(); c++; } } int tt = ((ExamDbDataHolder) users.get(i)).getTotal(); tbl.addCell(String.valueOf(tt)); float g = Float.valueOf(tt) / 11; tbl.addCell(String.format("%.1f", g)); String gr = nn.checkGrade(yearid, String.format("%.1f", g)); tbl.addCell(gr); } pdfp.add(tbl); } catch (Exception j) { j.printStackTrace(); } pdfp.close(); // Image img=new Image.getInstance("j.png"); } catch (DocumentException ex) { Logger.getLogger(ViewResults.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ViewResults.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:storemanagment.Printing.java
public PdfPCell creatTextCellTitles(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD)); p.add(text);// ww w .j a v a2s. c o m cell.addElement(p); // cell.setBorder(Rectangle.NO_BORDER); return cell; }
From source file:storemanagment.Printing.java
public PdfPCell createTextCell(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setFont(FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, java.awt.Font.BOLD)); // p.setFont(Font.BOLD); p.setAlignment(Element.ALIGN_CENTER); p.add(text);//from w w w. j a v a 2 s . c o m cell.addElement(p); cell.setBorder(Rectangle.NO_BORDER); cell.setVerticalAlignment(Rectangle.NO_BORDER); return cell; }
From source file:test.itext.html.AimsPdf.java
License:Open Source License
public static void addTitle(Document doc, String text) throws IOException, BadElementException, DocumentException { float[] widths = { 62f, 164f, 62f }; PdfPTable table = new PdfPTable(widths); table.setWidthPercentage(100);// ww w.j a v a 2 s. c om table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setSpacingAfter(10); Image image = Image.getInstance("app_title.gif"); image.scalePercent(70); PdfPCell cell = new PdfPCell(image); cell.setPadding(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); Paragraph title = new Paragraph(text, FontFactory.getFont("arial", 12, Font.BOLD)); cell = new PdfPCell(title); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); image = Image.getInstance("title_shot.gif"); image.scalePercent(70); cell = new PdfPCell(image); cell.setPadding(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); doc.add(table); table = new PdfPTable(1); table.setWidthPercentage(100); cell = new PdfPCell(); cell.setBackgroundColor(Color.BLACK); cell.setFixedHeight(1); table.addCell(cell); doc.add(table); }