Example usage for com.itextpdf.text Image setAlignment

List of usage examples for com.itextpdf.text Image setAlignment

Introduction

In this page you can find the example usage for com.itextpdf.text Image setAlignment.

Prototype


public void setAlignment(final int alignment) 

Source Link

Document

Sets the alignment for the image.

Usage

From source file:Visao.Relatorio.Relatorio_QuantidadeReclamacoesSexo.java

public void create(OutputStream outputStream, JFreeChart chart) throws DocumentException, IOException {
    Document document = null;/* w  w  w  . j  a  va 2 s. co m*/
    PdfWriter writer = null;

    try {
        //instantiate document and writer
        document = new Document();
        writer = PdfWriter.getInstance(document, outputStream);

        //open document
        document.open();
        Image img = Image.getInstance("src\\Imagens\\logo.png");
        img.setAlignment(Element.ALIGN_CENTER);
        document.add(img);

        //add image
        int width = 400;
        int height = 300;

        BufferedImage bufferedImage = chart.createBufferedImage(width, height);
        Image image = Image.getInstance(writer, bufferedImage, 1.0f);
        document.add(image);

        String saida = "\n\n" + controleRelatorio.numeroReclamacoesSexo();
        document.add(new Paragraph(saida));

        //release resources
        document.close();
        document = null;

        writer.close();
        writer = null;
    } catch (DocumentException | IOException de) {
        throw de;
    } finally {
        //release resources
        if (null != document) {
            try {
                document.close();
            } catch (Exception ex) {
            }
        }

        if (null != writer) {
            try {
                writer.close();
            } catch (Exception ex) {
            }
        }
    }
}

From source file:Visao.Relatorio.Relatorio_QuantidadeReclamacoesUF.java

public void create(OutputStream outputStream, JFreeChart chart) throws DocumentException, IOException {
    Document document = null;/*  www.  j  a va 2s .  com*/
    PdfWriter writer = null;

    try {
        //instantiate document and writer
        document = new Document();
        writer = PdfWriter.getInstance(document, outputStream);

        //open document
        document.open();
        Image img = Image.getInstance("src\\Imagens\\logo.png");
        img.setAlignment(Element.ALIGN_CENTER);
        document.add(img);

        //add image
        int width = 500;
        int height = 400;

        BufferedImage bufferedImage = chart.createBufferedImage(width, height);
        Image image = Image.getInstance(writer, bufferedImage, 1.0f);
        document.add(image);

        Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
        String quebralinha = "\n\nQuantidade de reclamaes por UF\n\n";
        Paragraph preface = new Paragraph(quebralinha, boldFont);
        preface.setAlignment(Element.ALIGN_CENTER);
        document.add(preface);

        PdfPTable table = new PdfPTable(2);

        PdfPCell pdfWordCell = new PdfPCell();
        PdfPCell pdfWordCell1 = new PdfPCell();
        Phrase firstLine = new Phrase("UF", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD));
        Phrase secondLine = new Phrase("Quantidade", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD));

        pdfWordCell.addElement(firstLine);
        pdfWordCell1.addElement(secondLine);

        table.addCell(pdfWordCell);
        table.addCell(pdfWordCell1);

        String consulta = "Select uf, count(codigoreclamacao) from "
                + "Reclamacao group by (uf) order by count(codigoreclamacao) desc";

        Iterator i = dao.getSessao().createSQLQuery(consulta).list().iterator();

        while (i.hasNext()) {
            Object[] reclamacao = (Object[]) i.next();
            table.addCell(reclamacao[0].toString());
            table.addCell(reclamacao[1].toString());
        }

        document.add(table);

        //release resources
        document.close();
        document = null;

        writer.close();
        writer = null;
    } catch (DocumentException | IOException de) {
        throw de;
    } finally {
        //release resources
        if (null != document) {
            try {
                document.close();
            } catch (Exception ex) {
            }
        }

        if (null != writer) {
            try {
                writer.close();
            } catch (Exception ex) {
            }
        }
    }
}

From source file:zzlorbittest3.PdfReporter.java

public void report(AccessInput ai, AccessOutput ao, String path, BufferedImage screenShot) {
    Document doc = new Document();
    try {/*  w  ww.  j av  a 2  s .c  o m*/
        PdfWriter.getInstance(doc, new FileOutputStream(path));
        doc.open();
        Image img;
        String str1, str2;
        addTitle(doc, "");

        /////////////////////////            1             ///////////////////////// 
        addSubTitle(doc, "");
        str1 = ":";
        for (SatelliteInput sli : ai.satelliteInput) {
            str1 += sli.satName + " ";
        }
        addContent(doc, str1);

        Time t1 = new Time(ai.startTime);
        Time t2 = new Time(ai.endTime);
        str1 = String.format("%d%d%d", t1.getBJ(Calendar.YEAR), t1.getBJ(Calendar.MONTH) + 1,
                t1.getBJ(Calendar.DAY_OF_MONTH));
        str2 = String.format("%d%d%d", t2.getBJ(Calendar.YEAR), t2.getBJ(Calendar.MONTH) + 1,
                t2.getBJ(Calendar.DAY_OF_MONTH));
        addContent(doc, ":" + str1 + "  :" + str2);

        /////////////////////////            2             ///////////////////////// 

        int len = ao.timeNodeArray.length;
        //            len=4;
        //            ao.progressArray[0]=0.6f;
        //            ao.progressArray[1]=0.3f;
        //            ao.progressArray[2]=0.9f;

        PdfPic pdfpic = new PdfPic();

        pdfpic.xArray = new float[len];
        pdfpic.xCoorStrArray = new String[len];

        Time t0 = new Time(ao.timeNodeArray[0]);

        //x 
        if (len >= 10) {
            for (int i = 0; i < len; i++) {
                Time t = new Time(ao.timeNodeArray[i]);
                pdfpic.xArray[i] = (t.getGregorianCalendar().getTime().getTime()
                        - t0.getGregorianCalendar().getTime().getTime()) / 1000.0f / 3600;
                if (t.getBJ(Calendar.DAY_OF_MONTH) == 1) {
                    pdfpic.xCoorStrArray[i] = Integer.toString(t.getBJ(Calendar.MONTH) + 1) + "";
                } else {
                    pdfpic.xCoorStrArray[i] = null;
                }
            }
        } else {
            for (int i = 0; i < len; i++) {
                Time t = new Time(ao.timeNodeArray[i]);
                pdfpic.xArray[i] = (t.getGregorianCalendar().getTime().getTime()
                        - t0.getGregorianCalendar().getTime().getTime()) / 1000.0f / 3600;
                if (t.getBJ(Calendar.DAY_OF_MONTH) == 1) {
                    pdfpic.xCoorStrArray[i] = Integer.toString(t.getBJ(Calendar.MONTH) + 1) + "";
                } else if (t.getBJ(Calendar.DAY_OF_MONTH) == 11) {
                    pdfpic.xCoorStrArray[i] = Integer.toString(t.getBJ(Calendar.MONTH) + 1) + "";
                } else if (t.getBJ(Calendar.DAY_OF_MONTH) == 21) {
                    pdfpic.xCoorStrArray[i] = Integer.toString(t.getBJ(Calendar.MONTH) + 1) + "";
                } else {
                    pdfpic.xCoorStrArray[i] = null;
                }
            }

        }

        addSubTitle(doc, "");

        pdfpic.yArray = new float[len];
        for (int i = 0; i < len - 1; i++) {
            for (int j = 0; j < 20; j++) {
                pdfpic.yArray[i] += ao.cloudArray[i][j] * ((1.0f / 20) * j + 0.025f);
            }
            pdfpic.yArray[i] /= ao.totalGrid;
        }
        img = pdfpic.getImage(PdfPic.PDFImageType.CLOUD);
        img.setAlignment(Element.ALIGN_CENTER);
        doc.add(img);

        /////////////////////////            3             ///////////////////////// 

        addSubTitle(doc, "");

        pdfpic.yArray = ao.progressArray;

        img = pdfpic.getImage(PdfPic.PDFImageType.PROGRESS);
        img.setAlignment(Element.ALIGN_CENTER);
        doc.add(img);

        str1 = String.format("%.1f", 100 * ao.progressArray[len - 2]);
        Time t = new Time(ao.timeNodeArray[len - 1]);
        str2 = String.format("%d%d%d", t.getBJ(Calendar.YEAR), 1 + t.getBJ(Calendar.MONTH),
                t.getBJ(Calendar.DAY_OF_MONTH));
        addContent(doc, "" + str1 + "%,:" + str2);

        /////////////////////////            5             ///////////////////////// 
        addSubTitle(doc, "");
        if (screenShot != null) {
            img = Image.getInstance(screenShot, Color.BLACK);
            img.scaleToFit(400, 500);
            img.setAlignment(1);
            doc.add(img);

        }
        str1 = "";
        addContent(doc, str1);

        /////////////////////////            6             ///////////////////////// 

        PdfPTable table;
        Paragraph para;
        PdfPCell cell;
        Font tableFont = new Font(songBaseFont, 8);

        addSubTitle(doc, "");

        table = new PdfPTable(3);
        table.setWidthPercentage(50);
        para = new Paragraph("", tableFont);
        para.setAlignment(Element.ALIGN_CENTER);
        cell = new PdfPCell(para);
        cell.setHorizontalAlignment(1);
        table.addCell(cell);

        para = new Paragraph("", tableFont);
        para.setAlignment(Element.ALIGN_CENTER);
        cell = new PdfPCell(para);
        cell.setHorizontalAlignment(1);
        table.addCell(cell);

        para = new Paragraph("", tableFont);
        para.setAlignment(Element.ALIGN_CENTER);
        cell = new PdfPCell(para);
        cell.setHorizontalAlignment(1);
        table.addCell(cell);

        for (int i = 0; i < ao.regionCoverageInfoArray.length; i++) {
            if (ao.regionCoverageInfoArray[i].regionCode == 0) {
                continue;
            }
            if (ao.regionCoverageInfoArray[i].groundTaskRegionTotalPoint <= 5) {
                continue;
            }
            str1 = ao.regionCoverageInfoArray[i].regionName;
            para = new Paragraph(str1, tableFont);
            para.setAlignment(Element.ALIGN_CENTER);
            cell = new PdfPCell(para);
            cell.setHorizontalAlignment(1);
            table.addCell(cell);

            str1 = String.format("%.1f%%", 100.0f * ao.regionCoverageInfoArray[i].groundTaskRegionTotalPoint
                    / ao.regionCoverageInfoArray[i].totalPoint);
            para = new Paragraph(str1, tableFont);
            para.setAlignment(Element.ALIGN_CENTER);
            cell = new PdfPCell(para);
            cell.setHorizontalAlignment(1);
            table.addCell(cell);

            str1 = String.format("%.1f%%", 100.0f * ao.regionCoverageInfoArray[i].coverageTimes
                    / ao.regionCoverageInfoArray[i].groundTaskRegionTotalPoint);
            para = new Paragraph(str1, tableFont);
            para.setAlignment(Element.ALIGN_CENTER);
            cell = new PdfPCell(para);
            cell.setHorizontalAlignment(1);
            table.addCell(cell);
        }
        doc.add(table);

        /////////////////////////            7             ///////////////////////// 
        addSubTitle(doc, "");
        String summaryString;
        str1 = String.format("%.1f", 100 * ao.progressArray[len - 2]);
        t = new Time(ao.timeNodeArray[len - 1]);
        str2 = String.format("%d%d%d", t.getBJ(Calendar.YEAR), 1 + t.getBJ(Calendar.MONTH),
                t.getBJ(Calendar.DAY_OF_MONTH));
        summaryString = "    "
                + (100.0f * ao.difficultyDegree[0] / ao.totalGrid
                        + 100.0f * ao.difficultyDegree[1] / ao.totalGrid >= 50f ? "" : "");
        addContent(doc, summaryString);
        summaryString = "    " + str1 + "  " + str2 + "";
        addContent(doc, summaryString);
        summaryString = String.format("    : %.1f%%,%.1f%%",
                100.0f * ao.difficultyDegree[0] / ao.totalGrid, 100.0f * ao.difficultyDegree[1] / ao.totalGrid);
        addContent(doc, summaryString);
        summaryString = String.format("    : %.1f%%,%.1f%%",
                100.0f * ao.difficultyDegree[2] / ao.totalGrid, 100.0f * ao.difficultyDegree[3] / ao.totalGrid);
        addContent(doc, summaryString);

        //            summaryString = "2";
        //            addContent(doc, summaryString);

        //////////////////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////          1           ////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////////////////////////

        doc.newPage();
        this.addSubTitle(doc, "1 ");

        table = new PdfPTable(11);
        tableFont = new Font(songBaseFont, 8);
        table.addCell("");
        for (int i = 0; i < 100; i += 10) {
            String str = String.format("%02d%%-%02d%%", i, i + 10);
            para = new Paragraph(str, tableFont);
            para.setAlignment(Element.ALIGN_CENTER);
            cell = new PdfPCell(para);
            cell.setHorizontalAlignment(1);
            table.addCell(cell);
        }

        for (int i = 0; i < len - 1; i++) {

            t = new Time(ao.timeNodeArray[i]);
            int day = t.getBJ(Calendar.DAY_OF_MONTH);
            int mon = 1 + t.getBJ((Calendar.MONTH));
            String str = Integer.toString(mon) + "";
            if (i == 0) {
                if (day < 11) {
                    str += "";
                } else if (day < 21) {
                    str += "";
                } else {
                    str += "";
                }
            } else {
                if (day == 1) {
                    str += "";
                } else if (day == 11) {
                    str += "";
                } else if (day == 21) {
                    str += "";
                } else {
                    continue;
                }
            }

            para = new Paragraph(str, tableFont);
            para.setAlignment(Element.ALIGN_CENTER);
            cell = new PdfPCell(para);
            cell.setHorizontalAlignment(1);
            table.addCell(cell);
            for (int j = 0; j < 10; j++) {

                str = String.format("%.1f%%",
                        100.0f * (ao.cloudArray[i][2 * j] + ao.cloudArray[i][2 * j + 1]) / ao.totalGrid);
                para = new Paragraph(str, tableFont);
                para.setAlignment(Element.ALIGN_CENTER);
                cell = new PdfPCell(para);
                cell.setHorizontalAlignment(1);
                table.addCell(cell);
            }

        }

        doc.add(table);

        //////////////////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////          2           ////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////////////////////////           

        doc.newPage();
        this.addSubTitle(doc, "2 ");

        float[] widthArray = new float[] { 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2 };
        table = new PdfPTable(widthArray);
        tableFont = new Font(songBaseFont, 8);
        table.addCell("");
        for (int i = 0; i < 13; i++) {
            String str = String.format("%02d", i);
            if (i == 12) {
                str = String.format("%02d", i);
            }
            para = new Paragraph(str, tableFont);
            para.setAlignment(Element.ALIGN_CENTER);
            cell = new PdfPCell(para);
            cell.setHorizontalAlignment(1);
            table.addCell(cell);
        }

        for (int i = 0; i < len - 1; i++) {

            t = new Time(ao.timeNodeArray[i]);
            int day = t.getBJ(Calendar.DAY_OF_MONTH);
            int mon = 1 + t.getBJ((Calendar.MONTH));
            String str = Integer.toString(mon) + "";
            if (i == 0) {
                if (day < 11) {
                    str += "";
                } else if (day < 21) {
                    str += "";
                } else {
                    str += "";
                }
            } else {
                if (day == 1) {
                    str += "";
                } else if (day == 11) {
                    str += "";
                } else if (day == 21) {
                    str += "";
                } else {
                    continue;
                }
            }

            para = new Paragraph(str, tableFont);
            para.setAlignment(Element.ALIGN_CENTER);
            cell = new PdfPCell(para);
            cell.setHorizontalAlignment(1);
            table.addCell(cell);
            for (int j = 0; j < 13; j++) {
                str = String.format("%.1f%%", 100.0f * ao.coverageTimesArray[i][j] / ao.totalGrid);
                if (j == 12) {
                    str = String.format("%.1f%%",
                            100.0f * (ao.coverageTimesArray[i][12] + ao.coverageTimesArray[i][13]
                                    + ao.coverageTimesArray[i][14] + ao.coverageTimesArray[i][15]
                                    + ao.coverageTimesArray[i][16] + ao.coverageTimesArray[i][17]
                                    + ao.coverageTimesArray[i][18] + ao.coverageTimesArray[i][19])
                                    / ao.totalGrid);
                }
                para = new Paragraph(str, tableFont);
                para.setAlignment(Element.ALIGN_CENTER);
                cell = new PdfPCell(para);
                cell.setHorizontalAlignment(1);
                table.addCell(cell);
            }

        }

        doc.add(table);
        doc.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}