Example usage for com.lowagie.text Image RIGHT

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

Introduction

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

Prototype

int RIGHT

To view the source code for com.lowagie.text Image RIGHT.

Click Source Link

Document

this is a kind of image alignment.

Usage

From source file:ambit.data.qmrf.Qmrf_Xml_Pdf.java

License:Open Source License

public void headerTable(Document pdfdoc, org.w3c.dom.Document xmldoc) {
    try {/*from   www. j a v  a 2s .  c  om*/
        int header_font_size = 10;
        Image png_left = Image
                .getInstance(Qmrf_Xml_Pdf.class.getClassLoader().getResource("ambit/data/qmrf/logo.png"));
        Image png_right = Image
                .getInstance(Qmrf_Xml_Pdf.class.getClassLoader().getResource("ambit/data/qmrf/logo.png"));
        png_left.setAlignment(Image.LEFT);
        png_right.setAlignment(Image.RIGHT);
        png_left.scalePercent(60);
        png_right.scalePercent(60);
        //png.scaleAbsolute(76, 67);
        //png.setAlignment(Image.MIDDLE);

        PdfPCell cell;

        float[] widths = { 1f, 5f, 1f };
        float[] widths1 = { 1f };
        PdfPTable table = new PdfPTable(widths);
        PdfPTable table1 = new PdfPTable(widths1);

        table.setWidthPercentage(100);

        cell = new PdfPCell();
        cell.setMinimumHeight(70);
        cell.addElement(new Chunk(png_left, +14, -40));
        table.addCell(cell);

        String Text = "";
        try {

            Text = findNodeValue(xml_QMRF_number, xmldoc);
            Chunk ident_title = new Chunk("QMRF identifier (JRC Inventory):");
            Chunk ident_text = new Chunk(Text);

            Font bi_font = new Font(baseFont, header_font_size, Font.BOLDITALIC);
            Font i_font = new Font(baseFont, header_font_size, Font.ITALIC);

            ident_title.setFont(bi_font);
            ident_text.setFont(i_font);
            Paragraph p = new Paragraph();
            p.add(ident_title);
            p.add(ident_text);
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            ident_title = new Chunk("QMRF Title:");
            Phrase textPhrase = new Phrase();
            createNodePhrase("QSAR_title", xmldoc, textPhrase, i_font);
            ident_title.setFont(bi_font);

            p = new Paragraph();
            p.add(ident_title);
            p.add(textPhrase);
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            java.util.Date now = new java.util.Date();
            java.text.DateFormat df = java.text.DateFormat.getDateInstance();
            String date = df.format(now);
            ident_title = new Chunk("Printing Date:");
            ident_text = new Chunk(date);
            ident_title.setFont(bi_font);
            ident_text.setFont(i_font);
            p = new Paragraph();
            p.add(ident_title);
            p.add(ident_text);

            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            p = new Paragraph("");
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);
            cell = new PdfPCell(table1);
            cell.setPadding(0f);
            table.addCell(cell);

        } catch (Throwable x) {
            x.printStackTrace();

        }

        //table.addCell(new PdfPCell(png, true));
        cell.addElement(new Chunk(png_right, +14, -40));
        table.addCell(cell);
        pdfdoc.add(table);
        pdfdoc.add(new Paragraph(16));

    } catch (Exception x) {
        x.printStackTrace();
    }
}

From source file:ambit2.data.qmrf.Qmrf_Xml_Pdf.java

License:Open Source License

public void headerTable(Document pdfdoc, org.w3c.dom.Document xmldoc) {
    try {//from   w  w w. j  a  v a2  s . c  o  m
        int header_font_size = 10;
        Image png_left = Image
                .getInstance(Qmrf_Xml_Pdf.class.getClassLoader().getResource("ambit/data/qmrf/logo.png"));
        Image png_right = Image
                .getInstance(Qmrf_Xml_Pdf.class.getClassLoader().getResource("ambit/data/qmrf/logo.png"));
        png_left.setAlignment(Image.LEFT);
        png_right.setAlignment(Image.RIGHT);
        png_left.scalePercent(60);
        png_right.scalePercent(60);
        //png.scaleAbsolute(76, 67);
        //png.setAlignment(Image.MIDDLE);

        PdfPCell cell;

        float[] widths = { 1f, 5f, 1f };
        float[] widths1 = { 1f };
        PdfPTable table = new PdfPTable(widths);
        PdfPTable table1 = new PdfPTable(widths1);

        table.setWidthPercentage(100);

        cell = new PdfPCell();
        cell.setMinimumHeight(70);
        cell.addElement(new Chunk(png_left, +14, -40));
        table.addCell(cell);

        String Text = "";
        try {

            Text = findNodeValue(xml_QMRF_number, xmldoc);
            Chunk ident_title = new Chunk("QMRF identifier (ECB Inventory):");
            Chunk ident_text = new Chunk(Text);

            Font bi_font = new Font(baseFont, header_font_size, Font.BOLDITALIC);
            Font i_font = new Font(baseFont, header_font_size, Font.ITALIC);

            ident_title.setFont(bi_font);
            ident_text.setFont(i_font);
            Paragraph p = new Paragraph();
            p.add(ident_title);
            p.add(ident_text);
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            ident_title = new Chunk("QMRF Title:");
            Phrase textPhrase = new Phrase();
            createNodePhrase("QSAR_title", xmldoc, textPhrase, i_font);
            ident_title.setFont(bi_font);

            p = new Paragraph();
            p.add(ident_title);
            p.add(textPhrase);
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            java.util.Date now = new java.util.Date();
            java.text.DateFormat df = java.text.DateFormat.getDateInstance();
            String date = df.format(now);
            ident_title = new Chunk("Printing Date:");
            ident_text = new Chunk(date);
            ident_title.setFont(bi_font);
            ident_text.setFont(i_font);
            p = new Paragraph();
            p.add(ident_title);
            p.add(ident_text);

            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            p = new Paragraph("");
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);
            cell = new PdfPCell(table1);
            cell.setPadding(0f);
            table.addCell(cell);

        } catch (Throwable x) {
            x.printStackTrace();

        }

        //table.addCell(new PdfPCell(png, true));
        cell.addElement(new Chunk(png_right, +14, -40));
        table.addCell(cell);
        pdfdoc.add(table);
        pdfdoc.add(new Paragraph(16));

    } catch (Exception x) {
        x.printStackTrace();
    }
}

From source file:appli_etudiants.ExportPDF.java

public static void main(Etudiants etudiant)
        throws SQLException, FileNotFoundException, BadElementException, IOException {
    try {/*ww  w.  j  ava  2  s.c o  m*/
        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("c:/tesPDF.pdf"));
        document.open();
        PdfContentByte canvas = writer.getDirectContentUnder();
        Image image = Image.getInstance("c:/fond_cv.jpg");
        image.setAbsolutePosition(0, 80);
        canvas.saveState();
        PdfGState state = new PdfGState();
        state.setFillOpacity(0.6f);
        canvas.setGState(state);
        canvas.addImage(image);
        canvas.restoreState();

        LineSeparator lineSepa = new LineSeparator();
        lineSepa.setLineColor(new Color(21, 96, 189));
        Paragraph para1 = new Paragraph();
        Paragraph para2 = new Paragraph(etudiant.getAdresse_rue());
        Paragraph para3 = new Paragraph(etudiant.getAdresse_cp() + " " + etudiant.getAdresse_ville());
        Paragraph para4 = new Paragraph(etudiant.getCourriel(),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189)));
        Paragraph para5 = new Paragraph(etudiant.getTel_personnel());
        Paragraph para6 = new Paragraph(etudiant.getTel_professionnel());
        Paragraph para7 = new Paragraph(etudiant.getSite_web());
        para1.add(new Chunk(etudiant.getPrenom(),
                FontFactory.getFont(FontFactory.HELVETICA, 20, Font.BOLD, new Color(21, 96, 189))));
        para1.add(
                new Chunk(" " + etudiant.getNom(), FontFactory.getFont(FontFactory.HELVETICA, 20, Font.BOLD)));

        Image image1 = Image.getInstance(DaoS4.getPhoto());
        image1.scalePercent(50);
        image1.setAlignment(Image.RIGHT | Image.TEXTWRAP);
        image1.scaleAbsolute(94, 94);
        document.add(image1);

        document.add(para1);
        document.add(para2);
        document.add(para3);
        document.add(para4);
        document.add(para5);
        document.add(para6);
        para7.setSpacingAfter(25f);
        document.add(para7);
        Paragraph para8 = new Paragraph(DaoS4.getLibelleTitre());
        para8.setSpacingBefore(25f);
        para8.setSpacingAfter(20f);
        document.add(para8);

        Paragraph para9 = new Paragraph(new Chunk("EXPERIENCE PROFESSIONELLE",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189))));
        para9.setSpacingBefore(15f);
        para9.setSpacingAfter(15f);
        document.add(para9);
        document.add(lineSepa);
        Paragraph para10 = new Paragraph(DaoS4.getLibelleExpPro());
        para10.setSpacingAfter(15f);
        document.add(para10);

        Paragraph para11 = new Paragraph(new Chunk("FORMATION",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189))));
        para11.setSpacingBefore(15f);
        para11.setSpacingAfter(15f);
        document.add(para11);
        document.add(lineSepa);
        Paragraph para12 = new Paragraph(DaoS4.getLibelleFormation());
        para12.setSpacingAfter(15f);
        document.add(para12);

        Paragraph para13 = new Paragraph(new Chunk("INFORMATIQUE",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189))));
        para13.setSpacingBefore(15f);
        para13.setSpacingAfter(15f);
        document.add(para13);
        document.add(lineSepa);
        Paragraph para14 = new Paragraph(DaoS4.getLibelleInformatique());
        para14.setSpacingAfter(15f);
        document.add(para14);

        Paragraph para15 = new Paragraph(new Chunk("LANGUE",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189))));
        para15.setSpacingBefore(15f);
        para15.setSpacingAfter(15f);
        document.add(para15);
        document.add(lineSepa);
        Paragraph para16 = new Paragraph(DaoS4.getLibelleLangue());
        para16.setSpacingAfter(15f);
        document.add(para16);

        Paragraph para17 = new Paragraph(new Chunk("CENTRES D'INTERET",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189))));
        para17.setSpacingBefore(15f);
        para17.setSpacingAfter(15f);
        document.add(para17);
        document.add(lineSepa);
        Paragraph para18 = new Paragraph(DaoS4.getLibelleInteret());
        para18.setSpacingAfter(15f);
        document.add(para18);

        document.close();
    } catch (DocumentException ex) {
        Logger.getLogger(ExportPDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.amphisoft.epub2pdf.content.XhtmlHandler.java

License:Open Source License

private void handleImage(String url, String alt, String borderWidth, String alignment)
        throws DocumentException {
    float marginTopPt = document.topMargin();
    float marginBottomPt = document.bottomMargin();
    float marginLeftPt = document.leftMargin();
    float marginRightPt = document.rightMargin();

    if (url == null)
        return;/*from ww w. j a va  2  s .co  m*/
    Image img = null;
    String imgSimpleName = "";
    try {
        File imgFile = new File(xhtmlDir, url);
        String imgPath = imgFile.getCanonicalPath();
        imgSimpleName = imgFile.getName();
        img = Image.getInstance(imgPath);
        if (alt == null) {
            alt = imgSimpleName;
        }
        img.setAlt(alt);
    } catch (Exception e) {
        printlnerr("epub2pdf: problem adding image " + imgSimpleName + ": " + e.getMessage());
        return;
    }
    if (borderWidth != null) {
        int border = Integer.parseInt(borderWidth);
        if (border == 0) {
            img.setBorder(Image.NO_BORDER);
        } else {
            img.setBorder(Image.BOX);
            img.setBorderWidth(border);
        }
    }

    if (alignment != null) {
        int align = Image.DEFAULT;
        if (ElementTags.ALIGN_LEFT.equalsIgnoreCase(alignment))
            align = Image.LEFT;
        else if (ElementTags.ALIGN_RIGHT.equalsIgnoreCase(alignment))
            align = Image.RIGHT;
        else if (ElementTags.ALIGN_MIDDLE.equalsIgnoreCase(alignment))
            align = Image.MIDDLE;
        img.setAlignment(align | Image.TEXTWRAP);
    } else {
        img.setAlignment(Image.MIDDLE);
    }

    Rectangle pageRect = document.getPageSize();
    float verticalMarginTotal = marginTopPt + marginBottomPt;
    float horizontalMarginTotal = marginLeftPt + marginRightPt;

    float imgMaxWidth = pageRect.getWidth() - horizontalMarginTotal - 2;
    float imgMaxHeight = pageRect.getHeight() - verticalMarginTotal - 2;

    float imgOrigWidth = img.getWidth();
    float imgOrigHeight = img.getHeight();

    if (imgOrigHeight > imgMaxHeight || imgOrigWidth > imgMaxWidth) {
        img.scaleToFit(imgMaxWidth, imgMaxHeight);
    }
    boolean addOK = addToDocument(img);
    if (!addOK) {
        System.err.println("** addToDocument(" + img.getUrl() + ") returned false");
    }

}

From source file:com.geek.tutorial.itext.image.TextWrapping.java

License:Open Source License

public TextWrapping() throws Exception {

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("TextWrapping.pdf"));
    document.open();/*from  w ww  . j a v a 2 s  .c o m*/

    for (int i = 0; i < 100; i++) {
        document.add(new Phrase("AAAA ")); // Code 1
    }

    com.lowagie.text.Image image = com.lowagie.text.Image.getInstance("square.jpg");
    image.setAlignment(Image.RIGHT | Image.TEXTWRAP); // Code 2
    document.add(image);

    document.add(new Phrase("\n\n")); // Code 3
    for (int i = 0; i < 100; i++) {
        document.add(new Phrase("BBBB "));
    }

    document.close();

}

From source file:nl.knaw.dans.common.lang.pdf.ExtendedHtmlWorker.java

License:Apache License

public void startElement(String tag, HashMap h) {
    if (!tagsSupported.containsKey(tag))
        return;//from w ww.  j av a2  s.  c  om
    try {
        style.applyStyle(tag, h);
        String follow = (String) FactoryProperties.followTags.get(tag);
        if (follow != null) {
            HashMap prop = new HashMap();
            prop.put(follow, null);
            cprops.addToChain(follow, prop);
            return;
        }
        FactoryProperties.insertStyle(h);
        if (tag.equals("a")) {
            cprops.addToChain(tag, h);
            if (currentParagraph == null)
                currentParagraph = new Paragraph();
            stack.push(currentParagraph);
            currentParagraph = new Paragraph();
            return;
        }
        if (tag.equals("br")) {
            if (currentParagraph == null)
                currentParagraph = new Paragraph();
            currentParagraph.add(factoryProperties.createChunk("\n", cprops));
            return;
        }
        if (tag.equals("font") || tag.equals("span")) {
            cprops.addToChain(tag, h);
            return;
        }
        if (tag.equals("img")) {
            String src = (String) h.get("src");
            if (src == null)
                return;
            cprops.addToChain(tag, h);
            Image img = null;
            if (interfaceProps != null) {
                ImageProvider ip = (ImageProvider) interfaceProps.get("img_provider");
                if (ip != null)
                    img = ip.getImage(src, h, cprops, document);
                if (img == null) {
                    HashMap images = (HashMap) interfaceProps.get("img_static");
                    if (images != null) {
                        Image tim = (Image) images.get(src);
                        if (tim != null)
                            img = Image.getInstance(tim);
                    } else {
                        if (!src.startsWith("http")) { // relative src references only
                            String baseurl = (String) interfaceProps.get("img_baseurl");
                            if (baseurl != null) {
                                src = baseurl + src;
                                img = Image.getInstance(src);
                            }
                        }
                    }
                }
            }
            if (img == null) {
                if (!src.startsWith("http")) {
                    String path = cprops.getProperty("image_path");
                    if (path == null)
                        path = "";
                    src = new File(path, src).getPath();
                }
                img = Image.getInstance(src);
            }
            String align = (String) h.get("align");
            String width = (String) h.get("width");
            String height = (String) h.get("height");
            String before = cprops.getProperty("before");
            String after = cprops.getProperty("after");
            if (before != null)
                img.setSpacingBefore(Float.parseFloat(before));
            if (after != null)
                img.setSpacingAfter(Float.parseFloat(after));
            float wp = lengthParse(width, (int) img.getWidth());
            float lp = lengthParse(height, (int) img.getHeight());
            if (wp > 0 && lp > 0)
                img.scalePercent(wp > lp ? lp : wp);
            else if (wp > 0)
                img.scalePercent(wp);
            else if (lp > 0)
                img.scalePercent(lp);
            img.setWidthPercentage(0);
            if (align != null) {
                endElement("p");
                int ralign = Image.MIDDLE;
                if (align.equalsIgnoreCase("left"))
                    ralign = Image.LEFT;
                else if (align.equalsIgnoreCase("right"))
                    ralign = Image.RIGHT;
                img.setAlignment(ralign);
                Img i = null;
                boolean skip = false;
                if (interfaceProps != null) {
                    i = (Img) interfaceProps.get("img_interface");
                    if (i != null)
                        skip = i.process(img, h, cprops, document);
                }
                if (!skip)
                    document.add(img);
                cprops.removeChain(tag);
            } else {
                cprops.removeChain(tag);
                if (currentParagraph == null)
                    currentParagraph = FactoryProperties.createParagraph(cprops);
                currentParagraph.add(new Chunk(img, 0, 0));
            }
            return;
        }
        endElement("p");
        if (tag.equals("h1") || tag.equals("h2") || tag.equals("h3") || tag.equals("h4") || tag.equals("h5")
                || tag.equals("h6")) {
            if (!h.containsKey("size")) {
                int v = 7 - Integer.parseInt(tag.substring(1));
                h.put("size", Integer.toString(v));
            }
            cprops.addToChain(tag, h);
            return;
        }
        if (tag.equals("ul")) {
            if (pendingLI)
                endElement("li");
            skipText = true;
            cprops.addToChain(tag, h);
            com.lowagie.text.List list = new com.lowagie.text.List(false, 10);
            list.setListSymbol("\u2022");
            String indent = ((String) h.get("indent"));
            if (indent != null && indent.matches("[0-9]+")) {
                list.setSymbolIndent(Integer.valueOf(indent));
            }
            stack.push(list);
            return;
        }
        if (tag.equals("ol")) {
            if (pendingLI)
                endElement("li");
            skipText = true;
            cprops.addToChain(tag, h);
            com.lowagie.text.List list = new com.lowagie.text.List(true, 10);
            String type = ((String) h.get("type"));
            if (type != null && type.toLowerCase().equals("a")) {
                list.setLettered(true);
                list.setNumbered(false);
                list.setLowercase(type.equals("a"));
            }
            String indent = ((String) h.get("indent"));
            if (indent != null && indent.matches("[0-9]+")) {
                list.setSymbolIndent(Integer.valueOf(indent));
            }
            stack.push(list);
            return;
        }
        if (tag.equals("li")) {
            if (pendingLI)
                endElement("li");
            skipText = false;
            pendingLI = true;
            cprops.addToChain(tag, h);
            stack.push(FactoryProperties.createListItem(cprops));
            return;
        }
        if (tag.equals("div") || tag.equals("body")) {
            cprops.addToChain(tag, h);
            return;
        }
        if (tag.equals("pre")) {
            if (!h.containsKey("face")) {
                h.put("face", "Courier");
            }
            cprops.addToChain(tag, h);
            isPRE = true;
            return;
        }
        if (tag.equals("p")) {
            cprops.addToChain(tag, h);
            currentParagraph = FactoryProperties.createParagraph(h);
            return;
        }
        if (tag.equals("tr")) {
            if (pendingTR)
                endElement("tr");
            skipText = true;
            pendingTR = true;
            cprops.addToChain("tr", h);
            return;
        }
        if (tag.equals("td") || tag.equals("th")) {
            if (pendingTD)
                endElement(tag);
            skipText = false;
            pendingTD = true;
            cprops.addToChain("td", h);
            stack.push(new IncCell(tag, cprops));
            return;
        }
        if (tag.equals("table")) {
            cprops.addToChain("table", h);
            IncTable table = new IncTable(h);
            stack.push(table);
            tableState.push(new boolean[] { pendingTR, pendingTD });
            pendingTR = pendingTD = false;
            skipText = true;
            return;
        }
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:org.drools.verifier.doc.DroolsDocsComponentFactory.java

License:Apache License

public void onEndPage(PdfWriter writer, Document document) {

    try {/*from ww w.ja v a  2s  . c o  m*/
        Image image = Image.getInstance(DroolsDocsBuilder.class.getResource("guvnor-webapp.png")); // TODO this image never existed
        image.setAlignment(Image.RIGHT);
        image.scaleAbsolute(100, 30);
        Rectangle page = document.getPageSize();
        PdfPTable head = new PdfPTable(2);

        PdfPCell cell1 = new PdfPCell(image);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell1.setBorder(0);

        head.addCell(cell1);

        PdfPCell cell2 = new PdfPCell(new Phrase(currentDate, DroolsDocsComponentFactory.HEADER_FOOTER_TEXT));
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell2.setBorder(0);

        head.addCell(cell2);

        head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        head.writeSelectedRows(0, -1, document.leftMargin(),
                page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:org.posterita.core.PDFReportGenerator.java

License:Open Source License

protected Image getTextAsImage(String text) throws OperationException {
    try {/*from   www  .  ja v a  2  s .  co  m*/
        PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
        //BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false); 
        BaseFont bf = HEADER_FONT.getBaseFont();
        float size = 10;
        float width = bf.getWidthPoint(text, size);
        template.beginText();
        //template.setRGBColorFillF(1, 1, 1);
        template.setFontAndSize(bf, size);
        template.setTextMatrix(0, 2);
        template.showText(text);
        template.endText();
        template.setWidth(width);
        template.setHeight(size + 2);
        // make an Image object from the template
        Image img = Image.getInstance(template);
        img.setAlignment(Image.RIGHT | Image.TEXTWRAP);

        return img;

    } catch (Exception e) {
        throw new OperationException(e);
    }
}

From source file:org.sakaiproject.tool.assessment.pdf.itext.HTMLWorker.java

License:Mozilla Public License

public void startElement(String tag, HashMap h) {
    if (!tagsSupported.containsKey(tag))
        return;/*w w  w  . j a v  a2 s  . c  o m*/
    try {
        style.applyStyle(tag, h);
        String follow = (String) FactoryProperties.followTags.get(tag);
        if (follow != null) {
            HashMap prop = new HashMap();
            prop.put(follow, null);
            cprops.addToChain(follow, prop);
            return;
        }
        FactoryProperties.insertStyle(h);
        if (tag.equals("a")) {
            cprops.addToChain(tag, h);
            if (currentParagraph == null)
                currentParagraph = new Paragraph();
            stack.push(currentParagraph);
            currentParagraph = new Paragraph();
            return;
        }
        if (tag.equals("br")) {
            if (currentParagraph == null)
                currentParagraph = new Paragraph();
            currentParagraph.add(factoryProperties.createChunk("\n", cprops));
            return;
        }
        if (tag.equals("hr")) {

            PdfPTable hr = new PdfPTable(1);
            hr.setHorizontalAlignment(Element.ALIGN_CENTER);
            hr.setWidthPercentage(100f);
            hr.setSpacingAfter(0f);
            hr.setSpacingBefore(0f);
            PdfPCell cell = new PdfPCell();
            cell.setUseVariableBorders(true);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(PdfPCell.BOTTOM);
            cell.setBorderWidth(1f);
            cell.setPadding(0);
            cell.addElement(factoryProperties.createChunk("\n", cprops));

            hr.addCell(cell);
            // paragraphs can't have tables? really? without it hr's may be rendered a bit early..
            //if (currentParagraph != null)
            //    currentParagraph.add(hr);
            //else
            document.add(hr);
            return;

        }
        if (tag.equals("font") || tag.equals("span")) {
            cprops.addToChain(tag, h);
            return;
        }
        if (tag.equals("img")) {
            String src = (String) h.get("src");
            if (src == null)
                return;
            cprops.addToChain(tag, h);
            Image img = null;
            if (interfaceProps != null) {
                HashMap images = (HashMap) interfaceProps.get("img_static");
                if (images != null) {
                    Image tim = (Image) images.get(src);
                    if (tim != null)
                        img = Image.getInstance(tim);
                } else {
                    if (!src.startsWith("http")) { // relative src references only
                        String baseurl = (String) interfaceProps.get("img_baseurl");
                        if (baseurl != null) {
                            src = baseurl + src;
                            img = Image.getInstance(src);
                        }
                    }
                }
            }
            if (img == null) {
                if (!src.startsWith("http")) {
                    String path = cprops.getProperty("image_path");
                    if (path == null)
                        path = "";
                    src = new File(path, src).getPath();
                    img = Image.getInstance(src);
                } else {
                    byte[] buffer;
                    String srcResource = src.substring(src.indexOf("/content", 0)).replaceAll("/content", "");
                    buffer = getImageStream(URLDecoder.decode(srcResource));
                    img = Image.getInstance(buffer);
                }
            }

            String align = (String) h.get("align");
            String width = (String) h.get("width");
            String height = (String) h.get("height");
            String border = (String) h.get("border");
            String hspace = (String) h.get("hspace");
            String vspace = (String) h.get("vspace");
            String before = cprops.getProperty("before");
            String after = cprops.getProperty("after");
            float wp = 0.0f;
            float lp = 0.0f;
            if (maxWidth > 0 && ((width != null && Integer.parseInt(width) > maxWidth)
                    || (width == null && (int) img.getWidth() > maxWidth))) {
                wp = lengthParse(String.valueOf(maxWidth), (int) img.getWidth());
                lp = wp;
            } else {
                wp = lengthParse(width, (int) img.getWidth());
                lp = lengthParse(height, (int) img.getHeight());
            }
            if (wp > 0 && lp > 0)
                img.scalePercent(wp, lp);
            else if (wp > 0)
                img.scalePercent(wp);
            else if (lp > 0)
                img.scalePercent(lp);
            img.setWidthPercentage(0);
            // border
            if (border != null && !"".equals(border)) {
                try {
                    img.setBorderWidth(Integer.parseInt(border));
                    img.setBorder(Image.BOX);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            // horizonatal space
            if (hspace != null && !"".equals(hspace)) {
                try {
                    img.setSpacingAfter(Float.parseFloat(hspace));
                    img.setSpacingBefore(Float.parseFloat(hspace));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            // horizontal alignment
            if (align != null && (align.equalsIgnoreCase("left") || align.equalsIgnoreCase("right"))) {
                endElement("p");
                int ralign = Image.LEFT;
                if (align.equalsIgnoreCase("right"))
                    ralign = Image.RIGHT;
                img.setAlignment(ralign | Image.TEXTWRAP);
                Img i = null;
                boolean skip = false;
                if (interfaceProps != null) {
                    i = (Img) interfaceProps.get("img_interface");
                    if (i != null)
                        skip = i.process(img, h, cprops, document);
                }
                if (!skip)
                    document.add(img);
                cprops.removeChain(tag);
            }
            // vertical alignment (or none)
            else {
                img.setAlignment(Image.TEXTWRAP);

                float bottom = 0.0f;
                float top = img.getTop();
                float prevHeight = 0.0f;
                float prevRise = 0.0f;

                if (currentParagraph != null) {
                    ArrayList chunks = currentParagraph.getChunks();
                    Chunk sibling = null;

                    for (int k = chunks.size() - 1; k >= 0; k--) {
                        if (chunks.get(k) != null)
                            sibling = (Chunk) chunks.get(k);
                    }

                    if (sibling != null) {
                        if (sibling.hasAttributes())
                            prevRise = sibling.getTextRise();
                        prevHeight = 0.0f;
                        if (sibling.getFont() != null) {
                            prevHeight = sibling.getFont().getCalculatedSize();
                        }
                    }
                }

                if ("absMiddle".equalsIgnoreCase(align)) {
                    if (prevHeight > 0)
                        bottom += (img.getScaledHeight() / 2.0f) - (prevHeight / 2.0f);
                    else if (img.getScaledHeight() > 0)
                        bottom += img.getScaledHeight() / 2.0f;
                } else if ("middle".equalsIgnoreCase(align)) {
                    if (img.getScaledHeight() > 0)
                        bottom += (img.getScaledHeight() / 2.0f);
                } else if ("bottom".equalsIgnoreCase(align) || "baseline".equalsIgnoreCase(align)
                        || "absbottom".equalsIgnoreCase(align)) {
                    //baseline and absbottom should have some slight tweeking from bottom, but not sure what??
                } else if ("top".equalsIgnoreCase(align)) {
                    bottom += img.getScaledHeight() - prevHeight;
                } else if ("texttop".equalsIgnoreCase(align)) {
                    bottom += img.getScaledHeight() - (prevHeight - prevRise);
                }

                cprops.removeChain(tag);
                if (currentParagraph == null) {
                    currentParagraph = FactoryProperties.createParagraph(cprops);
                    bottom = 0f;
                } else if (currentParagraph.isEmpty()) {
                    bottom = 0f;
                }

                currentParagraph.setLeading(2f + bottom, 1.00f);
                currentParagraph.add(new Chunk(img, 0, 0 - bottom));
            }
            return;
        }
        if (tag.equals("blockquote")) {
            cprops.addToChain(tag, h);
            inBLOCK = true;
            if (currentParagraph != null)
                endElement("p");
            currentParagraph = FactoryProperties.createParagraph(cprops);
            currentParagraph.add(factoryProperties.createChunk("\n", cprops));
            return;
        }
        endElement("p");
        if (tag.equals("h1") || tag.equals("h2") || tag.equals("h3") || tag.equals("h4") || tag.equals("h5")
                || tag.equals("h6")) {
            if (!h.containsKey("size")) {
                int v = 8 - Integer.parseInt(tag.substring(1));
                h.put("size", Integer.toString(v));
            }
            cprops.addToChain(tag, h);
            return;
        }
        if (tag.equals("ul")) {
            if (pendingLI)
                endElement("li");
            skipText = true;
            cprops.addToChain(tag, h);
            com.lowagie.text.List list = new com.lowagie.text.List(false, 10);
            list.setListSymbol("\u2022");
            stack.push(list);
            return;
        }
        if (tag.equals("ol")) {
            if (pendingLI)
                endElement("li");
            skipText = true;
            cprops.addToChain(tag, h);
            com.lowagie.text.List list = new com.lowagie.text.List(true, 10);
            stack.push(list);
            return;
        }
        if (tag.equals("li")) {
            if (pendingLI)
                endElement("li");
            skipText = false;
            pendingLI = true;
            cprops.addToChain(tag, h);
            stack.push(FactoryProperties.createListItem(cprops));
            return;
        }
        if (tag.equals("div") || tag.equals("body")) {
            cprops.addToChain(tag, h);
            return;
        }
        if (tag.equals("pre")) {
            if (!h.containsKey("face")) {
                h.put("face", "Courier");
            }
            cprops.addToChain(tag, h);
            isPRE = true;
            return;
        }
        if (tag.equals("p")) {
            cprops.addToChain(tag, h);
            currentParagraph = FactoryProperties.createParagraph(cprops);
            if (inBLOCK) {
                currentParagraph.setIndentationLeft(currentParagraph.getIndentationLeft() + 40.0F);
            }
            return;
        }
        if (tag.equals("tr")) {
            if (pendingTR)
                endElement("tr");
            skipText = true;
            pendingTR = true;
            cprops.addToChain("tr", h);
            return;
        }
        if (tag.equals("td") || tag.equals("th")) {
            if (pendingTD)
                endElement(tag);
            skipText = false;
            pendingTD = true;
            cprops.addToChain("td", h);
            stack.push(new IncCell(tag, cprops));
            return;
        }
        if (tag.equals("table")) {
            cprops.addToChain("table", h);
            IncTable table = new IncTable(h);
            stack.push(table);
            tableState.push(new boolean[] { pendingTR, pendingTD });
            pendingTR = pendingTD = false;
            skipText = true;
            return;
        }
    } catch (Exception e) {
        e.printStackTrace();
        //throw new ExceptionConverter(e);
    }
}