List of usage examples for com.lowagie.text Font BOLD
int BOLD
To view the source code for com.lowagie.text Font BOLD.
Click Source Link
From source file:recite18th.controller.Controller.java
License:Open Source License
public void print(String action) { /** thanks to http://www.java2s.com/Code/Java/PDF-RTF/DemonstratesthecreatingPDFinportraitlandscape.htm * QUICK FIX : do landscape/* w w w .ja va 2 s . co m*/ */ response.setContentType("application/pdf"); // Code 1 if (action.equals("download")) { response.setHeader("Content-Transfer-Encoding", "binary"); response.setHeader("Content-Disposition", "attachment; filename=\"" + "Report " + controllerName + ".pdf\""); } Document document = new Document(PageSize.A1.rotate()); try { PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // Code 2 document.open(); // various fonts BaseFont bf_helv = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false); BaseFont bf_times = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", false); BaseFont bf_courier = BaseFont.createFont(BaseFont.COURIER, "Cp1252", false); BaseFont bf_symbol = BaseFont.createFont(BaseFont.SYMBOL, "Cp1252", false); String headerImage = Config.base_path + "images/report-logo.gif"; Image imghead = Image.getInstance(headerImage); imghead.setAbsolutePosition(0, 0); PdfContentByte cbhead = writer.getDirectContent(); PdfTemplate tpLogo = cbhead.createTemplate(600, 300); tpLogo.addImage(imghead); PdfTemplate tpTitle = cbhead.createTemplate(1100, 300); String txtHeader = "BADAN KEPEGAWAIAN DAERAH PEMERINTAH DAERAH";//Config.application_title; tpTitle.beginText(); tpTitle.setFontAndSize(bf_times, 36); tpTitle.showText(txtHeader); tpTitle.endText(); PdfTemplate tpTitle2 = cbhead.createTemplate(900, 300); String txtHeader2 = " KABUPATEN BANTUL YOGYAKARTA"; tpTitle2.beginText(); tpTitle2.setFontAndSize(bf_times, 36); tpTitle2.showText(txtHeader2); tpTitle2.endText(); PdfTemplate tpAlamat = cbhead.createTemplate(1000, 400); tpAlamat.beginText(); tpAlamat.setFontAndSize(bf_times, 24); tpAlamat.showText( "Alamat : Jln. R. W. Monginsidi No. 01 Kompleks Parasamya Bantul, Telp. (0274) 367509"); tpAlamat.endText(); DateFormat df = new SimpleDateFormat("dd MMM yyyy"); java.util.Date dt = new java.util.Date(); PdfTemplate tp3 = cbhead.createTemplate(600, 300); tp3.beginText(); tp3.setFontAndSize(bf_times, 16); tp3.showText("Tanggal : " + df.format(dt)); tp3.endText(); cbhead.addTemplate(tpLogo, 800, 1500);//logo cbhead.addTemplate(tpTitle, 1000, 1580); cbhead.addTemplate(tpTitle2, 1000, 1540); cbhead.addTemplate(tpAlamat, 1000, 1500);//alamat cbhead.addTemplate(tp3, 270, 1500);//tanggal HeaderFooter header = new HeaderFooter(new Phrase(cbhead + "", new Font(bf_helv)), false); header.setAlignment(Element.ALIGN_CENTER); document.setHeader(header); //PdfContentByte cb = writer.getDirectContent(); Paragraph par = new Paragraph( "\n\n\n\n\n\n\nLAPORAN DATA SELURUH " + controllerName.toUpperCase() + "\n"); par.getFont().setStyle(Font.BOLD); par.getFont().setSize(18); par.setAlignment("center"); document.add(par); document.add(new Paragraph("\n\n")); // get data initSqlViewDataPerPage(); if (sqlViewDataPerPageForReport == null) { sqlViewDataPerPageForReport = sqlViewDataPerPage; } PreparedStatement pstmt = Db.getCon().prepareStatement(sqlViewDataPerPageForReport, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = pstmt.executeQuery(); ResultSetMetaData metaColumn = resultSet.getMetaData(); int nColoumn = metaColumn.getColumnCount(); // thanks to set cell width http://www.jexp.ru/index.php/Java/PDF_RTF/Table_Cell_Size#Setting_Cell_Widths if (nColoumn > 0) { Model model = initModel(); String tableName = model.getTableName(); // create table header // float[] widths = {1, 4}; PdfPTable table;// = new PdfPTable(nColoumn); PdfPCell cell = new PdfPCell(new Paragraph("Daftar " + controllerName)); Hashtable hashModel = TableCustomization.getTable(model.getTableName()); int ncolumnHeader = nColoumn + 1; // +1 because of row. number if (hashModel != null) { ncolumnHeader = Integer.parseInt("" + hashModel.get("columnCount")) + 1; } table = new PdfPTable(ncolumnHeader); cell.setColspan(ncolumnHeader); cell.setHorizontalAlignment(Element.ALIGN_CENTER); Paragraph p2 = new Paragraph("No."); p2.getFont().setSize(20); PdfPCell cellColNo = new PdfPCell(p2); cellColNo.setNoWrap(true); cellColNo.setMinimumHeight(50); cellColNo.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellColNo); if (hashModel != null) { Enumeration k = hashModel.keys(); while (k.hasMoreElements()) { String key = (String) k.nextElement(); if (key.equals("columnCount")) { continue; } PdfPCell cellCol = new PdfPCell(new Paragraph(hashModel.get(key) + "")); cellCol.setNoWrap(true); cellCol.setMinimumHeight(50); cellCol.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellCol); } } else { for (int i = 1; i < ncolumnHeader; i++) { System.out.println("DATA = " + metaColumn.getColumnName(i)); Paragraph p1 = new Paragraph(metaColumn.getColumnName(i) + ""); p1.getFont().setSize(20); PdfPCell cellCol = new PdfPCell(p1); cellCol.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellCol); } } //iterate all columns : table data resultSet.beforeFirst(); int row = 1; while (resultSet.next()) { System.out.println(row); Paragraph p3 = new Paragraph(row + ""); p3.getFont().setSize(20); cell = new PdfPCell(p3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); if (hashModel != null) {//skip dulu u/ kasus ga pny class kustomasi table Enumeration k = hashModel.keys(); while (k.hasMoreElements()) { String key = (String) k.nextElement(); if (key.equals("columnCount")) { continue; } table.addCell(resultSet.getObject(key) + ""); } } else { for (int i = 1; i < ncolumnHeader; i++) { System.out.println("DATA = " + metaColumn.getColumnName(i)); Paragraph p1 = new Paragraph(resultSet.getObject(metaColumn.getColumnName(i)) + ""); p1.getFont().setSize(18); PdfPCell cellCol = new PdfPCell(p1); cellCol.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellCol); } } row++; } document.add(table); document.add(new Paragraph("\n\n")); par = new Paragraph("Mengetahui"); par.setAlignment("center"); document.add(par); par = new Paragraph("Kepada Badan Kepegawaian"); par.setAlignment("center"); document.add(par); par = new Paragraph("\n\n\n"); document.add(par); par = new Paragraph("Drs. Maman Permana"); par.setAlignment("center"); document.add(par); par = new Paragraph("Nip: 197802042006041013"); par.setAlignment("center"); document.add(par); } document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:ro.nextreports.engine.exporter.RtfExporter.java
License:Apache License
private void updateFont(Font fnt, Map<String, Object> style) { if (style != null) { if (style.containsKey(StyleFormatConstants.FONT_FAMILY_KEY)) { String val = (String) style.get(StyleFormatConstants.FONT_FAMILY_KEY); fnt.setFamily(val); }//from w w w . j av a 2s . co m if (style.containsKey(StyleFormatConstants.FONT_SIZE)) { Float val = (Float) style.get(StyleFormatConstants.FONT_SIZE); fnt.setSize(val); } if (style.containsKey(StyleFormatConstants.FONT_COLOR)) { Color val = (Color) style.get(StyleFormatConstants.FONT_COLOR); fnt.setColor(val); } if (style.containsKey(StyleFormatConstants.FONT_STYLE_KEY)) { if (StyleFormatConstants.FONT_STYLE_NORMAL.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { fnt.setStyle(com.lowagie.text.Font.NORMAL); } if (StyleFormatConstants.FONT_STYLE_BOLD.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { fnt.setStyle(com.lowagie.text.Font.BOLD); } if (StyleFormatConstants.FONT_STYLE_ITALIC.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { fnt.setStyle(com.lowagie.text.Font.ITALIC); } if (StyleFormatConstants.FONT_STYLE_BOLDITALIC .equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { fnt.setStyle(com.lowagie.text.Font.BOLDITALIC); } } } }
From source file:rollyroll.com.servlet.ModuloServlet.java
private void exportar_ModulosaPDF(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try {// w ww .j a va 2 s .c o m // String[] headers = new String[]{"CODIGO", "NOMBRE", "ACCION", "ORDEN", "ICONO", "ESTADO"}; String[] headers = new String[] { "NOMBRE", "ACCION", "ICONO" }; ArrayList<Modulo> lista = null; lista = moduloService.listar_Modulos(); PdfPTable table = new PdfPTable(headers.length); table.setHorizontalAlignment(0); table.setWidthPercentage(95); float[] espaciocolumna = new float[] { 25f, 38f, 50f }; table.setWidths(espaciocolumna); for (int i = 0; i < headers.length; i++) { String header = headers[i]; PdfPCell cell = new PdfPCell(); cell.setBackgroundColor(Color.YELLOW); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setPhrase(new Phrase(header.toUpperCase(), new Font(Font.HELVETICA, 10, Font.BOLD))); table.addCell(cell); } table.completeRow(); PdfPCell cell; // int codigomodulo = 0; String nombremodulo = ""; String accionmodulo = ""; // int ordenmodulo = 0; String iconomodulo = ""; // int estadomodulo = 0; for (Modulo modulo : lista) { // codigomodulo += Integer.parseInt(modulo.getCodigomodulo()); nombremodulo += modulo.getNombremodulo(); accionmodulo += modulo.getAccionmodulo(); // ordenmodulo += Integer.parseInt(modulo.getOrdenmoduloS()); iconomodulo += modulo.getIconomodulo(); // estadomodulo += Byte.parseByte(modulo.getEstadomoduloS()); // cell = new PdfPCell(); // cell.setPhrase(new Phrase(modulo.getCodigomoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL))); // cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); // table.addCell(cell); // cell = new PdfPCell(); cell.setPhrase(new Phrase(modulo.getNombremodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL))); cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(); cell.setPhrase(new Phrase(modulo.getAccionmodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL))); cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.addCell(cell); // cell = new PdfPCell(); // cell.setPhrase(new Phrase(modulo.getOrdenmoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL))); // cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); // table.addCell(cell); cell = new PdfPCell(); cell.setPhrase(new Phrase(modulo.getIconomodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL))); cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.addCell(cell); // cell = new PdfPCell(); // cell.setPhrase(new Phrase(modulo.getEstadomoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL))); // cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); // table.addCell(cell); } table.completeRow(); //incia diseo de documento exportado Document document = new Document(PageSize.A4.rotate(), 20, 5, 5, 5); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); document.addTitle("Reporte de Ventas Generales"); document.add( new Paragraph("Reporte: Ventas Generales 2016", new Font(Font.HELVETICA, 16, Font.UNDERLINE))); document.add(new Paragraph("_")); document.add(table); document.add(Chunk.NEWLINE); document.add(new Paragraph( "Leyenda: AB: Inicio, BA: Retorno (Importante: No se consideran unidades sin GPS)")); document.addAuthor("Quispe Roque Alex Christian"); table = new PdfPTable(4); table.setHorizontalAlignment(0); table.setWidthPercentage(40); espaciocolumna = new float[] { 10f, 40f, 20f, 20f }; table.setWidths(espaciocolumna); cell = new PdfPCell(); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setPhrase(new Phrase("RESUMEN", new Font(Font.HELVETICA, 10, Font.BOLD))); cell.setColspan(7); table.addCell(cell); table.completeRow(); //aqui iniciamos asignacion de datos //=================================================================== // cell = new PdfPCell(); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase("", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setBackgroundColor(Color.yellow); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase("FLOTA OPERATIVA", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase(lista.size() + "", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase("UNIDADES", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // table.completeRow(); // // //================================================================================== // cell = new PdfPCell(); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase("2", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setBackgroundColor(Color.yellow); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase("NRO DE VIAJES", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase((totalAB + totalBA) + "", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase("VIAJES", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // // table.completeRow(); //================================================================================== document.add(Chunk.NEWLINE); document.add(table); document.left(1); document.top(1); document.close(); response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); // response.setHeader("Content-Disposition", "attachment; filename=ReporteGeneraldeModulos.pdf"); response.setHeader("Content-Disposition", "filename=ReporteGeneraldeModulos.pdf"); response.setHeader("Pragma", "public"); response.setContentType("application/pdf"); response.setContentLength(baos.size()); ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush(); } catch (Exception e) { RequestDispatcher rd2; rd2 = request.getRequestDispatcher("vista/include/error_404.jsp"); rd2.forward(request, response); System.out.println( "rollyroll.com.servlet.ModuloServlet.exportar_ModulosaPDF() => ERROR GRAVE AL GENERAR PDF"); e.getMessage(); } }
From source file:se.idega.idegaweb.commune.school.business.StudentAddressLabelsWriter.java
License:Open Source License
/** * Creates PDF address labels for the specified school classes. *///from www .j a v a2s. c om protected MemoryFileBuffer getPDFBuffer(IWApplicationContext iwac, Collection receivers) throws Exception { this.business = getSchoolCommuneBusiness(iwac); this.userBusiness = getCommuneUserBusiness(iwac); IWResourceBundle iwrb = iwac.getIWMainApplication().getBundle(CommuneBlock.IW_BUNDLE_IDENTIFIER) .getResourceBundle(iwac.getApplicationSettings().getApplicationLocale()); MemoryFileBuffer buffer = new MemoryFileBuffer(); MemoryOutputStream mos = new MemoryOutputStream(buffer); Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, mos); document.addTitle("Student address labels"); document.addAuthor("Idega Reports"); document.addSubject("Student address labels"); document.open(); this.font = new Font(Font.HELVETICA, 9, Font.BOLD); int studentCount = 0; Iterator iter = receivers.iterator(); while (iter.hasNext()) { if (studentCount > 0 && studentCount % NR_OF_ADDRESSES_PER_PAGE == 0) { document.newPage(); } addAddress(writer, iwrb, (MailReceiver) iter.next(), studentCount++); } if (studentCount == 0) { throw new Exception("No students."); } document.close(); writer.setPdfVersion(PdfWriter.VERSION_1_2); buffer.setMimeType(MIME_PDF); return buffer; }
From source file:se.idega.idegaweb.commune.school.report.business.ReportPDFWriter.java
License:Open Source License
private MemoryFileBuffer getPDFBuffer() throws DocumentException { MemoryFileBuffer buffer = new MemoryFileBuffer(); MemoryOutputStream mos = new MemoryOutputStream(buffer); Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, mos); String titleKey = this._reportModel.getReportTitleLocalizationKey(); String title = localize(titleKey, titleKey); this._normalFont = new Font(Font.HELVETICA, 7, Font.NORMAL); this._boldFont = new Font(Font.HELVETICA, 7, Font.BOLD); document.addTitle(title);// w ww. j a va 2 s . c om document.addAuthor("Agura IT Reports"); document.addSubject(title); document.open(); String dateString = new Date(System.currentTimeMillis()).toString(); document.add(new Phrase(title + " " + dateString + "\n\n", this._boldFont)); document.add(new Phrase("\n", this._boldFont)); int cols = this._reportModel.getColumnSize() + 1; Table table = new Table(cols); this._widths = new int[cols]; for (int i = 0; i < cols; i++) { this._widths[i] = 1; } table.setSpacing(1.5f); buildColumnHeaders(table); buildRowHeaders(table); buildReportCells(table); int totalWidth = 0; for (int i = 0; i < cols; i++) { this._widths[i] += 1; totalWidth += this._widths[i]; } int width = (100 * totalWidth) / 95; if (width > 100) { width = 100; } table.setWidth(width); table.setWidths(this._widths); document.add(table); document.close(); writer.setPdfVersion(PdfWriter.VERSION_1_2); return buffer; }
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 av a 2 s .c o 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.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 {//w ww . j a v a 2 s . co 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 av a 2 s . com*/ 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);//w ww .j ava 2s. c o m cell.addElement(p); cell.setBorder(Rectangle.NO_BORDER); cell.setVerticalAlignment(Rectangle.NO_BORDER); return cell; }
From source file:storemanagment.Printing.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 ww w . jav a 2 s . c o m cell.addElement(p); cell.setBorder(Rectangle.NO_BORDER); return cell; }