Example usage for com.lowagie.text Image scaleAbsoluteWidth

List of usage examples for com.lowagie.text Image scaleAbsoluteWidth

Introduction

In this page you can find the example usage for com.lowagie.text Image scaleAbsoluteWidth.

Prototype

public void scaleAbsoluteWidth(float newWidth) 

Source Link

Document

Scale the image to an absolute width.

Usage

From source file:com.aryjr.nheengatu.pdf.PDFImage.java

License:Open Source License

public static Image createImage(final Tag htmlImage) throws BadElementException, IOException {
    final TagsManager gm = TagsManager.getInstance();
    // TODO the image path can't be static
    Image img;
    if (htmlImage.getPropertyValue("src").indexOf("http://") >= 0) {
        img = Image.getInstance(new URL(htmlImage.getPropertyValue("src")));
    } else {//from  w w w. j  a va  2s  .com
        img = Image.getInstance(htmlImage.getPropertyValue("src"));
    }
    img.setWidthPercentage(0);// TODO without it, the image dimensions
    // will be the same of the cell
    img.setAlignment(gm.getAlign());
    if (htmlImage.getPropertyValue("width") != null) {
        img.scaleAbsoluteWidth(Integer.parseInt(htmlImage.getPropertyValue("width")));
    }
    if (htmlImage.getPropertyValue("height") != null) {
        img.scaleAbsoluteHeight(Integer.parseInt(htmlImage.getPropertyValue("height")));
    }
    return img;
}

From source file:com.gp.cong.logisoft.reports.BookingCoverSheetPdfCreater.java

public void createBody(SearchBookingReportDTO searchBookingReportDTO, String simpleRequest,
        MessageResources messageResources, String printFromBl, String documentName)
        throws DocumentException, MalformedURLException, IOException, Exception {
    NumberFormat numformat = new DecimalFormat("##,###,##0.00");
    PdfPCell cell = new PdfPCell();
    Paragraph paragraph;// ww w  .  java 2s .  c  o  m
    PdfPTable table;
    Phrase phrase;

    PdfPTable mainTable = makeTable(2);
    mainTable.setWidthPercentage(100);

    BookingFcl bookingFcl = searchBookingReportDTO.getBookingflFcl();
    FclBl fclBl = null;
    if (CommonUtils.isNotEmpty(printFromBl)) {
        fclBl = new FclBlDAO().getFileNoObject(bookingFcl.getFileNo());
    }
    String company = null;
    String contactName = "";
    String email = null;
    String phone = null;
    String fax = null;
    String address = null;
    QuotationDAO quotationDAO = new QuotationDAO();
    CustAddressBC custAddressBC = new CustAddressBC();
    Quotation quotation = quotationDAO.getFileNoObject(bookingFcl.getFileNo());
    if (null != quotation) {
        contactName = quotation.getContactname();
    }
    if (bookingFcl.getShippercheck() != null && bookingFcl.getShippercheck().equals("on")) {
        //from=bookingFcl.getShipper();
        company = bookingFcl.getShipper();
        email = bookingFcl.getShipperEmail();
        phone = bookingFcl.getShipperPhone();
        fax = bookingFcl.getShipperFax();
        address = bookingFcl.getAddressforShipper();
    } else if (bookingFcl.getForwardercheck() != null && bookingFcl.getForwardercheck().equals("on")) {
        company = bookingFcl.getForward();
        email = bookingFcl.getForwarderEmail();
        phone = bookingFcl.getForwarderPhone();
        fax = bookingFcl.getForwarderFax();
        address = bookingFcl.getAddressforForwarder();
    } else if (bookingFcl.getConsigneecheck() != null && bookingFcl.getConsigneecheck().equals("on")) {
        company = bookingFcl.getConsignee();
        email = bookingFcl.getConsingeeEmail();
        phone = bookingFcl.getConsingeePhone();
        fax = bookingFcl.getConsigneeFax();
        address = bookingFcl.getAddressforConsingee();
    } else {
        if (null != quotation) {
            company = quotation.getClientname();
            email = quotation.getEmail1();
            phone = quotation.getPhone();
            fax = quotation.getFax();
            CustAddress custAddress = custAddressBC.getClientAddress(quotation.getClientnumber());
            if (null != custAddress) {
                address = custAddress.getAddress1();
            }
        }
    }

    PdfPTable headerTable = makeTable(3);
    headerTable.setWidths(new float[] { 20, 50, 30 });
    headerTable.setWidthPercentage(100);

    PdfPTable headerTable1 = makeTable(1);
    headerTable1.setWidths(new float[] { 100 });
    headerTable1.setWidthPercentage(100);

    PdfPCell headingCell1 = makeCell(
            new Phrase(messageResources.getMessage("fileNumberPrefix") + String.valueOf(bookingFcl.getFileNo()),
                    headingFont1),
            Element.ALIGN_CENTER);
    headingCell1.setBackgroundColor(Color.LIGHT_GRAY);
    headingCell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
    headerTable1.addCell(headingCell1);
    cell = makeCellleftNoBorder("");
    cell.addElement(headerTable1);
    headerTable.addCell(headerTable1);

    PdfPTable headerTable2 = makeTable(2);
    headerTable2.setWidths(new float[] { 38, 62 });
    headerTable2.setWidthPercentage(100);

    SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy HH:mm a");
    SimpleDateFormat sdfForddMMyyyy = new SimpleDateFormat("dd-MMM-yyyy");
    String colon = ": ";
    String docCut = "";
    String carrierDocCut = "";
    String etd = "";
    String eta = "";
    if (bookingFcl.getDocCutOff() != null) {
        docCut = sdf.format(bookingFcl.getDocCutOff());
    }
    if (bookingFcl.getCarrierDocCut() != null) {
        carrierDocCut = sdf.format(bookingFcl.getCarrierDocCut());
    }
    if (bookingFcl.getEtd() != null) {
        etd = sdfForddMMyyyy.format(bookingFcl.getEtd());
    }
    if (bookingFcl.getEta() != null) {
        eta = sdfForddMMyyyy.format(bookingFcl.getEta());
    }

    headerTable2.addCell(makeCell(new Phrase("Doc Cutoff", headingFont2), Element.ALIGN_LEFT));
    headerTable2.addCell(makeCell(new Phrase(colon + docCut, redBoldFont), Element.ALIGN_LEFT));
    headerTable2.addCell(makeCell(new Phrase("Carrier Doc Cut", headingFont2), Element.ALIGN_LEFT));
    headerTable2.addCell(makeCell(new Phrase(colon + carrierDocCut, redBoldFont), Element.ALIGN_LEFT));

    cell = makeCellleftNoBorder("");
    cell.addElement(headerTable2);
    headerTable.addCell(headerTable2);

    PdfPTable headerTable3 = makeTable(2);
    headerTable3.setWidths(new float[] { 20, 80 });
    headerTable3.setWidthPercentage(100);

    headerTable3.addCell(makeCell(new Phrase("ETD", headingFont2), Element.ALIGN_LEFT));
    headerTable3.addCell(makeCell(new Phrase(colon + etd, headingFont2), Element.ALIGN_LEFT));
    headerTable3.addCell(makeCell(new Phrase("ETA", headingFont2), Element.ALIGN_LEFT));
    headerTable3.addCell(makeCell(new Phrase(colon + eta, headingFont2), Element.ALIGN_LEFT));

    cell = makeCellleftNoBorder("");
    cell.addElement(headerTable3);
    headerTable.addCell(headerTable3);

    document.add(headerTable);

    PdfPTable pTable = new PdfPTable(2);
    pTable.setWidthPercentage(100);

    PdfPTable clientTable = makeTable(2);
    clientTable.setWidths(new float[] { 27, 73 });
    clientTable.setWidthPercentage(100);

    clientTable.addCell(makeCellleftNoBorderWithBoldFont("Client Name"));
    clientTable.addCell(makeCellLeftNoBorderValue(company));
    clientTable.addCell(makeCellleftNoBorderWithBoldFont("Client Address"));
    clientTable.addCell(makeCellLeftNoBorderValue(address));
    clientTable.addCell(makeCellleftNoBorderWithBoldFont("Contact Name"));
    clientTable.addCell(makeCellLeftNoBorderValue(contactName));
    cell = makeCellleftNoBorderWithBoldFont("Contact Number");
    cell.setNoWrap(true);
    clientTable.addCell(cell);
    clientTable.addCell(makeCellLeftNoBorderValue(phone));
    clientTable.addCell(makeCellleftNoBorderWithBoldFont("Contact Fax"));
    clientTable.addCell(makeCellLeftNoBorderValue(fax));
    clientTable.addCell(makeCellleftNoBorderWithBoldFont("Contact Email"));
    clientTable.addCell(makeCellLeftNoBorderValue(email));

    cell = makeCellleftNoBorder("");
    cell.setBorderWidthRight(0.6f);
    cell.setBorderWidthBottom(0.6f);
    cell.setBorderWidthLeft(0.6f);
    cell.setBorderWidthTop(0.6f);
    cell.addElement(clientTable);
    pTable.addCell(cell);

    PdfPTable carrierTable = makeTable(2);
    carrierTable.setWidths(new float[] { 26, 74 });
    carrierTable.setWidthPercentage(100);
    String sslName[] = bookingFcl.getSslname().split("//");

    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("Carrier"));
    carrierTable.addCell(makeCellLeftNoBorderValue(sslName.length > 1 ? sslName[0] : ""));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("Vessel"));
    carrierTable.addCell(makeCellLeftNoBorderValue(bookingFcl.getVessel()));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("Voyage"));
    carrierTable.addCell(makeCellLeftNoBorderValue(bookingFcl.getVoyageCarrier()));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("SSL Booking#"));
    carrierTable.addCell(makeCellLeftNoBorderValue(bookingFcl.getSSBookingNo()));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("POO"));
    carrierTable.addCell(makeCellLeftNoBorderValue(getCityStateName(bookingFcl.getOriginTerminal())));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("POL"));
    carrierTable.addCell(makeCellLeftNoBorderValue(getCityStateName(bookingFcl.getPortofOrgin())));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("POD"));
    carrierTable.addCell(makeCellLeftNoBorderValue(getCityStateName(bookingFcl.getDestination())));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("FD"));
    carrierTable.addCell(makeCellLeftNoBorderValue(getCityStateName(bookingFcl.getPortofDischarge())));
    carrierTable.addCell(makeCellleftNoBorderWithBoldFont("Containers"));
    carrierTable.addCell(makeCellLeftNoBorderValue(
            this.getContainers(simpleRequest, searchBookingReportDTO, messageResources).getContent()));
    //        PdfPCell cell1 = makeCell(this.getContainers(simpleRequest, searchBookingReportDTO, messageResources), 1);
    //        cell1.setColspan(2);
    //        cell1.setBorderWidthLeft(0.0F);
    //        carrierTable.addCell(cell1);

    cell = makeCellleftNoBorder("");
    cell.setBorderWidthRight(0.6f);
    cell.setBorderWidthBottom(0.6f);
    cell.setBorderWidthTop(0.6f);
    cell.addElement(carrierTable);

    pTable.addCell(cell);

    document.add(pTable);

    PdfPTable hazardsMainTable = makeTable(1);
    hazardsMainTable.setWidths(new float[] { 100 });
    hazardsMainTable.setWidthPercentage(100);

    PdfPTable hazardsTable = makeTable(3);
    hazardsTable.setWidths(new float[] { 70, 15, 15 });
    hazardsTable.setWidthPercentage(100);

    Image yes = Image.getInstance(searchBookingReportDTO.getContextPath() + "/images/icons/y.png");
    yes.scalePercent(60);
    yes.scaleAbsoluteWidth(18);
    PdfPCell yesCell = new PdfPCell();
    yesCell.setBorder(0);
    yesCell.addElement(new Chunk(yes, 32, -0));

    Image no = Image.getInstance(searchBookingReportDTO.getContextPath() + "/images/icons/n.png");
    no.scalePercent(60);
    no.scaleAbsoluteWidth(18);
    PdfPCell noCell = new PdfPCell();
    noCell.setBorder(0);
    noCell.addElement(new Chunk(no, 32, -0));

    hazardsTable.addCell(makeCellleftNoBorderWithBoldFont("HAZARDOUS"));
    if (bookingFcl.getHazmat() != null && "Y".equalsIgnoreCase(bookingFcl.getHazmat())) {
        hazardsTable.addCell(yesCell);
        hazardsTable.addCell(makeCell(new Phrase("N", fontforYandN), 1));
    } else {
        hazardsTable.addCell(makeCell(new Phrase("Y", fontforYandN), 1));
        hazardsTable.addCell(noCell);
    }
    hazardsTable.addCell(makeCellleftNoBorderWithBoldFont("AES"));
    hazardsTable.addCell(makeCell(new Phrase("Y", fontforYandN), Element.ALIGN_CENTER));
    hazardsTable.addCell(makeCell(new Phrase("N", fontforYandN), Element.ALIGN_CENTER));
    hazardsTable.addCell(makeCellleftNoBorderWithBoldFont("DIRECT CONSIGMENT"));
    if (bookingFcl.getDirectConsignmntCheck() != null
            && "on".equalsIgnoreCase(bookingFcl.getDirectConsignmntCheck())) {
        hazardsTable.addCell(yesCell);
        hazardsTable.addCell(makeCell(new Phrase("N", fontforYandN), 1));
    } else {
        hazardsTable.addCell(makeCell(new Phrase("Y", fontforYandN), 1));
        hazardsTable.addCell(noCell);
    }
    hazardsTable.addCell(makeCellleftNoBorderWithBoldFont("AFR"));
    hazardsTable.addCell(makeCell(new Phrase("Y", fontforYandN), Element.ALIGN_CENTER));
    hazardsTable.addCell(makeCell(new Phrase("N", fontforYandN), Element.ALIGN_CENTER));

    cell = makeCellleftNoBorder("");
    cell.setBorderWidthRight(0.6f);
    cell.setBorderWidthBottom(0.6f);
    cell.setBorderWidthLeft(0.6f);
    cell.addElement(hazardsTable);

    hazardsMainTable.addCell(cell);
    document.add(hazardsMainTable);

    PdfPTable docsMainTable = makeTable(2);
    docsMainTable.setWidths(new float[] { 30, 70 });
    docsMainTable.setWidthPercentage(100);

    PdfPTable docsTable = makeTable(2);
    docsTable.setWidths(new float[] { 50, 50 });
    docsTable.setWidthPercentage(100);

    Image img = Image.getInstance(searchBookingReportDTO.getContextPath() + "/images/icons/uncheckedBox.png");
    img.scalePercent(50);
    img.scaleAbsoluteWidth(18);
    PdfPCell pCell = new PdfPCell();
    pCell.setBorder(0);
    pCell.addElement(new Chunk(img, 25, -0));

    //        Image checkedimg = Image.getInstance(searchBookingReportDTO.getContextPath() + "/images/icons/check.png");
    //        checkedimg.scalePercent(60);
    //        checkedimg.scaleAbsoluteWidth(18);
    //        PdfPCell checkedCell = new PdfPCell();
    //        checkedCell.setBorder(0);
    //        checkedCell.addElement(new Chunk(checkedimg, 25, -0));
    docsTable.addCell(makeCellleftNoBorderWithBoldFont("Docs"));
    docsTable.addCell(pCell);

    docsTable.addCell(makeCellNoBorders("       "));
    docsTable.addCell(makeCellNoBorders("       "));

    docsTable.addCell(makeCellleftNoBorderWithBoldFont("COB"));
    docsTable.addCell(pCell);

    docsTable.addCell(makeCellNoBorders("       "));
    docsTable.addCell(makeCellNoBorders("       "));

    docsTable.addCell(makeCellleftNoBorderWithBoldFont("MBL"));
    docsTable.addCell(pCell);

    docsTable.addCell(makeCellNoBorders("       "));
    docsTable.addCell(makeCellNoBorders("       "));

    docsTable.addCell(makeCellleftNoBorderWithBoldFont("Manifisted"));
    docsTable.addCell(pCell);

    cell = makeCellleftNoBorder("");
    cell.setBorderWidthBottom(0.6f);
    cell.setBorderWidthLeft(0.6f);
    cell.addElement(docsTable);
    docsMainTable.addCell(cell);

    PdfPTable noteTable = makeTable(1);
    noteTable.setWidths(new float[] { 100 });
    noteTable.setWidthPercentage(100);
    noteTable.addCell(makeCellCenterNoBorder("Notes"));
    noteTable.addCell(makeCellNoBorders("       "));
    noteTable.addCell(makeCellleftwithUnderLine("            "));
    noteTable.addCell(makeCellNoBorders("       "));
    noteTable.addCell(makeCellleftwithUnderLine("            "));
    noteTable.addCell(makeCellNoBorders("       "));
    noteTable.addCell(makeCellleftwithUnderLine("            "));
    noteTable.addCell(makeCellNoBorders("       "));
    noteTable.addCell(makeCellleftwithUnderLine("            "));
    noteTable.addCell(makeCellNoBorders("       "));

    cell = makeCellleftNoBorder("");
    cell.setBorderWidthBottom(0.6f);
    cell.setBorderWidthRight(0.6f);
    cell.addElement(noteTable);
    docsMainTable.addCell(cell);
    document.add(docsMainTable);

}

From source file:cz.incad.kramerius.pdf.impl.AbstractPDFRenderSupport.java

License:Open Source License

public static ScaledImageOptions insertJavaImage(Document document, float percentage, BufferedImage javaImg)
        throws IOException, BadElementException, MalformedURLException, DocumentException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    writeImageToStream(javaImg, "jpeg", bos);

    com.lowagie.text.Image img = com.lowagie.text.Image.getInstance(bos.toByteArray());

    Float ratio = ratio(document, percentage, javaImg);

    int fitToPageWidth = (int) (javaImg.getWidth(null) * ratio);
    int fitToPageHeight = (int) (javaImg.getHeight(null) * ratio);

    int offsetX = ((int) document.getPageSize().getWidth() - fitToPageWidth) / 2;
    int offsetY = ((int) document.getPageSize().getHeight() - fitToPageHeight) / 2;

    img.scaleAbsoluteHeight(ratio * img.getHeight());

    img.scaleAbsoluteWidth(ratio * img.getWidth());
    img.setAbsolutePosition((offsetX),/*from  w  w  w .j  av a  2 s. c  om*/
            document.getPageSize().getHeight() - offsetY - (ratio * img.getHeight()));

    document.add(img);

    ScaledImageOptions options = new ScaledImageOptions();
    options.setXdpi(img.getDpiX());
    options.setYdpi(img.getDpiY());

    options.setXoffset(offsetX);
    options.setYoffset(offsetY);

    options.setWidth(fitToPageWidth);
    options.setHeight(fitToPageHeight);
    options.setScaleFactor(ratio);

    return options;
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableImage.java

License:Open Source License

public StylableImage(StylableDocument ownerDocument, IStylableContainer parent, Image image, Float x, Float y,
        Float width, Float height) {
    this.parent = parent;
    this.image = image;
    this.x = x;// w ww  .j a  v a2  s  .  c om
    this.y = y;
    if (width != null) {
        image.scaleAbsoluteWidth(width);
    }
    if (height != null) {
        image.scaleAbsoluteHeight(height);
    }
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableList.java

License:Open Source License

public void applyStyles(Style style) {
    this.lastStyleApplied = style;

    Map<Integer, StyleListProperties> listPropertiesMap = style.getListPropertiesMap();
    if (listPropertiesMap != null) {
        StyleListProperties listProperties = getListProperties(listPropertiesMap, listLevel);
        if (listProperties != null) {
            String bulletChar = listProperties.getBulletChar();
            if (bulletChar != null) {
                // list item label is a char
                Chunk symbol = new Chunk(bulletChar);

                StyleTextProperties textProperties = listProperties.getTextProperties();
                if (textProperties != null) {
                    Font font = textProperties.getFont();
                    if (font != null) {
                        symbol.setFont(font);
                    }//  w w w  .  j a  va  2s. c o  m
                }

                super.setListSymbol(symbol);
            }

            Image image = listProperties.getImage();
            if (image != null) {
                // list item label is an image
                Float width = listProperties.getWidth();
                if (width != null) {
                    image.scaleAbsoluteWidth(width);
                }

                Float height = listProperties.getHeight();
                if (height != null) {
                    image.scaleAbsoluteHeight(height);
                }

                super.setListSymbol(new Chunk(image, 0.0f, 0.0f));
            }

            if (bulletChar == null && image == null) {
                // list item label is a number
                Chunk symbol = new Chunk("");

                StyleTextProperties textProperties = listProperties.getTextProperties();
                if (textProperties != null) {
                    Font font = textProperties.getFont();
                    if (font != null) {
                        symbol.setFont(font);
                    }
                }

                Integer startValue = listProperties.getStartValue();
                if (startValue != null) {
                    super.setFirst(startValue);
                }

                StyleNumFormat numFormat = listProperties.getNumFormat();
                if (numFormat != null) {
                    String numPrefix = listProperties.getNumPrefix();
                    if (numPrefix != null) {
                        super.setPreSymbol(numPrefix);
                        symbol = new Chunk(numPrefix, symbol.getFont());
                    }

                    String numSuffix = listProperties.getNumSuffix();
                    if (numSuffix != null) {
                        super.setPostSymbol(numSuffix);
                        symbol.append(numSuffix);
                    }

                    super.setNumbered(true);
                    super.setLettered(numFormat.isAlphabetical());
                    this.romanNumbered = numFormat.isRoman();
                    super.setLowercase(numFormat.isLowercase());
                }

                super.setListSymbol(symbol);
            }

            // set indentation, it is specified in different way by Open Office and MsWord
            Float marginLeft = listProperties.getMarginLeft();
            Float textIndent = listProperties.getTextIndent();
            Float spaceBefore = listProperties.getSpaceBefore();
            Float minLabelWidth = listProperties.getMinLabelWidth();
            if (marginLeft != null && textIndent != null) {
                // ODT generated by Open Office
                super.setIndentationLeft(Math.max(marginLeft + textIndent, 0.0f));
                super.setSymbolIndent(Math.max(-textIndent, 0.0f));
            } else if (spaceBefore != null && minLabelWidth != null) {
                // ODT generated by MsWord
                super.setIndentationLeft(Math.max(spaceBefore, 0.0f));
                super.setSymbolIndent(Math.max(minLabelWidth, 0.0f));
            }
        }
    }
}

From source file:mx.dr.util.report.impl.PdfService.java

License:Open Source License

/**
* write a label in pdf document.//w w w.  ja  v a 2s  . c  om
* <br/>
* escribe una etiqueta en el documento pdf.
* @param doc pdf document / documento pdf.
* @param dto object that encompasses the values of the labels to be placed in the document / objeto que engloba los valores de las etiquetas que se colocaran en el documento.
* @param offset jump on the Y axis to be given before placing the tag in the document / salto en el eje Y que se dara antes de colocar la etiqueta en el documento.
* @param table container table if applicable / contenedor de tabla si es que aplica.
* @throws Exception If an error occurs / si ocurre algun error.
*/
public void estampaEtiqueta(Document doc, Object dto, Float offset, PdfPTable table) throws Exception {
    List<Field> fields = new ArrayList<Field>();

    for (Field m : dto.getClass().getDeclaredFields()) {
        m.setAccessible(true);
        if (m.getAnnotation(DRPdfLabel.class) != null) {
            fields.add(m);
        }
    }
    Collections.sort(fields, new Comparator<Field>() {

        public int compare(Field o1, Field o2) {
            DRPdfLabel etiqueta1 = o1.getAnnotation(DRPdfLabel.class);
            DRPdfLabel etiqueta2 = o2.getAnnotation(DRPdfLabel.class);
            String uno = int2String(etiqueta1.y()) + "." + int2String(etiqueta1.order());
            String dos = int2String(etiqueta2.y()) + "." + int2String(etiqueta2.order());
            return uno.compareTo(dos);

        }

        private String int2String(int num) {
            if (num < 10) {
                return "0" + num;
            } else {
                return String.valueOf(num);
            }
        }
    });
    DRPdfLabel etiqueta;
    DRPdfTable etiquetaTabla;
    int lineaActual = 0;
    Paragraph pantagram = null;
    StringBuffer sb = null;
    Font font;
    Object valor;
    String label;
    DRPdfImage img;
    int residuo;
    int adicional = 0;
    for (Field m : fields) {
        etiqueta = m.getAnnotation(DRPdfLabel.class);
        img = m.getAnnotation(DRPdfImage.class);
        valor = m.get(dto);
        if (valor != null && valor instanceof List) {
            etiquetaTabla = m.getAnnotation(DRPdfTable.class);
            PdfPTable tableDance = null;
            if (etiquetaTabla != null) {
                tableDance = new PdfPTable(etiquetaTabla.colsPercentage());
                tableDance.setSpacingBefore(etiqueta.offset());
                for (String c : etiquetaTabla.columnLabels()) {
                    tableDance.addCell(c);
                }
            }
            if (pantagram != null) {
                doc.add(pantagram);
                pantagram = null;
            }
            for (int i = 0; i < ((List) valor).size(); i++) {
                if (i == 0 && etiqueta.offset() > 0) {
                    estampaEtiqueta(doc, ((List) valor).get(i), etiqueta.offset(), tableDance);
                } else {
                    estampaEtiqueta(doc, ((List) valor).get(i), null, tableDance);
                }
            }
            if (etiquetaTabla != null) {
                doc.add(tableDance);
            }
        } else if (img != null) {
            /* File file = new File(IMGDIR + valor);
            FileInputStream inImg = new FileInputStream(file);
            byte[] b=new byte[(int)file.length()];
            inImg.read(b);*/

            Image ima = Image.getInstance(IMGDIR + valor);

            //System.out.println(ima.getPlainWidth());
            ima.scaleAbsoluteWidth(img.width());
            //System.out.println(ima.getScaledWidth());
            ima.scaleAbsoluteHeight(ima.getScaledWidth());
            ima.setAlignment(img.style());
            ima.setAbsolutePosition(img.x(), img.y());
            doc.add(ima);

        } else if (table != null) {

            PdfPCell cerda = null;

            label = value2String(valor);
            residuo = etiqueta.length() - label.length();
            label = etiqueta.length() > 0 && residuo < 0 ? label.substring(0, etiqueta.length()) : label;
            DRPdfColumn col = m.getAnnotation(DRPdfColumn.class);
            if (col != null) {
                cerda = new PdfPCell(new Paragraph(label));
                cerda.setColspan(col.colspan());
                table.addCell(cerda);
            } else {
                table.addCell(label);
            }

        } else {
            if (lineaActual < etiqueta.y()) {
                if (pantagram != null) {
                    doc.add(pantagram);
                }
                if (offset == null || etiqueta.y() > 1) {
                    if (etiqueta.offset() > 0) {
                        pantagram = new Paragraph(etiqueta.offset());
                    } else {
                        pantagram = new Paragraph();
                    }
                } else {
                    pantagram = new Paragraph(offset);
                }
                lineaActual = etiqueta.y();
            }

            if (etiqueta.wspacesBefore() > 0) {
                sb = new StringBuffer("");
                fillEmpty(etiqueta.wspacesBefore(), sb);
                font = new Font(Font.COURIER, 12);
                pantagram.add(new Chunk(sb.toString(), font));
            }
            sb = new StringBuffer("");
            label = value2String(valor);
            residuo = etiqueta.length() - label.length();
            label = etiqueta.length() > 0 && residuo < 0 ? label.substring(0, etiqueta.length()) : label;

            if (etiqueta.font().equals(BaseFont.COURIER)) {
                font = new Font(Font.COURIER, etiqueta.fontSize(), etiqueta.style(),
                        new Color(etiqueta.color()[0], etiqueta.color()[1], etiqueta.color()[2]));
                adicional = 0;
            } else {
                font = FontFactory.getFont(TTFDIR + etiqueta.font(), BaseFont.CP1252, BaseFont.EMBEDDED,
                        etiqueta.fontSize(), etiqueta.style(),
                        new Color(etiqueta.color()[0], etiqueta.color()[1], etiqueta.color()[2]));
                adicional = label.equals("") ? (residuo / 2) + 1 : 0;
            }

            if (etiqueta.length() > 0 && etiqueta.justified().equals(DRPdfLabel.JUSTIFIED.DER) && residuo > 0) {
                fillEmpty(residuo + adicional, sb);
            }
            sb.append(label);
            if (etiqueta.length() > 0 && etiqueta.justified().equals(DRPdfLabel.JUSTIFIED.IZQ) && residuo > 0) {
                fillEmpty(residuo + adicional, sb);
            }
            pantagram.add(new Chunk(sb.toString(), font));
        }
    }
    if (pantagram != null) {
        doc.add(pantagram);
    }

}

From source file:org.odftoolkit.odfdom.converter.internal.itext.stylable.StylableList.java

License:Open Source License

public void applyStyles(Style style) {
    this.lastStyleApplied = style;

    Map<Integer, StyleListProperties> listPropertiesMap = style.getListPropertiesMap();
    if (listPropertiesMap != null) {
        StyleListProperties listProperties = null;
        for (int i = listLevel; i >= 0 && listProperties == null; i--) {
            // find style for current or nearest lower list level
            listProperties = listPropertiesMap.get(i);
        }/*from   w w  w.jav a  2s  .co m*/
        if (listProperties != null) {
            String bulletChar = listProperties.getBulletChar();
            if (bulletChar != null) {
                // list item label is a char
                Chunk symbol = new Chunk(bulletChar);

                StyleTextProperties textProperties = style.getTextProperties();
                if (textProperties != null) {
                    Font font = textProperties.getFont();
                    if (font != null) {
                        symbol.setFont(font);
                    }
                }

                super.setListSymbol(symbol);
            }

            Image image = listProperties.getImage();
            if (image != null) {
                // list item label is an image
                Float width = listProperties.getWidth();
                if (width != null) {
                    image.scaleAbsoluteWidth(width);
                }

                Float height = listProperties.getHeight();
                if (height != null) {
                    image.scaleAbsoluteHeight(height);
                }

                super.setListSymbol(new Chunk(image, 0.0f, 0.0f));
            }

            if (bulletChar == null && image == null) {
                // list item label is a number
                Chunk symbol = new Chunk("");

                StyleTextProperties textProperties = style.getTextProperties();
                if (textProperties != null) {
                    Font font = textProperties.getFont();
                    if (font != null) {
                        symbol.setFont(font);
                    }
                }

                Integer startValue = listProperties.getStartValue();
                if (startValue != null) {
                    super.setFirst(startValue);
                }

                String numPrefix = listProperties.getNumPrefix();
                if (numPrefix != null) {
                    super.setPreSymbol(numPrefix);
                    symbol = new Chunk(numPrefix, symbol.getFont());
                }

                String numSuffix = listProperties.getNumSuffix();
                if (numSuffix != null) {
                    super.setPostSymbol(numSuffix);
                    symbol.append(numSuffix);
                }

                StyleNumFormat numFormat = listProperties.getNumFormat();
                if (numFormat != null) {
                    super.setNumbered(true);
                    super.setLettered(numFormat.isAlphabetical());
                    this.romanNumbered = numFormat.isRoman();
                    super.setLowercase(numFormat.isLowercase());
                }

                super.setListSymbol(symbol);
            }

            Float marginLeft = listProperties.getMarginLeft();
            Float textIndent = listProperties.getTextIndent();
            if (marginLeft != null && textIndent != null) {
                super.setIndentationLeft(Math.max(marginLeft + textIndent, 0.0f));
                super.setSymbolIndent(Math.max(-textIndent, 0.0f));
                super.setAutoindent(false);
            }
        }
    }
}

From source file:org.webguitoolkit.ui.util.export.PDFEvent.java

License:Apache License

public void onEndPage(PdfWriter writer, Document document) {
    TableExportOptions exportOptions = wgtTable.getExportOptions();
    try {//  ww w.j a v a 2 s. c o  m
        Rectangle page = document.getPageSize();
        if (exportOptions.isShowDefaultHeader() || StringUtils.isNotEmpty(exportOptions.getHeaderImage())) {
            PdfPTable head = new PdfPTable(3);
            head.getDefaultCell().setBorder(Rectangle.NO_BORDER);
            Paragraph title = new Paragraph(wgtTable.getTitle());
            title.setAlignment(Element.ALIGN_LEFT);
            head.addCell(title);

            Paragraph empty = new Paragraph("");
            head.addCell(empty);
            if (StringUtils.isNotEmpty(exportOptions.getHeaderImage())) {
                try {
                    URL absoluteFileUrl = wgtTable.getPage().getClass()
                            .getResource("/" + exportOptions.getHeaderImage());
                    if (absoluteFileUrl != null) {
                        String path = absoluteFileUrl.getPath();
                        Image jpg = Image.getInstance(path);
                        jpg.scaleAbsoluteHeight(40);
                        jpg.scaleAbsoluteWidth(200);
                        head.addCell(jpg);
                    }
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    Paragraph noImage = new Paragraph("Image not found!");
                    head.addCell(noImage);
                }
            } else {
                head.addCell(empty);
            }
            head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            head.writeSelectedRows(0, -1, document.leftMargin(),
                    page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());
        }

        if (exportOptions.isShowDefaultFooter() || StringUtils.isNotEmpty(exportOptions.getFooterText())
                || exportOptions.isShowPageNumber()) {
            PdfPTable foot = new PdfPTable(3);
            String footerText = exportOptions.getFooterText() != null ? exportOptions.getFooterText() : "";

            if (!exportOptions.isShowDefaultFooter()) {
                foot.addCell(new Paragraph(footerText));
                foot.addCell(new Paragraph(""));
            } else {
                foot.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                String leftText = "";
                if (StringUtils.isNotEmpty(exportOptions.getFooterText())) {
                    leftText = exportOptions.getFooterText();
                }
                Paragraph left = new Paragraph(leftText);
                left.setAlignment(Element.ALIGN_LEFT);
                foot.addCell(left);

                DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM,
                        TextService.getLocale());
                Date today = new Date();
                String date = df.format(today);
                Paragraph center = new Paragraph(date);
                center.setAlignment(Element.ALIGN_CENTER);
                foot.addCell(center);
            }

            if (exportOptions.isShowPageNumber()) {
                Paragraph right = new Paragraph(
                        TextService.getString("pdf.page@Page:") + " " + writer.getPageNumber());
                right.setAlignment(Element.ALIGN_LEFT);
                foot.addCell(right);

                foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
                foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                        writer.getDirectContent());
            } else {
                foot.addCell(new Paragraph(""));
            }
        }
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

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.j  ava 2 s .co  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");

        }
    }
}