Example usage for com.lowagie.text.pdf PdfContentByte setGState

List of usage examples for com.lowagie.text.pdf PdfContentByte setGState

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfContentByte setGState.

Prototype

public void setGState(PdfGState gstate) 

Source Link

Document

Sets the graphic state

Usage

From source file:org.mapfish.print.map.renderers.vector.LineStringRenderer.java

License:Open Source License

protected void renderImpl(RenderingContext context, PdfContentByte dc, PJsonObject style, LineString geometry) {
    PdfGState state = new PdfGState();
    applyStyle(context, dc, style, state);
    dc.setGState(state);
    Coordinate[] coords = geometry.getCoordinates();
    if (coords.length < 2)
        return;/*  ww w  .  j ava2  s. c o  m*/
    dc.moveTo((float) coords[0].x, (float) coords[0].y);
    for (int i = 1; i < coords.length; i++) {
        Coordinate coord = coords[i];
        dc.lineTo((float) coord.x, (float) coord.y);
    }
    dc.stroke();
}

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");
    /*/*  w  ww.ja va  2  s  .  com*/
     * 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 void renderImpl(RenderingContext context, PdfContentByte dc, PJsonObject style, Polygon geometry) {
    PdfGState state = new PdfGState();
    applyStyle(context, dc, style, state);
    dc.setGState(state);

    final LineString ring = geometry.getExteriorRing();
    renderRing(dc, ring);//w w  w  .  ja  v a 2 s  . c o m
    for (int i = 0; i < geometry.getNumInteriorRing(); ++i) {
        renderRing(dc, geometry.getInteriorRingN(i));
    }
    dc.eoFillStroke();
}

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";
    }// www  .  jav  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:questions.images.TransparentEllipse2.java

public static void main(String[] args) {

    Document document = new Document(PageSize.POSTCARD);
    try {/*  w  w w.j a  v  a  2 s .c  om*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        PdfContentByte cb = writer.getDirectContent();

        // clipped image
        cb.ellipse(1, 1, PageSize.POSTCARD.getWidth() - 2, PageSize.POSTCARD.getHeight() - 2);
        cb.clip();
        cb.newPath();
        Image img = Image.getInstance(RESOURCE);
        img.scaleToFit(PageSize.POSTCARD.getWidth(), PageSize.POSTCARD.getHeight());
        cb.addImage(img, PageSize.POSTCARD.getWidth(), 0, 0, PageSize.POSTCARD.getHeight(), 0, 0);

        //Prepare gradation list
        int gradationStep = 40;
        float[] gradationRatioList = new float[gradationStep];
        for (int i = 0; i < gradationStep; i++) {
            gradationRatioList[i] = 1 - (float) Math.sin(Math.toRadians(90.0f / gradationStep * (i + 1)));
        }

        //Create template
        PdfTemplate template = cb.createTemplate(PageSize.POSTCARD.getWidth(), PageSize.POSTCARD.getHeight());

        //Prepare transparent group
        PdfTransparencyGroup transGroup = new PdfTransparencyGroup();
        transGroup.put(PdfName.CS, PdfName.DEVICEGRAY);
        transGroup.setIsolated(true);
        transGroup.setKnockout(false);
        template.setGroup(transGroup);

        //Prepare graphic state
        PdfGState gState = new PdfGState();
        PdfDictionary maskDict = new PdfDictionary();
        maskDict.put(PdfName.TYPE, PdfName.MASK);
        maskDict.put(PdfName.S, new PdfName("Luminosity"));
        maskDict.put(new PdfName("G"), template.getIndirectReference());
        gState.put(PdfName.SMASK, maskDict);
        cb.setGState(gState);

        //Create gradation for mask
        for (int i = 1; i < gradationStep + 1; i++) {
            template.setLineWidth(gradationStep + 1 - i);
            template.setGrayStroke(gradationRatioList[gradationStep - i]);
            template.ellipse(0, 0, PageSize.POSTCARD.getWidth(), PageSize.POSTCARD.getHeight());
            template.stroke();
        }

        //Place template
        cb.addTemplate(template, 0, 0);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    document.close();
}

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   ww  w. j a va 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");

        }
    }
}