Example usage for com.lowagie.text PageSize A4

List of usage examples for com.lowagie.text PageSize A4

Introduction

In this page you can find the example usage for com.lowagie.text PageSize A4.

Prototype

Rectangle A4

To view the source code for com.lowagie.text PageSize A4.

Click Source Link

Document

This is the a4 format

Usage

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_cabinetWord(String filename, String room) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;//  w w w.  j a  v a2  s.c  o  m
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        RtfWriter2.getInstance(document, new FileOutputStream(filename));
        document.open();
        // new File(filename)
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        // title.setFont(titleFont);
        List cabinetlist = (List) reportHash.get("cabinetlist");

        Paragraph context = new Paragraph();
        // 
        context.setAlignment(Element.ALIGN_CENTER);
        //         context.setFont(contextFont);
        // 
        //         context.setSpacingBefore(0);
        // 
        //         context.setFirstLineIndent(6);
        //         document.add(context);
        //         document.add(new Paragraph("\n"));
        Table aTable = new Table(6);
        //         float[] widths = { 220f, 220f, 220f, 110f, 110f, 110f, 110f, 220f };
        //         aTable.setWidths(widths);
        aTable.setWidth(100); //  90%
        aTable.setAlignment(Element.ALIGN_CENTER);// 
        aTable.setAutoFillEmptyCells(true); // 
        //         aTable.setBorderWidth(1); // 
        //         aTable.setBorderColor(new Color(0, 125, 255)); // 
        //         aTable.setPadding(2);// 
        //         aTable.setSpacing(4);// 
        //         aTable.setBorder(2);// 
        Cell cell = null;
        cell = new Cell(new Phrase(room + "", titleFont));
        cell.setRowspan(2);
        cell.setColspan(6);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setRowspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("", titleFont));
        cell.setRowspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("U", titleFont));
        cell.setRowspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("U", titleFont));
        cell.setRowspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("U", titleFont));
        cell.setRowspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("U(%)", titleFont));
        cell.setRowspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        Cabinet cabinet = null;
        if (cabinetlist != null && cabinetlist.size() > 0) {
            for (int i = 0; i < cabinetlist.size(); i++) {

                cabinet = (Cabinet) cabinetlist.get(i);
                cell = new Cell(new Phrase(1 + i + "", contextFont));
                cell.setRowspan(2);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);
                cell = new Cell(new Phrase(cabinet.getName(), contextFont));
                cell.setRowspan(2);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);

                cell = new Cell(new Phrase(cabinet.getAllu(), contextFont));
                cell.setRowspan(2);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);
                cell = new Cell(new Phrase(cabinet.getUseu(), contextFont));
                cell.setRowspan(2);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);
                cell = new Cell(new Phrase(cabinet.getTempu(), contextFont));
                cell.setRowspan(2);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);
                cell = new Cell(new Phrase(cabinet.getRateu(), contextFont));
                cell.setRowspan(2);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);

            }
        }
        document.add(aTable);
        document.close();
    } catch (Exception e) {
        // TODO: handle exception
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_equipmentWord(String filename, String roomname, String cabinetname, String uselect,
        String unumber, String rate) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;/*from www  .j  ava2  s.c o  m*/
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        RtfWriter2.getInstance(document, new FileOutputStream(filename));
        document.open();
        // new File(filename)
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        // title.setFont(titleFont);
        List equipmentlist = (List) reportHash.get("equipmentlist");

        Paragraph context = new Paragraph();
        // 
        context.setAlignment(Element.ALIGN_CENTER);
        //         context.setFont(contextFont);
        // 
        //         context.setSpacingBefore(0);
        // 
        //         context.setFirstLineIndent(6);
        //         document.add(context);
        //         document.add(new Paragraph("\n"));
        Table aTable = new Table(6);
        //         float[] widths = { 220f, 220f, 220f, 110f, 110f, 110f, 110f, 220f };
        //         aTable.setWidths(widths);
        aTable.setWidth(100); //  90%
        aTable.setAlignment(Element.ALIGN_CENTER);// 
        aTable.setAutoFillEmptyCells(true); // 
        //         aTable.setBorderWidth(1); // 
        //         aTable.setBorderColor(new Color(0, 125, 255)); // 
        //         aTable.setPadding(2);// 
        //         aTable.setSpacing(4);// 
        //         aTable.setBorder(2);// 
        Cell cell = null;
        cell = new Cell(new Phrase(roomname + cabinetname + "", titleFont));
        cell.setColspan(6);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase(":" + roomname, titleFont));
        cell.setColspan(3);
        this.setCellFormat(cell, false);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase(":" + cabinetname, titleFont));
        cell.setColspan(3);
        this.setCellFormat(cell, false);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("U:" + uselect, titleFont));
        cell.setColspan(2);
        this.setCellFormat(cell, false);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase(":" + unumber, titleFont));
        cell.setColspan(2);
        this.setCellFormat(cell, false);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase(":" + rate, titleFont));
        cell.setColspan(2);
        this.setCellFormat(cell, false);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("", titleFont));

        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("", titleFont));

        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("", titleFont));

        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("", titleFont));

        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("", titleFont));

        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("", titleFont));

        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        EquipmentReport equipmentReport = null;
        if (equipmentlist != null && equipmentlist.size() > 0) {
            for (int i = 0; i < equipmentlist.size(); i++) {

                equipmentReport = (EquipmentReport) equipmentlist.get(i);
                cell = new Cell(new Phrase(1 + i + "", contextFont));

                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);
                cell = new Cell(new Phrase(equipmentReport.getEquipmentname(), contextFont));

                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);

                cell = new Cell(new Phrase(equipmentReport.getEquipmentdesc(), contextFont));

                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);
                cell = new Cell(new Phrase(equipmentReport.getOperation(), contextFont));

                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);
                cell = new Cell(new Phrase(equipmentReport.getContactname(), contextFont));

                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);
                cell = new Cell(new Phrase(equipmentReport.getContactphone(), contextFont));

                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);

            }
        }
        document.add(aTable);
        document.close();
    } catch (Exception e) {
        // TODO: handle exception
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_OperEquipmentWord(String filename, String opername, String contactname,
        String contactphone) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;/* w w  w  .ja  v  a  2 s .  co  m*/
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        RtfWriter2.getInstance(document, new FileOutputStream(filename));
        document.open();
        // new File(filename)
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        // title.setFont(titleFont);
        List equipmentlist = (List) reportHash.get("equipmentlist");

        Paragraph context = new Paragraph();
        // 
        context.setAlignment(Element.ALIGN_CENTER);
        //         context.setFont(contextFont);
        // 
        //         context.setSpacingBefore(0);
        // 
        //         context.setFirstLineIndent(6);
        //         document.add(context);
        //         document.add(new Paragraph("\n"));
        Table aTable = new Table(7);
        //         float[] widths = { 220f, 220f, 220f, 110f, 110f, 110f, 110f, 220f };
        //         aTable.setWidths(widths);
        aTable.setWidth(100); //  90%
        aTable.setAlignment(Element.ALIGN_CENTER);// 
        aTable.setAutoFillEmptyCells(true); // 
        //         aTable.setBorderWidth(1); // 
        //         aTable.setBorderColor(new Color(0, 125, 255)); // 
        //         aTable.setPadding(2);// 
        //         aTable.setSpacing(4);// 
        //         aTable.setBorder(2);// 
        Cell cell = null;
        cell = new Cell(new Phrase(opername + "", titleFont));
        cell.setColspan(7);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase(":" + opername, titleFont));
        cell.setColspan(2);
        this.setCellFormat(cell, false);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase(":" + contactname, titleFont));
        cell.setColspan(2);
        this.setCellFormat(cell, false);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase(":" + contactphone, titleFont));
        cell.setColspan(3);
        this.setCellFormat(cell, false);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("", titleFont));

        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("", titleFont));

        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("U", titleFont));

        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("", titleFont));

        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("IP", titleFont));

        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("", titleFont));

        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        cell = new Cell(new Phrase("", titleFont));

        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        OperCabinet operCabinet = null;
        if (equipmentlist != null && equipmentlist.size() > 0) {
            for (int i = 0; i < equipmentlist.size(); i++) {

                operCabinet = (OperCabinet) equipmentlist.get(i);
                cell = new Cell(new Phrase(operCabinet.getRoomname(), contextFont));

                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);
                cell = new Cell(new Phrase(operCabinet.getCabinetname(), contextFont));

                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);

                cell = new Cell(new Phrase(operCabinet.getUseu(), contextFont));

                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);
                cell = new Cell(new Phrase(operCabinet.getEquipmentname(), contextFont));

                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);
                cell = new Cell(new Phrase(operCabinet.getIpaddress(), contextFont));

                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);
                cell = new Cell(new Phrase(operCabinet.getCabinetname(), contextFont));

                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);
                cell = new Cell(new Phrase(operCabinet.getContactphone(), contextFont));

                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable.addCell(cell);

            }
        }
        document.add(aTable);
        document.close();
    } catch (Exception e) {
        // TODO: handle exception
    }
}

From source file:com.allinfinance.system.util.PdfUtil.java

License:Open Source License

public static void create(String mchtId, String selMchtId, String path, List<Object[]> list,
        LinkedHashMap<String, List<Object[]>> map, Set<String> set) throws Exception {

    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

    ////from   ww  w  . ja  va2s  .  c  o  m
    Font font17 = new Font(bfChinese, 17, Font.BOLD);
    Font font8 = new Font(bfChinese, 8, Font.NORMAL);
    Font font9 = new Font(bfChinese, 9, Font.NORMAL);
    Font font9Bold = new Font(bfChinese, 9, Font.BOLD);
    Font font8Red = new Font(bfChinese, 8, Font.NORMAL);
    font8Red.setColor(Color.RED);
    Font font8Green = new Font(bfChinese, 8, Font.NORMAL);
    font8Green.setColor(Color.GREEN);

    logger.info("Starting build document...");

    Document document = new Document(PageSize.A4, 36, 36, 36, 36);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
    document.open();
    LINECANVAS border = new LINECANVAS();

    //
    float[] widths = { 0.1f, 0.35f, 0.35f, 0.1f, 0.1f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    table.getDefaultCell().setFixedHeight(12);

    //CELL
    PdfPCell cellMchntId = new PdfPCell(new Paragraph(mchtId, font8));
    cellMchntId.setBorder(PdfPCell.BOTTOM);
    cellMchntId.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell cellMchntName = new PdfPCell(new Paragraph(InformationUtil.getMchtName(mchtId), font8));
    cellMchntName.setBorder(PdfPCell.BOTTOM);
    cellMchntName.setHorizontalAlignment(Element.ALIGN_CENTER);

    String point = InformationUtil.getCurPaperPoint(selMchtId);
    PdfPCell cellPoint;
    cellPoint = new PdfPCell(new Paragraph(point, font8Red));
    cellPoint.setBorder(PdfPCell.NO_BORDER);
    cellPoint.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell cellLevel;
    String level = InformationUtil.getCurPaperLevel(selMchtId);
    if (Integer.valueOf(point) >= 60) {
        cellLevel = new PdfPCell(new Paragraph(level, font8Green));
    } else {
        cellLevel = new PdfPCell(new Paragraph(level, font8Red));
    }
    cellLevel.setBorder(PdfPCell.NO_BORDER);
    cellLevel.setHorizontalAlignment(Element.ALIGN_CENTER);

    //
    Image img = Image.getInstance(
            ServletActionContext.getServletContext().getResource("/ext/resources/images/Title_logo.gif"));
    img.scalePercent(70);
    float w = img.getScaledWidth();
    float h = img.getScaledHeight();
    writer.getDirectContent().addImage(img, w, 0, 0, h, 36, PageSize.A4.getHeight() - 36 - h);

    //
    PdfPCell cell = new PdfPCell(new Paragraph("?", font17));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setColspan(5);
    cell.setFixedHeight(h);
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setFixedHeight(20);
    cell.setColspan(5);
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);

    table.addCell(new Paragraph("?", font8));
    table.addCell(cellMchntId);
    table.addCell(" ");
    table.addCell(new Paragraph(": ", font8));
    table.addCell(cellPoint);

    table.addCell(new Paragraph("??", font8));
    table.addCell(cellMchntName);
    table.addCell(" ");
    table.addCell(new Paragraph(": ", font8));
    table.addCell(cellLevel);

    document.add(table);
    document.add(new Paragraph("\n\n"));

    //?
    PdfPTable t = new PdfPTable(1);

    Iterator<Object[]> it0 = list.iterator();
    int i = 1;
    while (it0.hasNext()) {
        Object[] obj = it0.next();
        PdfPCell c = new PdfPCell();
        c.addElement(new Paragraph("Q" + String.valueOf(i++) + "" + obj[1].toString(), font9Bold));
        List<Object[]> opts = map.get(obj[0].toString());
        String opt = "";
        Iterator<Object[]> it1 = opts.iterator();
        while (it1.hasNext()) {
            Object[] o = it1.next();
            if (set.contains(o[0])) {
                opt += "? ";
                opt += o[1].toString();
                opt += "         ";
            } else {
                opt += " ";
                opt += o[1].toString();
                opt += "         ";
            }
        }
        c.addElement(new Paragraph(opt.trim(), font9));
        c.setBorder(PdfPCell.NO_BORDER);
        if (i - 1 != list.size()) {
            c.setCellEvent(border);
        }
        t.addCell(c);
    }

    PdfPTable oTable = new PdfPTable(1);
    oTable.setWidthPercentage(100);
    PdfPCell ce = new PdfPCell(t);
    ce.setBorderColor(Color.GRAY);
    oTable.addCell(ce);

    document.add(oTable);

    document.close();

    logger.info("Finish build document...");

}

From source file:com.allinfinance.system.util.PdfUtil.java

License:Open Source License

public static void create(String path, List<Object[]> list, LinkedHashMap<String, List<Object[]>> map)
        throws Exception {

    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

    ////from www. j a  va 2  s .  c  om
    Font font17 = new Font(bfChinese, 17, Font.BOLD);
    Font font8 = new Font(bfChinese, 8, Font.NORMAL);
    Font font10 = new Font(bfChinese, 10, Font.NORMAL);
    Font font10Bold = new Font(bfChinese, 10, Font.BOLD);
    Font font8Red = new Font(bfChinese, 8, Font.NORMAL);
    font8Red.setColor(Color.RED);
    Font font8Green = new Font(bfChinese, 8, Font.NORMAL);
    font8Green.setColor(Color.GREEN);

    logger.info("Starting build document...");

    Document document = new Document(PageSize.A4, 36, 36, 36, 36);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
    document.open();
    LINECANVAS border = new LINECANVAS();

    //
    float[] widths = { 0.1f, 0.35f, 0.55f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    table.getDefaultCell().setFixedHeight(12);

    //CELL
    PdfPCell cellMchntId = new PdfPCell(new Paragraph("XXXXXXXXXXXXXXX", font8));
    cellMchntId.setBorder(PdfPCell.BOTTOM);
    cellMchntId.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell cellMchntName = new PdfPCell(new Paragraph("?", font8));
    cellMchntName.setBorder(PdfPCell.BOTTOM);
    cellMchntName.setHorizontalAlignment(Element.ALIGN_CENTER);

    //
    Image img = Image.getInstance(
            ServletActionContext.getServletContext().getResource("/ext/resources/images/Title_logo.gif"));
    img.scalePercent(70);
    float w = img.getScaledWidth();
    float h = img.getScaledHeight();
    writer.getDirectContent().addImage(img, w, 0, 0, h, 36, PageSize.A4.getHeight() - 36 - h);

    //
    PdfPCell cell = new PdfPCell(new Paragraph("?", font17));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setColspan(3);
    cell.setFixedHeight(h);
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setFixedHeight(20);
    cell.setColspan(3);
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);

    table.addCell(new Paragraph("?", font8));
    table.addCell(cellMchntId);
    table.addCell(" ");

    table.addCell(new Paragraph("??", font8));
    table.addCell(cellMchntName);
    table.addCell(" ");

    document.add(table);
    document.add(new Paragraph("\n\n"));

    //?
    PdfPTable t = new PdfPTable(1);

    Iterator<Object[]> it0 = list.iterator();
    int i = 1;
    while (it0.hasNext()) {
        Object[] obj = it0.next();
        PdfPCell c = new PdfPCell();
        c.addElement(new Paragraph("Q" + String.valueOf(i++) + "" + obj[1].toString(), font10Bold));
        List<Object[]> opts = map.get(obj[0].toString());
        String opt = "";
        Iterator<Object[]> it1 = opts.iterator();
        while (it1.hasNext()) {
            Object[] o = it1.next();
            opt += " ";
            opt += o[1].toString();
            opt += "         ";
        }
        c.addElement(new Paragraph(opt.trim(), font10));
        c.setBorder(PdfPCell.NO_BORDER);
        if (i - 1 != list.size()) {
            c.setCellEvent(border);
        }
        t.addCell(c);
    }

    PdfPTable oTable = new PdfPTable(1);
    oTable.setWidthPercentage(100);
    PdfPCell ce = new PdfPCell(t);
    ce.setBorderColor(Color.GRAY);
    oTable.addCell(ce);

    document.add(oTable);

    document.close();

    logger.info("Finish build document...");

}

From source file:com.anevis.jfreechartsamplespring.chart.ChartServiceImpl.java

private byte[] writeChartsToDocument(JFreeChart... charts) {
    try {//from  w w w.j  a v a2s.  c o m
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        float width = PageSize.A4.getWidth();
        float height = PageSize.A4.getHeight() / 2;
        int index = 0;

        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        document.open();
        PdfContentByte contentByte = writer.getDirectContent();

        for (JFreeChart chart : charts) {

            PdfTemplate template = contentByte.createTemplate(width, height);
            Graphics2D graphics2D = template.createGraphics(width, height);
            Rectangle2D rectangle2D = new Rectangle2D.Double(0, 0, width, height);

            chart.draw(graphics2D, rectangle2D);

            graphics2D.dispose();
            contentByte.addTemplate(template, 0, height - (height * index));
            index++;
        }

        writer.flush();
        document.close();

        return baos.toByteArray();
    } catch (DocumentException ex) {
        Logger.getLogger(ChartService.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:com.AppModel.Reportes.GeneraPdf.java

public void generarArchivoPdf(String xml) {
    try {/*  www .  ja v a  2s. c  o  m*/
        Document document = new Document(PageSize.A4);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream("plantillaa.pdf"));
        document.open();
        document.addAuthor("Persona creadora");
        document.addCreator("Software generador");
        document.addCreationDate();
        document.addTitle("Titulo del documento");

        HTMLWorker htmlWorker = new HTMLWorker(document);
        //            String str = "<table>\n"
        //                    + "            <tr>\n"
        //                    + "                <td>Boleta</td>\n"
        //                    + "                <td>Fecha</td>\n"
        //                    + "                <th>Operacion</th>\n"
        //                    + "                <td>Abono</td>\n"
        //                    + "                <td>Interes generado </td>\n"
        //                    + "                <td>Cargo</td>\n"
        //                    + "                <td>Usuario que realizo el movimiento</td>    \n"
        //                    + "            </tr>\n"
        //                    + "            <tr>\n"
        //                    + "                <td align=center>MLOM005817</td>\n"
        //                    + "                <td align=center>2015-04-19 15:53:37.0</td>\n"
        //                    + "                <td align=center>Nuevo empeo</td>\n"
        //                    + "                <td align=center></td>\n"
        //                    + "                <td align=center></td>\n"
        //                    + "                <td align=center>$533.00</td>\n"
        //                    + "                <td align=center>admin</td>\n"
        //                    + "            </tr>\n"
        //                    + "            <tr>\n"
        //                    + "                <td align=center>MLOM005817</td>\n"
        //                    + "                <td align=center>2015-04-19 15:56:04.0</td>\n"
        //                    + "                <td align=center>Extension de contrato</td>\n"
        //                    + "                <td align=center></td><td align=center>$1.44</td>\n"
        //                    + "                <td align=center></td>\n"
        //                    + "                <td align=center>admin</td>\n"
        //                    + "            </tr>\n"
        //                    + "            <tr>\n"
        //                    + "                <td align=center>MLOM005817</td>\n"
        //                    + "                <td align=center>2015-04-19 16:00:51.0</td>\n"
        //                    + "                <td align=center>Desempeo</td>\n"
        //                    + "                <td align=center>$554.64 </td>\n"
        //                    + "                <td align=center>$21.64 </td>\n"
        //                    + "                <td align=center></td>\n"
        //                    + "                <td align=center>admin</td>\n"
        //                    + "            </tr>\n"
        //                    + "            <tr>\n"
        //                    + "                <td align=center>MLOM005818</td>\n"
        //                    + "                <td align=center>2015-04-19 16:37:24.0</td>\n"
        //                    + "                <td align=center>Refrendo</td>\n"
        //                    + "                <td align=center>$533.00 </td>\n"
        //                    + "                <td align=center>$21.64 </td>\n"
        //                    + "                <td align=center>$533.00 </td>\n"
        //                    + "                <td align=center>admin</td>\n"
        //                    + "            </tr>\n"
        //                    + "            <tr>\n"
        //                    + "                <td></td>\n"
        //                    + "                <td></td>\n"
        //                    + "                <td></td>\n"
        //                    + "                <td></td>\n"
        //                    + "                <td align=center><b>$1,087.64 pesos</b> </td>\n"
        //                    + "                <td align=center><b>$44.72 pesos</b> </td>\n"
        //                    + "                <td align=center><b>$1,066.00 pesos</b> </td>\n"
        //                    + "            </tr>\n"
        //                    + "            <tr style=height:50px;>\n"
        //                    + "                <td align=right colspan=7> </td>\n"
        //                    + "                <td  align=left colspan=5><b>El monto de apertura dia fue de: $90000.0 pesos</b> </td>\n"
        //                    + "                <td  align=left colspan=5><b id='saldoAlCierre' title='89511.72'>Saldo al cierre: $89511.72 pesos</b> </td>\n"
        //                    + "            </tr>\n"
        //                    + "        </table>";
        String str = "<table>\n" + "            <tr>\n" + "                <td>Boleta</td>\n"
                + "                <td>Fecha</td>\n" + "                <th>Operacion</th>\n"
                + "                <td>Abono</td>\n" + "                <td>Interes generado </td>\n"
                + "                <td>Cargo</td>\n"
                + "                <td>Usuario que realizo el movimiento</td>    \n" + "            </tr>\n"
                + "            <tr>\n" + "                <td align=center>MLOM005817</td>\n"
                + "                <td align=center>2015-04-19 15:53:37.0</td>\n"
                + "                <td align=center>Nuevo empeo</td>\n"
                + "                <td align=center></td>\n" + "                <td align=center></td>\n"
                + "                <td align=center>$533.00</td>\n"
                + "                <td align=center>admin</td>\n" + "            </tr>\n" + "            <tr>\n"
                + "                <td align=center>MLOM005817</td>\n"
                + "                <td align=center>2015-04-19 15:56:04.0</td>\n"
                + "                <td align=center>Extension de contrato</td>\n"
                + "                <td align=center></td><td align=center>$1.44</td>\n"
                + "                <td align=center></td>\n" + "                <td align=center>admin</td>\n"
                + "            </tr>\n" + "            <tr>\n"
                + "                <td align=center>MLOM005817</td>\n"
                + "                <td align=center>2015-04-19 16:00:51.0</td>\n"
                + "                <td align=center>Desempeo</td>\n"
                + "                <td align=center>$554.64 </td>\n"
                + "                <td align=center>$21.64 </td>\n" + "                <td align=center></td>\n"
                + "                <td align=center>admin</td>\n" + "            </tr>\n" + "            <tr>\n"
                + "                <td align=center>MLOM005818</td>\n"
                + "                <td align=center>2015-04-19 16:37:24.0</td>\n"
                + "                <td align=center>Refrendo</td>\n"
                + "                <td align=center>$533.00 </td>\n"
                + "                <td align=center>$21.64 </td>\n"
                + "                <td align=center>$533.00 </td>\n"
                + "                <td align=center>admin</td>\n" + "            </tr>\n" + "            <tr>\n"
                + "                <td></td>\n" + "                <td></td>\n" + "                <td></td>\n"
                + "                <td align=center><b>$1,087.64 pesos</b> </td>\n"
                + "                <td align=center><b>$44.72 pesos</b> </td>\n"
                + "                <td align=center><b>$1,066.00 pesos</b> </td>\n" + "            </tr>\n"
                + "            <tr style=height:50px;>\n" + "                <td align=right colspan=7> </td>\n"
                + "            </tr><tr>\n"
                + "                <td  align=left colspan=5><b>El monto de apertura dia fue de: $90000.0 pesos</b> </td>\n"
                + "            </tr><tr>\n"
                + "                <td  align=left colspan=5><b id='saldoAlCierre' title='89511.72'>Saldo al cierre: $89511.72 pesos</b> </td>\n"
                + "            </tr>\n" + "        </table>";
        htmlWorker.parse(new StringReader(str));
        document.close();
    } catch (Exception e) {
        System.out.println("" + e.getMessage());
    }

}

From source file:com.aripd.clms.service.ContractServiceBean.java

@Override
public void generatePdf(ContractEntity contract) {
    String baseFontUrl = "/fonts/Quivira.otf";
    FontFactory.register(baseFontUrl);// ww  w  . j av a2 s .  c om

    ByteArrayOutputStream output = new ByteArrayOutputStream();
    try {
        BaseFont bf = BaseFont.createFont(baseFontUrl, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        Font font18n = new Font(bf, 18, Font.NORMAL);
        Font font12n = new Font(bf, 12, Font.NORMAL);
        Font font8n = new Font(bf, 8, Font.NORMAL);
        Font font8nbu = new Font(bf, 8, Font.BOLD | Font.UNDERLINE);
        Font font8ng = new Font(bf, 8, Font.NORMAL, Color.DARK_GRAY);
        Font font6n = new Font(bf, 6, Font.NORMAL);

        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, output);
        document.open();
        addMetaData(document);
        addTitlePage(document, contract);
        Image imgBlue = Image.getInstance(1, 1, 3, 8, new byte[] { (byte) 0, (byte) 0, (byte) 255, });
        imgBlue.scaleAbsolute(document.getPageSize().getWidth(), 10);
        imgBlue.setAbsolutePosition(0, document.getPageSize().getHeight() - imgBlue.getScaledHeight());
        PdfImage stream = new PdfImage(imgBlue, "", null);
        stream.put(new PdfName("ITXT_SpecialId"), new PdfName("123456789"));
        PdfIndirectObject ref = writer.addToBody(stream);
        imgBlue.setDirectReference(ref.getIndirectReference());
        document.add(imgBlue);

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

        PdfPCell cell = new PdfPCell(new Paragraph(contract.getName(), font18n));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        cell.setPadding(5);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph("Version: " + contract.getVersion(), font8n));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        cell.setPadding(5);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph("Review: " + contract.getReview(), font8n));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        cell.setPadding(5);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(contract.getRemark(), font12n));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        cell.setPadding(5);
        table.addCell(cell);
        document.add(table);
        // Start a new page
        document.newPage();

        HTMLWorker htmlWorker = new HTMLWorker(document);
        htmlWorker.parse(new StringReader(contract.getRemark()));
        // Start a new page
        document.newPage();

        document.add(new Paragraph("Review Board", font18n));
        document.add(new LineSeparator(0.5f, 100, null, 0, -5));

        table = new PdfPTable(3);
        table.setWidthPercentage(100);

        cell = new PdfPCell(new Paragraph("Review Board", font18n));
        cell.setColspan(3);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph("Version", font12n));
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph("Date", font12n));
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph("Review", font12n));
        table.addCell(cell);
        for (HistoryContractEntity history : historyContractService.listing(contract)) {
            cell = new PdfPCell(new Paragraph(history.getVersion().toString(), font8n));
            table.addCell(cell);
            cell = new PdfPCell(new Paragraph(history.getStartdate().toString(), font8n));
            table.addCell(cell);
            cell = new PdfPCell(new Paragraph(history.getReview(), font8n));
            table.addCell(cell);
        }
        document.add(table);

        document.close();

        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
        response.reset();
        response.addHeader("Content-Type", "application/force-download");
        String filename = URLEncoder.encode(contract.getName() + ".pdf", "UTF-8");
        //            response.addHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + filename);
        response.getOutputStream().write(output.toByteArray());
        response.getOutputStream().flush();
        context.responseComplete();
        context.renderResponse();

    } catch (BadPdfFormatException | IOException ex) {
        Logger.getLogger(ContractServiceBean.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(ContractServiceBean.class.getName()).log(Level.SEVERE, null, ex);
    }

}

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

License:Open Source License

public void generateFile(final OutputStream out) throws IOException {
    final Document document;
    if (styleSheet == null || styleSheet.getStyles() == null || !styleSheet.getStyles().containsKey("@page")) {
        document = new Document(PageSize.A4);
        document.setMargins(3.0f * PDFDocument.CM_UNIT, 2.0f * PDFDocument.CM_UNIT, 1.0f * PDFDocument.CM_UNIT,
                2.0f * PDFDocument.CM_UNIT);
        System.out.println("Processamento: terminou setMargins");
    } else {// www  . j  av a  2  s . co m
        Style style = ((Style) (styleSheet.getStyles().get("@page")));
        if ("landscape".equals(style.getPropertyValue("size"))) {
            document = new Document(PageSize.A4.rotate());
        } else {
            document = new Document(PageSize.A4);
        }
        String s = style.getPropertyValue("margin-left");
        Float f = styleMeasure(s, "3cm");
        document.setMargins(styleMeasure(style.getPropertyValue("margin-left"), "3cm"),
                styleMeasure(style.getPropertyValue("margin-right"), "2cm"),
                styleMeasure(style.getPropertyValue("margin-top"), "1cm"),
                styleMeasure(style.getPropertyValue("margin-bottom"), "2cm"));
        System.out.println("Processamento: terminou setMargins do else");
    }
    try {
        final PdfWriter writer = PdfWriter.getInstance(document, out);
        writer.setPageEvent(new PDFPageBreak(writer, document, headFirstPage, footFirstPage, head, foot));
        document.open();
        final MultiColumnText mct = new MultiColumnText();
        // set up 3 even columns with 10pt space between
        mct.addRegularColumns(document.left(), document.right(), 0f, 1);

        System.out.println("Processamento: prestes a extract visible components");

        // Extracting the document content
        extractVisibleComponents(body, document, mct, null, null);

        document.add(mct);
        document.close();
    } catch (final DocumentException de) {
        System.err.println(de.getMessage());
    }
}

From source file:com.aurel.track.util.PdfUtils.java

License:Open Source License

public static void createPdfFromText(StringBuilder text, File pdfFile) {
    Document output = null;//from w  ww . jav  a2s  . c  om
    try {
        BufferedReader input = new BufferedReader(new StringReader(text.toString()));
        // Size DIN A4
        //    see com.lowagie.text.PageSize for a complete list of page-size constants.
        output = new Document(PageSize.A4, 40, 40, 40, 40);
        float fntSize, lineSpacing;
        fntSize = 9f;
        lineSpacing = 11f;
        Font font1 = FontFactory.getFont(FontFactory.COURIER, fntSize);
        Font font2 = FontFactory.getFont(FontFactory.COURIER, fntSize);
        font2.setColor(Color.BLUE);
        Font font3 = FontFactory.getFont(FontFactory.COURIER, fntSize);
        font3.setColor(Color.RED);

        PdfWriter.getInstance(output, new FileOutputStream(pdfFile));

        output.open();
        output.addAuthor("Steinbeis");
        output.addSubject("Debug Info");
        output.addTitle(pdfFile.getName());

        String line = "";
        while (null != (line = input.readLine())) {
            Font ft = font1;
            if (line.startsWith("%")) {
                ft = font2;
            }
            if (line.startsWith("% ^^^") || line.startsWith("% vvv")) {
                ft = font3;
            }
            Paragraph p = new Paragraph(lineSpacing, line, ft);
            p.setAlignment(Element.ALIGN_JUSTIFIED);
            output.add(p);
        }
        output.close();
        input.close();
    } catch (Exception e) {
        LOGGER.debug("Problem creating debug info pdf file", e);
    }
}