List of usage examples for com.lowagie.text.pdf PdfGState setFillOpacity
public void setFillOpacity(float n)
From source file:org.mapfish.print.map.renderers.SVGMapRenderer.java
License:Open Source License
public void render(Transformer transformer, java.util.List<URI> uris, PdfContentByte dc, RenderingContext context, float opacity, int nbTilesHorizontal, float offsetX, float offsetY, long bitmapTileW, long bitmapTileH) throws IOException { if (uris.size() != 1) { //tiling not supported in SVG throw new InvalidValueException("format", "application/x-pdf"); }//from ww w.ja va 2 s . c o m dc.saveState(); try { dc.transform(transformer.getSvgTransform()); if (opacity < 1.0) { PdfGState gs = new PdfGState(); gs.setFillOpacity(opacity); gs.setStrokeOpacity(opacity); //gs.setBlendMode(PdfGState.BM_SOFTLIGHT); dc.setGState(gs); } Graphics2D g2 = dc.createGraphics(transformer.getRotatedSvgW(), transformer.getRotatedSvgH()); //avoid a warning from Batik System.setProperty("org.apache.batik.warn_destination", "false"); g2.setRenderingHint(RenderingHintsKeyExt.KEY_TRANSCODING, RenderingHintsKeyExt.VALUE_TRANSCODING_PRINTING); g2.setRenderingHint(RenderingHintsKeyExt.KEY_AVOID_TILE_PAINTING, RenderingHintsKeyExt.VALUE_AVOID_TILE_PAINTING_ON); final URI uri = uris.get(0); LOGGER.debug(uri); final TranscoderInput ti = getTranscoderInput(uri.toURL(), transformer, context); if (ti != null) { PrintTranscoder pt = new PrintTranscoder(); pt.transcode(ti, null); Paper paper = new Paper(); paper.setSize(transformer.getRotatedSvgW(), transformer.getRotatedSvgH()); paper.setImageableArea(0, 0, transformer.getRotatedSvgW(), transformer.getRotatedSvgH()); PageFormat pf = new PageFormat(); pf.setPaper(paper); pt.print(g2, pf, 0); } g2.dispose(); } finally { dc.restoreState(); } }
From source file:org.mapfish.print.map.renderers.SVGTileRenderer.java
License:Open Source License
public void render(final Transformer transformer, java.util.List<URI> uris, ParallelMapTileLoader parallelMapTileLoader, final RenderingContext context, final float opacity, int nbTilesHorizontal, float offsetX, float offsetY, long bitmapTileW, long bitmapTileH) throws IOException { if (uris.size() != 1) { //tiling not supported in SVG throw new InvalidValueException("format", "application/x-pdf"); }//from www . ja v a2 s. c o m final URI uri = uris.get(0); parallelMapTileLoader.addTileToLoad(new MapTileTask() { public PrintTranscoder pt; @Override protected void readTile() throws IOException, DocumentException { LOGGER.debug(uri); final TranscoderInput ti = getTranscoderInput(uri.toURL(), transformer, context); if (ti != null) { pt = new PrintTranscoder(); pt.transcode(ti, null); } } @Override protected void renderOnPdf(PdfContentByte dc) throws DocumentException { dc.transform(transformer.getSvgTransform()); if (opacity < 1.0) { PdfGState gs = new PdfGState(); gs.setFillOpacity(opacity); gs.setStrokeOpacity(opacity); //gs.setBlendMode(PdfGState.BM_SOFTLIGHT); dc.setGState(gs); } Graphics2D g2 = dc.createGraphics(transformer.getRotatedSvgW(), transformer.getRotatedSvgH()); //avoid a warning from Batik System.setProperty("org.apache.batik.warn_destination", "false"); g2.setRenderingHint(RenderingHintsKeyExt.KEY_TRANSCODING, RenderingHintsKeyExt.VALUE_TRANSCODING_PRINTING); g2.setRenderingHint(RenderingHintsKeyExt.KEY_AVOID_TILE_PAINTING, RenderingHintsKeyExt.VALUE_AVOID_TILE_PAINTING_ON); Paper paper = new Paper(); paper.setSize(transformer.getRotatedSvgW(), transformer.getRotatedSvgH()); paper.setImageableArea(0, 0, transformer.getRotatedSvgW(), transformer.getRotatedSvgH()); PageFormat pf = new PageFormat(); pf.setPaper(paper); pt.print(g2, pf, 0); g2.dispose(); } }); }
From source file:org.mapfish.print.map.renderers.vector.PointRenderer.java
License:Open Source License
protected void renderImpl(RenderingContext context, PdfContentByte dc, PJsonObject style, Point geometry) { PdfGState state = new PdfGState(); final Coordinate coordinate = geometry.getCoordinate(); float pointRadius = style.optFloat("pointRadius", 4.0f); final float f = context.getStyleFactor(); String graphicName = style.optString("graphicName"); float width = style.optFloat("graphicWidth", pointRadius * 2.0f); float height = style.optFloat("graphicHeight", pointRadius * 2.0f); float offsetX = style.optFloat("graphicXOffset", -width / 2.0f); float offsetY = style.optFloat("graphicYOffset", -height / 2.0f); // See Feature/Vector.js for more information about labels String label = style.optString("label"); String labelAlign = style.optString("labelAlign", "lb"); /*// ww w . j ava 2 s. c o m * Valid values for horizontal alignment: "l"=left, "c"=center, "r"=right. * Valid values for vertical alignment: "t"=top, "m"=middle, "b"=bottom. */ float labelXOffset = style.optFloat("labelXOffset", (float) 0.0); float labelYOffset = style.optFloat("labelYOffset", (float) 0.0); String fontColor = style.optString("fontColor", "#000000"); /* Supported itext fonts: COURIER, HELVETICA, TIMES_ROMAN */ String fontFamily = style.optString("fontFamily", "HELVETICA"); String fontSize = style.optString("fontSize", "12"); String fontWeight = style.optString("fontWeight", "normal"); if (style.optString("externalGraphic") != null) { float opacity = style.optFloat("graphicOpacity", style.optFloat("fillOpacity", 1.0f)); state.setFillOpacity(opacity); state.setStrokeOpacity(opacity); dc.setGState(state); try { Image image = PDFUtils.createImage(context, width * f, height * f, new URI(style.getString("externalGraphic")), 0.0f); image.setAbsolutePosition((float) coordinate.x + offsetX * f, (float) coordinate.y + offsetY * f); dc.addImage(image); } catch (BadElementException e) { context.addError(e); } catch (URISyntaxException e) { context.addError(e); } catch (DocumentException e) { context.addError(e); } } else if (graphicName != null && !graphicName.equalsIgnoreCase("circle")) { PolygonRenderer.applyStyle(context, dc, style, state); float[] symbol = SYMBOLS.get(graphicName); if (symbol == null) { throw new InvalidValueException("graphicName", graphicName); } dc.setGState(state); dc.moveTo((float) coordinate.x + symbol[0] * width * f + offsetX * f, (float) coordinate.y + symbol[1] * height * f + offsetY * f); for (int i = 2; i < symbol.length - 2; i += 2) { dc.lineTo((float) coordinate.x + symbol[i] * width * f + offsetX * f, (float) coordinate.y + symbol[i + 1] * height * f + offsetY * f); } dc.closePath(); dc.fillStroke(); } else if (label != null && label.length() > 0) { BaseFont bf = PDFUtils.getBaseFont(fontFamily, fontSize, fontWeight); float fontHeight = (float) Double.parseDouble(fontSize.toLowerCase().replaceAll("px", "")) * f; dc.setFontAndSize(bf, fontHeight); dc.setColorFill(ColorWrapper.convertColor(fontColor)); state.setFillOpacity((float) 1.0); dc.setGState(state); dc.beginText(); dc.setTextMatrix((float) coordinate.x + labelXOffset * f, (float) coordinate.y + labelYOffset * f); dc.setGState(state); dc.showTextAligned(PDFUtils.getHorizontalAlignment(labelAlign), label, (float) coordinate.x + labelXOffset * f, (float) coordinate.y + labelYOffset * f - PDFUtils.getVerticalOffset(labelAlign, fontHeight), 0); dc.endText(); } else { PolygonRenderer.applyStyle(context, dc, style, state); dc.setGState(state); dc.circle((float) coordinate.x, (float) coordinate.y, pointRadius * f); dc.fillStroke(); } }
From source file:org.mapfish.print.map.renderers.vector.PolygonRenderer.java
License:Open Source License
protected static void applyStyle(RenderingContext context, PdfContentByte dc, PJsonObject style, PdfGState state) { if (style == null) return;/* ww w.j ava2 s . c o m*/ LineStringRenderer.applyStyle(context, dc, style, state); if (style.optString("fillColor") != null) { dc.setColorFill(ColorWrapper.convertColor(style.getString("fillColor"))); } if (style.optString("fillOpacity") != null) { state.setFillOpacity(style.getFloat("fillOpacity")); } }
From source file:org.meveo.admin.action.billing.BillingAccountBean.java
License:Open Source License
public void generatePDF(long invoiceId) { Invoice invoice = invoiceService.findById(invoiceId); byte[] invoicePdf = invoice.getPdf(); FacesContext context = FacesContext.getCurrentInstance(); String invoiceFilename = null; BillingRun billingRun = invoice.getBillingRun(); invoiceFilename = invoice.getInvoiceNumber() + ".pdf"; if (billingRun != null && billingRun.getStatus() != BillingRunStatusEnum.VALIDATED) { invoiceFilename = "unvalidated-invoice.pdf"; }/*from w w w.j a v a 2 s.co m*/ HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.setContentType("application/pdf"); // fill in response.setHeader("Content-disposition", "attachment; filename=" + invoiceFilename); try { OutputStream os = response.getOutputStream(); Document document = new Document(PageSize.A4); if (billingRun != null && invoice.getBillingRun().getStatus() != BillingRunStatusEnum.VALIDATED) { // Add watemark image PdfReader reader = new PdfReader(invoicePdf); int n = reader.getNumberOfPages(); PdfStamper stamp = new PdfStamper(reader, os); PdfContentByte over = null; BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); PdfGState gs = new PdfGState(); gs.setFillOpacity(0.5f); int i = 1; while (i <= n) { over = stamp.getOverContent(i); over.setGState(gs); over.beginText(); System.out.println("top=" + document.top() + ",bottom=" + document.bottom()); over.setTextMatrix(document.top(), document.bottom()); over.setFontAndSize(bf, 150); over.setColorFill(Color.GRAY); over.showTextAligned(Element.ALIGN_CENTER, "TEST", document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, 45); over.endText(); i++; } stamp.close(); } else { os.write(invoicePdf); // fill in PDF with bytes } // contentType os.flush(); os.close(); context.responseComplete(); } catch (IOException e) { log.error("failed to generate PDF ", e); } catch (DocumentException e) { log.error("error in generation PDF ", e); } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
License:Open Source License
public boolean drawPdfImage(final com.lowagie.text.Image image, final Image img, AffineTransform xform, final ImageObserver obs) { if (img == null) { throw new NullPointerException("Image must not be null."); }// www. j a v a 2s . co m if (image == null) { throw new NullPointerException("Image must not be null."); } if (xform == null) { xform = AffineTransform.getTranslateInstance(0, 0); } xform.translate(0, img.getHeight(obs)); xform.scale(img.getWidth(obs), img.getHeight(obs)); final AffineTransform inverse = this.normalizeMatrix(); final AffineTransform flipper = FLIP_TRANSFORM; inverse.concatenate(xform); inverse.concatenate(flipper); try { final double[] mx = new double[6]; inverse.getMatrix(mx); if (currentFillGState != 255) { PdfGState gs = fillGState[255]; if (gs == null) { gs = new PdfGState(); gs.setFillOpacity(1); fillGState[255] = gs; } cb.setGState(gs); } cb.addImage(image, (float) mx[0], (float) mx[1], (float) mx[2], (float) mx[3], (float) mx[4], (float) mx[5]); } catch (Exception ex) { PdfGraphics2D.logger.error("Failed to draw the image: ", ex); // throw new IllegalArgumentException("Failed to draw the image"); } finally { if (currentFillGState != 255) { final PdfGState gs = fillGState[currentFillGState]; cb.setGState(gs); } } return true; }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
License:Open Source License
private void setPaint(final boolean invert, final double xoffset, final double yoffset, final boolean fill) { if (paint instanceof Color) { final Color color = (Color) paint; final int alpha = color.getAlpha(); if (fill) { if (alpha != currentFillGState) { currentFillGState = alpha; PdfGState gs = fillGState[alpha]; if (gs == null) { gs = new PdfGState(); gs.setFillOpacity(alpha / 255.00f); fillGState[alpha] = gs; }// www .ja va2s.c o m cb.setGState(gs); } cb.setColorFill(color); } else { if (alpha != currentStrokeGState) { currentStrokeGState = alpha; PdfGState gs = strokeGState[alpha]; if (gs == null) { gs = new PdfGState(); gs.setStrokeOpacity(alpha / 255.0f); strokeGState[alpha] = gs; } cb.setGState(gs); } cb.setColorStroke(color); } } else if (paint instanceof GradientPaint) { final GradientPaint gp = (GradientPaint) paint; final Point2D p1 = gp.getPoint1(); transform.transform(p1, p1); final Point2D p2 = gp.getPoint2(); transform.transform(p2, p2); final Color c1 = gp.getColor1(); final Color c2 = gp.getColor2(); final PdfShading shading = PdfShading.simpleAxial(cb.getPdfWriter(), (float) p1.getX(), normalizeY((float) p1.getY()), (float) p2.getX(), normalizeY((float) p2.getY()), c1, c2); final PdfShadingPattern pat = new PdfShadingPattern(shading); if (fill) { cb.setShadingFill(pat); } else { cb.setShadingStroke(pat); } } else if (paint instanceof TexturePaint) { try { final TexturePaint tp = (TexturePaint) paint; final BufferedImage img = tp.getImage(); final Rectangle2D rect = tp.getAnchorRect(); final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null); final PdfPatternPainter pattern = cb.createPattern(image.getWidth(), image.getHeight()); final AffineTransform inverse = this.normalizeMatrix(); inverse.translate(rect.getX(), rect.getY()); inverse.scale(rect.getWidth() / image.getWidth(), -rect.getHeight() / image.getHeight()); final double[] mx = new double[6]; inverse.getMatrix(mx); pattern.setPatternMatrix((float) mx[0], (float) mx[1], (float) mx[2], (float) mx[3], (float) mx[4], (float) mx[5]); image.setAbsolutePosition(0, 0); pattern.addImage(image); if (fill) { cb.setPatternFill(pattern); } else { cb.setPatternStroke(pattern); } } catch (Exception ex) { if (fill) { cb.setColorFill(Color.gray); } else { cb.setColorStroke(Color.gray); } } } else { try { int type = BufferedImage.TYPE_4BYTE_ABGR; if (paint.getTransparency() == Transparency.OPAQUE) { type = BufferedImage.TYPE_3BYTE_BGR; } final BufferedImage img = new BufferedImage((int) width, (int) height, type); final Graphics2D g = (Graphics2D) img.getGraphics(); g.transform(transform); final AffineTransform inv = transform.createInverse(); Shape fillRect = new Rectangle2D.Double(0, 0, img.getWidth(), img.getHeight()); fillRect = inv.createTransformedShape(fillRect); g.setPaint(paint); g.fill(fillRect); if (invert) { final AffineTransform tx = new AffineTransform(); tx.scale(1, -1); tx.translate(-xoffset, -yoffset); g.drawImage(img, tx, null); } g.dispose(); // g = null; final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null); final PdfPatternPainter pattern = cb.createPattern(width, height); image.setAbsolutePosition(0, 0); pattern.addImage(image); if (fill) { cb.setPatternFill(pattern); } else { cb.setPatternStroke(pattern); } } catch (Exception ex) { if (fill) { cb.setColorFill(Color.gray); } else { cb.setColorStroke(Color.gray); } } } }
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();//w w w. j a v a 2 s. 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"); } } }