List of usage examples for com.lowagie.text.pdf PdfPTable setSpacingAfter
public void setSpacingAfter(float spacing)
From source file:org.sonar.report.pdf.ExecutivePDFReporter.java
License:Open Source License
protected void printDashboard(Project project, Section section) throws DocumentException { // Static Analysis Paragraph staticAnalysis = new Paragraph(getTextProperty("general.static_analysis"), Style.UNDERLINED_FONT); PdfPTable staticAnalysisTable = new PdfPTable(3); staticAnalysisTable.getDefaultCell().setBorderColor(Color.WHITE); PdfPTable linesOfCode = new PdfPTable(1); Style.noBorderTable(linesOfCode); linesOfCode.addCell(new Phrase(getTextProperty("general.lines_of_code"), Style.DASHBOARD_TITLE_FONT)); PdfPTable linesOfCodeTendency = new PdfPTable(2); Style.noBorderTable(linesOfCodeTendency); linesOfCodeTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT); linesOfCodeTendency.addCell(// w ww.j a va2s. co m new Phrase(project.getMeasure(MetricKeys.NCLOC).getFormatValue(), Style.DASHBOARD_DATA_FONT)); linesOfCodeTendency.addCell(getTendencyImage(project.getMeasure(MetricKeys.NCLOC).getQualitativeTendency(), project.getMeasure(MetricKeys.NCLOC).getQuantitativeTendency())); linesOfCode.addCell(linesOfCodeTendency); linesOfCode.addCell(new Phrase(project.getMeasure(MetricKeys.PACKAGES).getFormatValue() + " packages", Style.DASHBOARD_DATA_FONT_2)); linesOfCode.addCell(new Phrase(project.getMeasure(MetricKeys.CLASSES).getFormatValue() + " classes", Style.DASHBOARD_DATA_FONT_2)); linesOfCode.addCell(new Phrase(project.getMeasure(MetricKeys.FUNCTIONS).getFormatValue() + " methods", Style.DASHBOARD_DATA_FONT_2)); linesOfCode.addCell(new Phrase( project.getMeasure(MetricKeys.DUPLICATED_LINES_DENSITY).getFormatValue() + " duplicated lines", Style.DASHBOARD_DATA_FONT_2)); PdfPTable comments = new PdfPTable(1); Style.noBorderTable(comments); comments.addCell(new Phrase(getTextProperty("general.comments"), Style.DASHBOARD_TITLE_FONT)); PdfPTable commentsTendency = new PdfPTable(2); commentsTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT); Style.noBorderTable(commentsTendency); commentsTendency.addCell(new Phrase(project.getMeasure(MetricKeys.COMMENT_LINES_DENSITY).getFormatValue(), Style.DASHBOARD_DATA_FONT)); commentsTendency.addCell( getTendencyImage(project.getMeasure(MetricKeys.COMMENT_LINES_DENSITY).getQualitativeTendency(), project.getMeasure(MetricKeys.COMMENT_LINES_DENSITY).getQuantitativeTendency())); comments.addCell(commentsTendency); comments.addCell( new Phrase(project.getMeasure(MetricKeys.COMMENT_LINES).getFormatValue() + " comment lines", Style.DASHBOARD_DATA_FONT_2)); PdfPTable complexity = new PdfPTable(1); Style.noBorderTable(complexity); complexity.addCell(new Phrase(getTextProperty("general.complexity"), Style.DASHBOARD_TITLE_FONT)); PdfPTable complexityTendency = new PdfPTable(2); complexityTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT); Style.noBorderTable(complexityTendency); complexityTendency.addCell(new Phrase(project.getMeasure(MetricKeys.FUNCTION_COMPLEXITY).getFormatValue(), Style.DASHBOARD_DATA_FONT)); complexityTendency.addCell( getTendencyImage(project.getMeasure(MetricKeys.FUNCTION_COMPLEXITY).getQualitativeTendency(), project.getMeasure(MetricKeys.FUNCTION_COMPLEXITY).getQuantitativeTendency())); complexity.addCell(complexityTendency); complexity.addCell(new Phrase(project.getMeasure(MetricKeys.CLASS_COMPLEXITY).getFormatValue() + " /class", Style.DASHBOARD_DATA_FONT_2)); complexity .addCell(new Phrase(project.getMeasure(MetricKeys.COMPLEXITY).getFormatValue() + " decision points", Style.DASHBOARD_DATA_FONT_2)); staticAnalysisTable.setSpacingBefore(10); staticAnalysisTable.addCell(linesOfCode); staticAnalysisTable.addCell(comments); staticAnalysisTable.addCell(complexity); staticAnalysisTable.setSpacingAfter(20); // Dynamic Analysis Paragraph dynamicAnalysis = new Paragraph(getTextProperty("general.dynamic_analysis"), Style.UNDERLINED_FONT); PdfPTable dynamicAnalysisTable = new PdfPTable(3); Style.noBorderTable(dynamicAnalysisTable); PdfPTable codeCoverage = new PdfPTable(1); Style.noBorderTable(codeCoverage); codeCoverage.addCell(new Phrase(getTextProperty("general.code_coverage"), Style.DASHBOARD_TITLE_FONT)); PdfPTable codeCoverageTendency = new PdfPTable(2); Style.noBorderTable(codeCoverageTendency); codeCoverageTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT); codeCoverageTendency.addCell(new Phrase( project.getMeasure(MetricKeys.COVERAGE).getFormatValue() + " coverage", Style.DASHBOARD_DATA_FONT)); codeCoverageTendency .addCell(getTendencyImage(project.getMeasure(MetricKeys.COVERAGE).getQualitativeTendency(), project.getMeasure(MetricKeys.COVERAGE).getQuantitativeTendency())); codeCoverage.addCell(codeCoverageTendency); codeCoverage.addCell(new Phrase(project.getMeasure(MetricKeys.TESTS).getFormatValue() + " tests", Style.DASHBOARD_DATA_FONT_2)); PdfPTable testSuccess = new PdfPTable(1); Style.noBorderTable(testSuccess); testSuccess.addCell(new Phrase(getTextProperty("general.test_success"), Style.DASHBOARD_TITLE_FONT)); PdfPTable testSuccessTendency = new PdfPTable(2); Style.noBorderTable(testSuccessTendency); testSuccessTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT); testSuccessTendency.addCell(new Phrase(project.getMeasure(MetricKeys.TEST_SUCCESS_DENSITY).getFormatValue(), Style.DASHBOARD_DATA_FONT)); testSuccessTendency.addCell( getTendencyImage(project.getMeasure(MetricKeys.TEST_SUCCESS_DENSITY).getQualitativeTendency(), project.getMeasure(MetricKeys.TEST_SUCCESS_DENSITY).getQuantitativeTendency())); testSuccess.addCell(testSuccessTendency); testSuccess.addCell(new Phrase(project.getMeasure(MetricKeys.TEST_FAILURES).getFormatValue() + " failures", Style.DASHBOARD_DATA_FONT_2)); testSuccess.addCell(new Phrase(project.getMeasure(MetricKeys.TEST_ERRORS).getFormatValue() + " errors", Style.DASHBOARD_DATA_FONT_2)); dynamicAnalysisTable.setSpacingBefore(10); dynamicAnalysisTable.addCell(codeCoverage); dynamicAnalysisTable.addCell(testSuccess); dynamicAnalysisTable.addCell(""); dynamicAnalysisTable.setSpacingAfter(20); Paragraph codingRulesViolations = new Paragraph(getTextProperty("general.coding_rules_violations"), Style.UNDERLINED_FONT); PdfPTable codingRulesViolationsTable = new PdfPTable(3); Style.noBorderTable(codingRulesViolationsTable); PdfPTable rulesCompliance = new PdfPTable(1); Style.noBorderTable(rulesCompliance); rulesCompliance .addCell(new Phrase(getTextProperty("general.rules_compliance"), Style.DASHBOARD_TITLE_FONT)); PdfPTable rulesComplianceTendency = new PdfPTable(2); Style.noBorderTable(rulesComplianceTendency); rulesComplianceTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT); rulesComplianceTendency.addCell(new Phrase( project.getMeasure(MetricKeys.VIOLATIONS_DENSITY).getFormatValue(), Style.DASHBOARD_DATA_FONT)); // Workarround for avoid resizing Image tendencyRulesResize = getTendencyImage( project.getMeasure(MetricKeys.VIOLATIONS_DENSITY).getQualitativeTendency(), project.getMeasure(MetricKeys.VIOLATIONS_DENSITY).getQuantitativeTendency()); tendencyRulesResize.scaleAbsolute(Style.TENDENCY_ICONS_HEIGHT, Style.TENDENCY_ICONS_HEIGHT); PdfPCell tendencyRulesCell = new PdfPCell(tendencyRulesResize); tendencyRulesCell.setBorder(0); rulesComplianceTendency.addCell(tendencyRulesCell); rulesCompliance.addCell(rulesComplianceTendency); PdfPTable violations = new PdfPTable(1); Style.noBorderTable(violations); violations.addCell(new Phrase(getTextProperty("general.violations"), Style.DASHBOARD_TITLE_FONT)); PdfPTable violationsTendency = new PdfPTable(2); Style.noBorderTable(violationsTendency); violationsTendency.getDefaultCell().setFixedHeight(Style.TENDENCY_ICONS_HEIGHT); violationsTendency.addCell( new Phrase(project.getMeasure(MetricKeys.VIOLATIONS).getFormatValue(), Style.DASHBOARD_DATA_FONT)); // Workarround for avoid resizing Image tendencyResize = getTendencyImage(project.getMeasure(MetricKeys.VIOLATIONS).getQualitativeTendency(), project.getMeasure(MetricKeys.VIOLATIONS).getQuantitativeTendency()); tendencyResize.scaleAbsolute(Style.TENDENCY_ICONS_HEIGHT, Style.TENDENCY_ICONS_HEIGHT); PdfPCell tendencyCell = new PdfPCell(tendencyResize); tendencyCell.setBorder(0); violationsTendency.addCell(tendencyCell); violations.addCell(violationsTendency); codingRulesViolationsTable.setSpacingBefore(10); codingRulesViolationsTable.addCell(rulesCompliance); codingRulesViolationsTable.addCell(violations); codingRulesViolationsTable.addCell(""); codingRulesViolationsTable.setSpacingAfter(20); section.add(Chunk.NEWLINE); section.add(staticAnalysis); section.add(staticAnalysisTable); section.add(dynamicAnalysis); section.add(dynamicAnalysisTable); section.add(codingRulesViolations); section.add(codingRulesViolationsTable); }
From source file:org.sonar.report.pdf.Header.java
License:Open Source License
public void onEndPage(PdfWriter writer, Document document) { try {/* w w w.j a v a 2s .c o m*/ Image logoImage = Image.getInstance(logo); Rectangle page = document.getPageSize(); PdfPTable head = new PdfPTable(4); head.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); head.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); head.addCell(logoImage); Phrase projectName = new Phrase(project.getName(), FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY)); Phrase phrase = new Phrase("Sonar PDF Report", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY)); head.getDefaultCell().setColspan(2); head.addCell(phrase); head.getDefaultCell().setColspan(1); head.addCell(projectName); head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - 20, writer.getDirectContent()); head.setSpacingAfter(10); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.sonar.report.pdf.Style.java
License:Open Source License
/** * This method makes a simple table with content. * //from w w w. j a va 2 s . c o m * @param left Data for left column * @param right Data for right column * @param title The table title * @param noData Showed when left or right are empty * @return The table (iText table) ready to add to the document */ public static PdfPTable createSimpleTable(List<String> left, List<String> right, String title, String noData) { PdfPTable table = new PdfPTable(2); table.getDefaultCell().setColspan(2); table.addCell(new Phrase(title, Style.DASHBOARD_TITLE_FONT)); table.getDefaultCell().setBackgroundColor(Color.GRAY); table.addCell(""); table.getDefaultCell().setColspan(1); table.getDefaultCell().setBackgroundColor(Color.WHITE); Iterator<String> itLeft = left.iterator(); Iterator<String> itRight = right.iterator(); while (itLeft.hasNext()) { String textLeft = itLeft.next(); String textRight = itRight.next(); table.addCell(textLeft); table.addCell(textRight); } if (left.isEmpty()) { table.getDefaultCell().setColspan(2); table.addCell(noData); } table.setSpacingBefore(20); table.setSpacingAfter(20); return table; }
From source file:org.sonar.report.pdf.Style.java
License:Open Source License
public static PdfPTable createTwoColumnsTitledTable(List<String> titles, List<String> content) { PdfPTable table = new PdfPTable(10); Iterator<String> itLeft = titles.iterator(); Iterator<String> itRight = content.iterator(); while (itLeft.hasNext()) { String textLeft = itLeft.next(); String textRight = itRight.next(); table.getDefaultCell().setColspan(1); table.addCell(textLeft);// ww w . j av a 2s . com table.getDefaultCell().setColspan(9); table.addCell(textRight); } table.setSpacingBefore(20); table.setSpacingAfter(20); table.setLockedWidth(false); table.setWidthPercentage(90); return table; }
From source file:org.sonar.report.pdf.TeamWorkbookPDFReporter.java
License:Open Source License
private PdfPTable createViolationsDetailedTable(String ruleName, List<String> files, List<String> lines) { // TODO: internationalize this PdfPTable table = new PdfPTable(10); Iterator<String> itLeft = files.iterator(); Iterator<String> itRight = lines.iterator(); table.getDefaultCell().setColspan(1); table.getDefaultCell().setBackgroundColor(new Color(255, 228, 181)); table.addCell(new Phrase("Rule", Style.NORMAL_FONT)); table.getDefaultCell().setColspan(9); table.getDefaultCell().setBackgroundColor(Color.WHITE); table.addCell(new Phrase(ruleName, Style.NORMAL_FONT)); table.getDefaultCell().setColspan(10); table.getDefaultCell().setBackgroundColor(Color.GRAY); table.addCell(""); table.getDefaultCell().setColspan(7); table.getDefaultCell().setBackgroundColor(new Color(255, 228, 181)); table.addCell(new Phrase("File", Style.NORMAL_FONT)); table.getDefaultCell().setColspan(3); table.addCell(new Phrase("Line", Style.NORMAL_FONT)); table.getDefaultCell().setBackgroundColor(Color.WHITE); int i = 0;//from w w w . j ava 2 s. co m String lineNumbers = ""; while (i < files.size() - 1) { if (lineNumbers.equals("")) { lineNumbers += lines.get(i); } else { lineNumbers += ", " + lines.get(i); } if (!files.get(i).equals(files.get(i + 1))) { table.getDefaultCell().setColspan(7); table.addCell(files.get(i)); table.getDefaultCell().setColspan(3); table.addCell(lineNumbers); lineNumbers = ""; } i++; } table.getDefaultCell().setColspan(7); table.addCell(files.get(files.size() - 1)); table.getDefaultCell().setColspan(3); if (lineNumbers.equals("")) { lineNumbers += lines.get(i); } else { lineNumbers += ", " + lines.get(lines.size() - 1); } table.addCell(lineNumbers); table.setSpacingBefore(20); table.setSpacingAfter(20); table.setLockedWidth(false); table.setWidthPercentage(90); return table; }
From source file:org.sonarqube.report.extendedpdf.ExtendedHeader.java
License:Open Source License
public void onEndPage(PdfWriter writer, Document document) { String pageTemplate = "/templates/page.pdf"; try {//from www .ja v a 2 s. c o m PdfContentByte cb = writer.getDirectContentUnder(); PdfReader reader = new PdfReader(this.getClass().getResourceAsStream(pageTemplate)); PdfImportedPage page = writer.getImportedPage(reader, 1); cb.addTemplate(page, 0, 0); Font font = FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY); Rectangle pageSize = document.getPageSize(); PdfPTable head = new PdfPTable(1); head.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); head.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); head.getDefaultCell().setBorder(0); Phrase projectName = new Phrase(project.getName(), font); head.addCell(projectName); head.setTotalWidth(pageSize.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin(), pageSize.getHeight() - 15, writer.getDirectContent()); head.setSpacingAfter(10); PdfPTable foot = new PdfPTable(1); foot.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); foot.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); foot.getDefaultCell().setBorder(0); SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm"); Phrase projectAnalysisDate = new Phrase(df.format(project.getMeasures().getDate()), font); foot.addCell(projectAnalysisDate); foot.setTotalWidth(pageSize.getWidth() - document.leftMargin() - document.rightMargin()); foot.writeSelectedRows(0, -1, document.leftMargin(), 20, writer.getDirectContent()); foot.setSpacingBefore(10); } catch (IOException e) { Logger.error("Cannot find the required template: " + pageTemplate); e.printStackTrace(); } }
From source file:org.sonarqube.report.extendedpdf.OverviewPDFReporter.java
License:Open Source License
protected void printFrontPage(Document frontPageDocument, PdfWriter frontPageWriter) throws org.dom4j.DocumentException, ReportException { String frontPageTemplate = "/templates/frontpage.pdf"; try {//from w ww . j av a 2s .c om PdfContentByte cb = frontPageWriter.getDirectContent(); PdfReader reader = new PdfReader(this.getClass().getResourceAsStream(frontPageTemplate)); PdfImportedPage page = frontPageWriter.getImportedPage(reader, 1); frontPageDocument.newPage(); cb.addTemplate(page, 0, 0); Project project = getProject(); Rectangle pageSize = frontPageDocument.getPageSize(); PdfPTable projectInfo = new PdfPTable(1); projectInfo.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); projectInfo.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); projectInfo.getDefaultCell().setBorder(Rectangle.BOTTOM); projectInfo.getDefaultCell().setPaddingBottom(10); projectInfo.getDefaultCell().setBorderColor(Color.GRAY); Font font = FontFactory.getFont(FontFactory.COURIER, 18, Font.NORMAL, Color.LIGHT_GRAY); Phrase projectName = new Phrase("Project: " + project.getName(), font); projectInfo.addCell(projectName); Phrase projectVersion = new Phrase("Version: " + project.getMeasures().getVersion(), font); projectInfo.addCell(projectVersion); SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm"); Phrase projectAnalysisDate = new Phrase("Analysis Date: " + df.format(project.getMeasures().getDate()), font); projectInfo.addCell(projectAnalysisDate); projectInfo.setTotalWidth( pageSize.getWidth() - frontPageDocument.leftMargin() * 2 - frontPageDocument.rightMargin() * 2); projectInfo.writeSelectedRows(0, -1, frontPageDocument.leftMargin(), pageSize.getHeight() - 575, frontPageWriter.getDirectContent()); projectInfo.setSpacingAfter(10); } catch (IOException e) { Logger.error("Cannot find the required template: " + frontPageTemplate); e.printStackTrace(); } }
From source file:org.viafirma.util.QRCodeUtil.java
License:Apache License
/** * @param texto//from w w w .java 2 s . c o m * Texto a colocar * @param textoQR * Imagen QR a colocar * @param codFirma * Cdigo de Firma a generar. * @param url Url del servicio de verificacin desde donde se puede descargar el documento. * @param document * Documeto destino * @param pageSize * Tamao de la pgina * @return * @throws BadElementException * @throws MalformedURLException * @throws IOException * @throws DocumentException * @throws ExcepcionErrorInterno */ private static float addContent(String texto, String url, String textoQR, String codFirma, Document document, Rectangle pageSize, boolean completo, boolean isSellado) throws BadElementException, MalformedURLException, IOException, DocumentException, ExcepcionErrorInterno { Image imagenCabezera = null; float widthCabecera = 0; float heightCabecera = 0; if (!isSellado) { // Recuperamos la imagen de cabecera imagenCabezera = Image.getInstance(QRCodeUtil.class.getResource(IMAGE_CABECERA)); // Colocamos la imagen en la zona superior de la pgina imagenCabezera.setAbsolutePosition(0, pageSize.getHeight() - imagenCabezera.getHeight()); heightCabecera = imagenCabezera.getHeight(); widthCabecera = imagenCabezera.getWidth(); } // Recuperamos el pie de firma Image imagenQR = Image.getInstance(QRCodeUtil.getInstance().generate(texto, url, textoQR, codFirma)); float rescalado = pageSize.getWidth() / (widthCabecera + document.leftMargin() + document.rightMargin()); float sizeCabecera = 0; if (rescalado < 1f && !isSellado) { // Requiere rescalado, la imagen es mayor que la pgina. imagenCabezera.scalePercent(rescalado * 100); sizeCabecera = rescalado * imagenCabezera.getHeight(); } float sizeCabecerayPie = HEIGHT_QR_CODE_PDF + sizeCabecera + document.bottomMargin() + document.topMargin() + SPACE_SEPARACION; // float escaleQR = HEIGHT_QR_CODE_PDF / (imagenQR.getHeight() + 5); float escaleQR = (pageSize.getWidth() - document.leftMargin() - document.rightMargin()) / (imagenQR.getWidth() + 6); // imagen.setSpacingAfter(120); if (!isSellado) { document.add(imagenCabezera); } // Aadimos una caja de texto si estamos mostrando el contenido del // fichero firmado. if (completo) { // Aadimos el espacio ocupado por la imagen Paragraph p = new Paragraph(""); p.setSpacingAfter(heightCabecera * rescalado); document.add(p); // Aadimos una tabla con borde donde colocar el documento. PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); table.getDefaultCell().setBorderWidth(10); PdfPCell celda = new PdfPCell(); celda.setFixedHeight(pageSize.getHeight() - sizeCabecerayPie); table.addCell(celda); table.setSpacingAfter(SPACE_SEPARACION); document.add(table); } if (completo) { // La imagen la colocamos justo debajo imagenQR.setAbsolutePosition(document.leftMargin(), escaleQR * HEIGHT_QR_CODE_PDF - SPACE_SEPARACION * 2); } else { imagenQR.setAbsolutePosition(document.leftMargin(), pageSize.getHeight() - sizeCabecerayPie); } imagenQR.scalePercent(escaleQR * 100); document.add(imagenQR); return sizeCabecerayPie; }
From source file:sms.ReportForms.java
public void utext(String query, String Name, String dob, String house, String formclass, String kcpe, String imgurl, String kcpegrade, String id) { methods nn = new methods(); String u = unig();/*from w w w . jav a 2s . c o m*/ checkPreviousResults(u, kcpe, kcpegrade, id); ArrayList<ExamDbDataHolder> users = selectExamResults(u, query); if (users.size() < 2) { Form1Exams n = new Form1Exams(); String[] Subjects = n.findSubjectid(); String[] Subjectsnames = n.findSubjectname(); 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 { Document pdfp = new Document(); PdfWriter w = PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(), "" + sid.getText() + ".pdf"))); pdfp.open(); PdfContentByte canvas = w.getDirectContentUnder(); Image imgb = Image.getInstance("C:\\Users\\kimani kogi\\Pictures\\icons\\logo.png"); imgb.setAbsolutePosition(2, 2); imgb.scaleAbsoluteHeight(PageSize.A4.getHeight() / 4); imgb.scaleAbsoluteWidth(PageSize.A4.getWidth() / 4); canvas.saveState(); PdfGState state = new PdfGState(); state.setFillOpacity(0.6f); canvas.setGState(state); canvas.addImage(imgb); canvas.restoreState(); PdfPTable tbl1 = new PdfPTable(2); // tbl.setWidthPercentage(100); tbl1.setTotalWidth(575); tbl1.setLockedWidth(true); tbl1.setWidths(new int[] { 1, 4 }); if (imgurl.equals("image")) { tbl1.addCell("no image "); String img = imgurl; } else { tbl1.addCell(createImageCell(imgurl)); } tbl1.addCell(createTextCell(schooldetails)); PdfPTable tbl = new PdfPTable(8); // tbl.setWidthPercentage(100); tbl.setTotalWidth(575); tbl.setLockedWidth(true); tbl.setSpacingBefore(8); tbl.setSpacingAfter(6); tbl.getDefaultCell().setBorderWidthTop(2); tbl.getDefaultCell().setBorderWidthLeft(0); tbl.getDefaultCell().setBorderWidthRight(0); tbl.setWidths(new int[] { 1, 1, 1, 2, 1, 1, 1, 1 }); tbl.addCell("Adm No:"); tbl.addCell(sid.getText()); tbl.addCell("Name:"); tbl.addCell(Name); tbl.addCell("Form:"); tbl.addCell(formclass); tbl.addCell("Kcpe:"); tbl.addCell(kcpe); tbl.addCell("House:"); tbl.addCell(house); tbl.addCell("Term:"); tbl.addCell("Second term"); tbl.addCell("Year:"); tbl.addCell("2017"); tbl.addCell("DOB:"); tbl.addCell(dob); PdfPTable tbl2 = new PdfPTable(5); // tbl.setWidthPercentage(100); tbl2.setTotalWidth(575); tbl2.setLockedWidth(true); // tbl2.getDefaultCell().setFixedHeight(35f); tbl2.setWidths(new int[] { 2, 1, 1, 2, 2 }); tbl2.addCell(creatTextCellHeader("Subjects")); tbl2.addCell(creatTextCellHeader("Exams")); tbl2.addCell(creatTextCellHeader("Grade")); tbl2.addCell(creatTextCellHeader("Ratings")); tbl2.addCell(creatTextCellHeader("Remarks")); // String [] Subjectsnames=n.findSubjectname(); for (int i = 0; i < users.size(); i++) { for (int a = 0; a < Subjectsnames.length; a++) { tbl2.addCell(Subjectsnames[a]); String re = null; if (Subjects[a].equals("s1")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getMathematics()); re = ((ExamDbDataHolder) users.get(i)).getMathematics(); // JOptionPane.showMessageDialog(null,((ExamDbDataHolder)users.get(i)).getMathematics()); // String maths = ((ExamDbDataHolder)users.get(i)).getMathematics(); } else if (Subjects[a].equals("s2")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getEnglish()); re = ((ExamDbDataHolder) users.get(i)).getEnglish(); //row[c] = ((ExamDbDataHolder)users.get(i)).getEnglish(); // c++; } else if (Subjects[a].equals("s3")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getKiswahili()); re = ((ExamDbDataHolder) users.get(i)).getKiswahili(); // row[c] = ((ExamDbDataHolder)users.get(i)).getKiswahili(); // c++; } else if (Subjects[a].equals("s4")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getPhysics()); re = ((ExamDbDataHolder) users.get(i)).getPhysics(); // row[c] = ((ExamDbDataHolder)users.get(i)).getPhysics(); // c++; } else if (Subjects[a].equals("s5")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getChemistry()); re = ((ExamDbDataHolder) users.get(i)).getChemistry(); // row[c] = ((ExamDbDataHolder)users.get(i)).getChemistry(); // c++; } else if (Subjects[a].equals("s6")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getBiology()); re = ((ExamDbDataHolder) users.get(i)).getBiology(); // row[c] = ((ExamDbDataHolder)users.get(i)).getBiology(); // c++; } else if (Subjects[a].equals("s7")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getHistory()); re = ((ExamDbDataHolder) users.get(i)).getHistory(); // row[c] = ((ExamDbDataHolder)users.get(i)).getHistory(); // c++; } else if (Subjects[a].equals("s8")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getGeography()); re = ((ExamDbDataHolder) users.get(i)).getGeography(); // row[c] = ((ExamDbDataHolder)users.get(i)).getGeography(); // c++; } else if (Subjects[a].equals("s9")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getCre()); re = ((ExamDbDataHolder) users.get(i)).getCre(); // row[c] = ((ExamDbDataHolder)users.get(i)).getCre(); // c++; } else if (Subjects[a].equals("s10")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getIre()); re = ((ExamDbDataHolder) users.get(i)).getIre(); // row[c] = ((ExamDbDataHolder)users.get(i)).getIre(); // c++; } else if (Subjects[a].equals("s11")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getHre()); re = ((ExamDbDataHolder) users.get(i)).getHre(); // row[c] = ((ExamDbDataHolder)users.get(i)).getHre(); // c++; } else if (Subjects[a].equals("s12")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getAgriculture()); re = ((ExamDbDataHolder) users.get(i)).getAgriculture(); // row[c] = ((ExamDbDataHolder)users.get(i)).getAgriculture(); // c++; } else if (Subjects[a].equals("s13")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getHomescience()); re = ((ExamDbDataHolder) users.get(i)).getHomescience(); // row[c] = ((ExamDbDataHolder)users.get(i)).getHomescience(); // c++; } else if (Subjects[a].equals("s14")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getArtdesign()); re = ((ExamDbDataHolder) users.get(i)).getArtdesign(); // row[c] = ((ExamDbDataHolder)users.get(i)).getArtdesign(); // c++; } else if (Subjects[a].equals("s15")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getComputer()); re = ((ExamDbDataHolder) users.get(i)).getComputer(); // row[c] = ((ExamDbDataHolder)users.get(i)).getComputer(); // c++; } else if (Subjects[a].equals("s16")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getBuilding()); re = ((ExamDbDataHolder) users.get(i)).getBuilding(); // row[c] = ((ExamDbDataHolder)users.get(i)).getBuilding(); // c++; } else if (Subjects[a].equals("s17")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getWoodwork()); re = ((ExamDbDataHolder) users.get(i)).getWoodwork(); // row[c] = ((ExamDbDataHolder)users.get(i)).getWoodwork(); // c++; } else if (Subjects[a].equals("s18")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getMetalwork()); re = ((ExamDbDataHolder) users.get(i)).getMetalwork(); // row[c] = ((ExamDbDataHolder)users.get(i)).getMetalwork(); // c++; } else if (Subjects[a].equals("s19")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getMusic()); re = ((ExamDbDataHolder) users.get(i)).getMusic(); // row[c] = ((ExamDbDataHolder)users.get(i)).getMusic(); // c++; } else if (Subjects[a].equals("s20")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getFrench()); re = ((ExamDbDataHolder) users.get(i)).getFrench(); // row[c] = ((ExamDbDataHolder)users.get(i)).getFrench(); // c++; } else if (Subjects[a].equals("s21")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getGerman()); re = ((ExamDbDataHolder) users.get(i)).getGerman(); // row[c] = ((ExamDbDataHolder)users.get(i)).getGerman(); // c++; } else if (Subjects[a].equals("s22")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getArabic()); re = ((ExamDbDataHolder) users.get(i)).getArabic(); // row[c] = ((ExamDbDataHolder)users.get(i)).getArabic(); // c++; } else if (Subjects[a].equals("s23")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getBusiness()); re = ((ExamDbDataHolder) users.get(i)).getBusiness(); // row[c] = ((ExamDbDataHolder)users.get(i)).getBusiness(); // c++; } String[] gr = nn.checkGrade(re, Subjects[a]); tbl2.addCell(gr[0]); tbl2.addCell(gr[1]); tbl2.addCell(""); } } //add for all other subjects PdfPTable tbl3 = new PdfPTable(4); // tbl.setWidthPercentage(100); tbl3.setTotalWidth(575); tbl3.setLockedWidth(true); tbl3.setSpacingBefore(8); tbl3.setSpacingAfter(6); // tbl3.getDefaultCell().setBorderWidthTop(0); tbl3.getDefaultCell().setBorder(0); // tbl3.getDefaultCell().setBorderWidthLeft(0); // tbl3.getDefaultCell().setBorderWidthRight(0); tbl3.setWidths(new int[] { 1, 1, 1, 1 }); tbl3.addCell(creatTextCellHeader("CURRENT MARKS:")); tbl3.addCell(creatTextCellHeader(String.valueOf(((ExamDbDataHolder) users.get(0)).getTotal()))); float g = Float.valueOf(((ExamDbDataHolder) users.get(0)).getTotal()); // tbl.addCell(String.format("%.1f", g)); String gr = nn.checkGrade(yearid, String.format("%.1f", g / getYear())); tbl3.addCell(creatTextCellHeader("PREVIOUS MARKS:")); tbl3.addCell(creatTextCellHeader("459")); tbl3.addCell(creatTextCellHeader("AVERAGE MARKS:")); tbl3.addCell(creatTextCellHeader(String.format("%.1f", g / getYear()))); tbl3.addCell(creatTextCellHeader("PREVIOUS AVERAGE:")); tbl3.addCell(creatTextCellHeader("50")); tbl3.addCell(creatTextCellHeader("MEAN GRADE:")); tbl3.addCell(creatTextCellHeader(gr)); tbl3.addCell(creatTextCellHeader("PREVIOUS MEAN GRADE:")); tbl3.addCell(creatTextCellHeader("B")); tbl3.addCell(creatTextCellHeader("POS")); tbl3.addCell(creatTextCellHeader("3 ")); tbl3.addCell(creatTextCellHeader("OUT OF")); tbl3.addCell(creatTextCellHeader("79")); PdfPTable tbl4 = new PdfPTable(2); // tbl.setWidthPercentage(100); tbl4.setHorizontalAlignment(0); //tbl4.HorizontalAlignment=Element.ALIGN_LEFT; tbl4.setTotalWidth(575 / 2); tbl4.setLockedWidth(true); tbl4.setSpacingBefore(8); tbl4.setSpacingAfter(6); // tbl3.getDefaultCell().setBorderWidthTop(0); tbl4.getDefaultCell().setBorder(0); // tbl3.getDefaultCell().setBorderWidthLeft(0); // tbl3.getDefaultCell().setBorderWidthRight(0); tbl4.setWidths(new int[] { 2, 1 }); PdfPCell cell = new PdfPCell(new Paragraph("REMARKS")); cell.setColspan(2); tbl4.addCell(cell); tbl4.addCell(creatTextCellHeader( "CLASS TEACHERS........................................................." + ":............................\n\n\n")); tbl4.addCell(creatTextCellChart("chart")); tbl4.addCell(creatTextCellHeader( "SIGNATURE-------------------------------------------------------------" + "-------------------------------\n\n\n")); tbl4.addCell(creatTextCellHeader( "-------------\n\n\n-----------------------------------------------------------" + "-----------------------------")); pdfp.add(tbl1); pdfp.add(tbl); pdfp.add(tbl2); pdfp.add(tbl3); pdfp.add(tbl4); // 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; pdfp.close(); } catch (Exception j) { j.printStackTrace(); } // Image img=new Image.getInstance("j.png"); } } }
From source file:storemanagment.Printing.java
public final void TransactionGiven(String transactionReceiptNo, String officer, ArrayList<CartPojo> items) { Calendar c = Calendar.getInstance(); Date today = c.getTime();//from ww w . jav a2 s. c o m java.util.Date d = (today); java.sql.Date DATE = new java.sql.Date(d.getTime()); // String OrgDetails=res[1]+"\n"+DATE.toString(); String orgDetails[] = getRes(); String orgImg = orgDetails[0]; String orgAbout = orgDetails[1]; 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(null) == JFileChooser.APPROVE_OPTION) { try { Document pdfp = new Document(); PdfWriter writer = PdfWriter.getInstance(pdfp, new FileOutputStream( new File(chooser.getSelectedFile(), transactionReceiptNo + "" + DATE + ".pdf"))); // PdfWriter writer = PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(),"Group "+jComboBoxGroup.getSelectedItem().toString()+".pdf"))); HeaderFooterPageEvent event = new HeaderFooterPageEvent(officer, transactionReceiptNo, DATE); writer.setPageEvent(event); pdfp.open(); // Document pdfp=new Document(); // PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(),transactionReceiptNo+""+DATE+".pdf"))); // pdfp.open(); PdfPTable header1 = new PdfPTable(1); // // tbl.setWidthPercentage(100); // header1.setTotalWidth(575); header1.setLockedWidth(true); header1.addCell(createTextCell("")); header1.addCell(createTextCell("")); header1.addCell(createTextCell("")); header1.addCell(createTextCell("")); PdfPTable header = new PdfPTable(3); // // tbl.setWidthPercentage(100); // header.setTotalWidth(575); header.setLockedWidth(true); header.setWidths(new int[] { 1, 4, 1 }); //THE FIRST ROW //first column ///Logo if (orgImg.equals("image")) { header.addCell("no image "); } else { header.addCell(createImageCell(orgImg)); } //second column ///description header.addCell(createTextCell(orgAbout)); header.addCell(createTextCell("")); PdfPTable RecieptTilte = new PdfPTable(3); // // tbl.setWidthPercentage(100); // RecieptTilte.setTotalWidth(575); RecieptTilte.setLockedWidth(true); // RecieptTilte.setHorizontalAlignment(Align.CENTER); RecieptTilte.setWidths(new int[] { 1, 1, 1 }); RecieptTilte.setSpacingBefore(8); RecieptTilte.setSpacingAfter(6); // RecieptTilte.getDefaultCell().setBorderWidthBottom(2); RecieptTilte.getDefaultCell().setBorderWidthLeft(0); RecieptTilte.getDefaultCell().setBorderWidthRight(0); RecieptTilte.addCell(""); RecieptTilte.addCell("Transaction Receipt"); RecieptTilte.setSpacingAfter(8); RecieptTilte.addCell(""); PdfPTable RecieptitemsTitles = new PdfPTable(3); RecieptitemsTitles.setTotalWidth(575); RecieptitemsTitles.setWidths(new int[] { 2, 1, 1 }); RecieptitemsTitles.setLockedWidth(true); RecieptitemsTitles.addCell(creatTextCellTitles("Item-Name")); RecieptitemsTitles.addCell(creatTextCellTitles("Quantiy")); RecieptitemsTitles.addCell(creatTextCellTitles("Unit")); // RecieptitemsTitles.addCell(creatTextCellTitles("Id")); // PdfPTable Recieptitems=new PdfPTable(4); for (int a = 0; a < items.size(); a++) { RecieptitemsTitles.addCell(createTextCellcolor(((CartPojo) items.get(a)).getItem_name(), a)); RecieptitemsTitles .addCell(createTextCellcolor(((CartPojo) items.get(a)).getTransaction_quantity(), a)); RecieptitemsTitles.addCell( createTextCellcolor(((CartPojo) items.get(a)).getTransaction_quantity_in(), a)); // RecieptitemsTitles.addCell(createTextCellcolor(String.valueOf(((CartPojo)items.get(a)).getItem_id()),a)); } pdfp.add(header1); pdfp.add(header); pdfp.add(RecieptTilte); pdfp.add(RecieptitemsTitles); pdfp.close(); } catch (DocumentException ex) { Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex); } // jComboBoxGroup if (Desktop.isDesktopSupported()) { try { File file = new File(chooser.getSelectedFile(), transactionReceiptNo + "" + DATE + ".pdf"); Desktop.getDesktop().open(file); } catch (Exception ex) { ex.printStackTrace(); } } } }