Example usage for com.itextpdf.text Paragraph add

List of usage examples for com.itextpdf.text Paragraph add

Introduction

In this page you can find the example usage for com.itextpdf.text Paragraph add.

Prototype

@Override
public boolean add(Element o) 

Source Link

Document

Adds an Element to the Paragraph.

Usage

From source file:com.auskeny.ems.print.PdfCreator.java

public static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*from   w w  w  .  j  a  va 2s.c  om*/
    // Lets write a big header
    preface.add(new Paragraph("Title of the document", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document describes something which is very important ", smallBold));

    addEmptyLine(preface, 8);

    preface.add(new Paragraph(
            "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
            redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:com.bougsid.printers.PrintMission.java

public void printMission(Mission mission) {
    Document document = new Document(PageSize.A4);
    try {/* ww w  .  jav  a 2 s  .c  o  m*/
        File downloadDir = new File(msg.getMessage("application.mission.downloaddir"));
        if (!downloadDir.exists()) {
            downloadDir.mkdir();
        }
        System.out.println("Dir =" + downloadDir.getPath());
        PdfWriter.getInstance(document,
                new FileOutputStream(downloadDir.getPath() + "/" + mission.getUuid() + ".pdf"));
        document.open();
        Paragraph p = new Paragraph();
        p.setSpacingAfter(60);
        document.add(p);
        //header
        Paragraph paragraph = new Paragraph(
                msg.getMessage("mission.pdf.school") + "       " + mission.getIdMission() + "           ",
                DEFAULT_FONT);
        Phrase phrase = new Phrase(msg.getMessage("mission.pdf.city") + " "
                + LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
        paragraph.add(phrase);
        paragraph.setSpacingAfter(50);
        document.add(paragraph);
        //title
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(40);
        PdfPCell cell = new PdfPCell(new Phrase(msg.getMessage("mission.pdf.title"),
                FontFactory.getFont(FontFactory.HELVETICA, 18)));
        cell.setBorderWidth(1);
        cell.setPadding(10);

        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        table.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.setSpacingAfter(40);
        document.add(table);

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

        //line 1
        cell = new PdfPCell(new Paragraph(mission.getEmploye().getCivilite().getLabel(), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFullName(), DEFAULT_FONT));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 2
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.matricule"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getMatricule(), DEFAULT_FONT));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 3
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.grade"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFonction(), DEFAULT_FONT));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        if (mission.getEntreprise() != null) {
            //line 4
            cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1"), DEFAULT_FONT_BOLD));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingTop(20);
            table.addCell(cell);
            cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1_2"), DEFAULT_FONT_BOLD));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingTop(20);
            table.addCell(cell);

            //line 5
            cell = new PdfPCell(new Paragraph(" ", DEFAULT_FONT_BOLD));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingTop(20);
            table.addCell(cell);
            cell = new PdfPCell(new Paragraph(" - " + mission.getEntreprise().getNom(), DEFAULT_FONT));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingTop(20);
            table.addCell(cell);
        }

        //line 6
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.lieu"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        p = new Paragraph();
        p.setFont(DEFAULT_FONT);
        for (Ville ville : mission.getVilles()) {
            p.add(ville.getNom() + "\n");
        }
        cell = new PdfPCell(p);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 7
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.startdate"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(
                ": " + mission.getStartDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "    Heure : "
                        + mission.getStartDate().format(DateTimeFormatter.ofPattern("HH:mm")),
                DEFAULT_FONT));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 8
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.enddate"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(
                ": " + mission.getEndDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "    Heure : "
                        + mission.getEndDate().format(DateTimeFormatter.ofPattern("HH:mm")),
                DEFAULT_FONT));

        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 9
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.transport"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        switch (mission.getTransportType()) {
        case PERSONNEL:
            cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.perso") + " "
                    + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat")
                    + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT));
            break;
        case Accompagnement:
            cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.accomp") + " "
                    + mission.getAccompEmploye().getCivilite() + " " + mission.getAccompEmploye().getFullName()
                    + " " + msg.getMessage("mission.pdf.accomp.voitue") + " "
                    + mission.getAccompEmploye().getVehicule().getMarque() + " "
                    + msg.getMessage("mission.pdf.mat") + " "
                    + mission.getAccompEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT));
            break;
        case Service:
            cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.service") + " "
                    + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat")
                    + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT));
            break;
        default: {
            cell = new PdfPCell(new Paragraph(
                    ": " + mission.getTransportType().getLabel() + " " + msg.getMessage("mission.pdf.taxi"),
                    DEFAULT_FONT));
        }
        }
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        table.setSpacingAfter(40);
        document.add(table);

        //note
        document.add(new Paragraph(msg.getMessage("mission.pdf.TEXT_2"), DEFAULT_FONT));

        //signature
        if (mission.getEmploye().getGrade().getType() == GradeType.DG) {

        } else {
            Employe dir = employeService.getDG();
            if (dir != null)
                paragraph = new Paragraph(dir.getFullName(), DEFAULT_FONT);
            paragraph.setAlignment(Element.ALIGN_RIGHT);
            paragraph.setSpacingBefore(40);
            document.add(paragraph);
            paragraph = new Paragraph(msg.getMessage("mission.pdf.DG"), DEFAULT_FONT);
            paragraph.setAlignment(Element.ALIGN_RIGHT);
            document.add(paragraph);
        }

    } catch (DocumentException ex) {
        ex.printStackTrace();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    }
    document.close();
    //        try {
    //            Desktop.getDesktop().open(new File("./order.pdf"));
    //        } catch (IOException ex) {
    //            JOptionPane.showMessageDialog(null, "Fichier gner mais ne peut pas etre ouvert vrifier le dossier");
    //        }
}

From source file:com.centurylink.mdw.pdf.PdfExportHelper.java

License:Apache License

private void printHtmlParagraphs(Section section, String content, int parentLevel) throws Exception {
    if (content == null || content.length() == 0)
        return;//  www. j a v a  2s . c  om
    Paragraph comb = new Paragraph();
    ElementList list = XMLWorkerHelper.parseToElementList(content, null);
    for (Element element : list) {
        comb.add(element);
    }
    section.add(comb);
    section.add(new Paragraph("\n", normalFont));
}

From source file:com.coast.PDFPrinter_iText.java

License:Apache License

/**
 * Prints the document at its actual size. This is the recommended way to print.
 *///www.  j  a  va 2  s  .c  om
private static void print(String pFileName, String pPayload) throws IOException, Exception {
    Document document = new Document();
    // step 2
    PdfWriter.getInstance(document, new FileOutputStream(pFileName));
    // step 3
    document.open();
    // step 4
    String _dateTime = LocalDateTime.now().toString();
    document.addTitle("List of All Customers & their assets as of: " + _dateTime);
    document.addCreationDate();
    document.addSubject("List of All Customers & their assets as of: " + _dateTime);

    Font _font = new Font();
    _font.setColor(BaseColor.BLUE);
    _font.setStyle(Font.BOLD);
    _font.setSize(15);

    Chunk _chunk = new Chunk("List of All Customers & their assets as of: " + _dateTime);
    _chunk.setFont(_font);
    Paragraph _header = new Paragraph();
    _header.add(_chunk);
    document.add(_header);
    document.add(new Paragraph(pPayload));

    // step 5
    document.close();
}

From source file:com.debashubham.dumpy.ChainageCalcActivity.java

private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*w w w.ja  va 2  s.c om*/
    // Lets write a big header
    preface.add(new Paragraph("SURVEY REPORT", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + surveyor_name + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(
            new Paragraph("This document is the report of a survey conducted on " + date_of_survey, smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document is the report of a survey with the work named as: " + work_name,
            smallBold));

    addEmptyLine(preface, 8);

    preface.add(new Paragraph(
            "This document is a preliminary version and not subject to your license agreement or any other agreement with the user.",
            redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:com.debashubham.dumpy.ChainageCalcActivity.java

private void createTable(Section subCatPart) throws DocumentException {
    PdfPTable entry_table = new PdfPTable(10);
    entry_table.setWidthPercentage(100);
    //        entry_table.setWidths(new float[]{0.25f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,1.0f});
    PdfPCell id = new PdfPCell(new Phrase("Station Point"));
    id.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell left_row = new PdfPCell(new Phrase("CH. Left(m)"));
    left_row.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell center_row = new PdfPCell(new Phrase("CH. Center(m)"));
    center_row.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell right_row = new PdfPCell(new Phrase("CH. Right(m)"));
    right_row.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell bs = new PdfPCell(new Phrase("BS(m)"));
    bs.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell is = new PdfPCell(new Phrase("IS(m)"));
    is.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell fs = new PdfPCell(new Phrase("FS(m)"));
    fs.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell hi = new PdfPCell(new Phrase("HI(m)"));
    hi.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell rl = new PdfPCell(new Phrase("RL(m)"));
    rl.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell remarks = new PdfPCell(new Phrase("REMARKS"));
    remarks.setHorizontalAlignment(Element.ALIGN_CENTER);
    entry_table.addCell(id);//  w w  w . j av  a  2s . c o  m
    entry_table.addCell(left_row);
    entry_table.addCell(center_row);
    entry_table.addCell(right_row);
    entry_table.addCell(bs);
    entry_table.addCell(is);
    entry_table.addCell(fs);
    entry_table.addCell(hi);
    entry_table.addCell(rl);
    entry_table.addCell(remarks);
    entry_table.setHeaderRows(1);
    int largest = rl_list.size();

    Log.e("Total RL:", String.valueOf(largest));
    double total_bs = 0, total_fs = 0, first_rl = 0, last_rl = 0;

    for (int i = 1; i <= largest; i++) {

        entry_table.addCell(String.valueOf(i));

        if (i == 1)
            first_rl = rl_list.get(i);
        if (i == largest)
            last_rl = rl_list.get(i);

        if (left.containsKey(i)) {
            entry_table.addCell(String.valueOf(left.get(i)));
            entry_table.addCell("");
            entry_table.addCell("");
        } else if (center.containsKey(i)) {
            entry_table.addCell("");
            entry_table.addCell(String.valueOf(center.get(i)));
            entry_table.addCell("");
        } else if (right.containsKey(i)) {
            entry_table.addCell("");
            entry_table.addCell("");
            entry_table.addCell(String.valueOf(right.get(i)));
        } else {
            entry_table.addCell("");
            entry_table.addCell("");
            entry_table.addCell("");
        }

        if (bs_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(bs_list.get(i)));
            total_bs += bs_list.get(i);
            Log.e("TABLE:", "BS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "BS not entered");
        }
        if (is_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(is_list.get(i)));
            Log.e("TABLE:", "IS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "IS not entered");
        }
        if (fs_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(fs_list.get(i)));
            total_fs += fs_list.get(i);
            Log.e("TABLE:", "FS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "FS not entered");
        }
        if (hi_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(hi_list.get(i)));
            Log.e("TABLE:", "HI");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "HI not entered");
        }
        if (rl_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(rl_list.get(i)));
            Log.e("TABLE:", "RL");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "RL not entered");
        }
        if (remarks_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(remarks_list.get(i)));
            Log.e("TABLE:", "REMARKS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "REMARKS not entered");
        }
    }
    subCatPart.add(entry_table);
    Log.e("Total BS:", String.valueOf(total_bs));
    Log.e("Total FS:", String.valueOf(total_fs));
    Log.e("First RL:", String.valueOf(first_rl));
    Log.e("Last RL:", String.valueOf(last_rl));
    Paragraph check_para = new Paragraph("Arithmetic Check:", subFont);
    addEmptyLine(check_para, 2);
    check_para.add("Summation(BS) - Summation(FS) = Last RL - First RL");
    addEmptyLine(check_para, 1);
    double bsfs_diff = Math.round((total_bs - total_fs) * 1000.0) / 1000.0;
    double rl_diff = Math.round((last_rl - first_rl) * 1000.0) / 1000.0;
    boolean checktrue = (bsfs_diff) == (rl_diff) ? true : false;
    check_para.add(String.valueOf(bsfs_diff) + " = " + String.valueOf(rl_diff));
    addEmptyLine(check_para, 1);
    if (checktrue) {
        check_para.setSpacingBefore(20);
        check_para.add("OK");
    } else {
        check_para.setSpacingBefore(20);
        check_para.add("Check Fail!");
    }
    addEmptyLine(check_para, 1);
    check_para.add("_______________________________________________________");
    subCatPart.add(check_para);
    Paragraph legend_para = new Paragraph("LEGEND:", subFont);
    addEmptyLine(legend_para, 1);
    legend_para.add("BS : Back Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("IS : Intermediate Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("FS : Fore Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("HI : Height of Instrument");
    addEmptyLine(legend_para, 1);
    legend_para.add("RL : Reduced Level");
    addEmptyLine(legend_para, 1);
    legend_para.add("CH. : Chainage");
    subCatPart.add(legend_para);
}

From source file:com.debashubham.dumpy.SimpleCalcActivity.java

private void createTable(Section subCatPart) throws BadElementException {
    PdfPTable entry_table = new PdfPTable(7);
    entry_table.setWidthPercentage(100);
    PdfPCell id = new PdfPCell(new Phrase("Station Point"));
    id.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell bs = new PdfPCell(new Phrase("BS"));
    bs.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell is = new PdfPCell(new Phrase("IS"));
    is.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell fs = new PdfPCell(new Phrase("FS"));
    fs.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell hi = new PdfPCell(new Phrase("HI"));
    hi.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell rl = new PdfPCell(new Phrase("RL"));
    rl.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell remarks = new PdfPCell(new Phrase("REMARKS"));
    remarks.setHorizontalAlignment(Element.ALIGN_CENTER);
    entry_table.addCell(id);//from   ww  w .  j  a  va2 s.  c  o m
    entry_table.addCell(bs);
    entry_table.addCell(is);
    entry_table.addCell(fs);
    entry_table.addCell(hi);
    entry_table.addCell(rl);
    entry_table.addCell(remarks);
    entry_table.setHeaderRows(1);
    int largest = rl_list.size();

    Log.e("Total RL:", String.valueOf(largest));
    double total_bs = 0, total_fs = 0, first_rl = 0, last_rl = 0;

    for (int i = 1; i <= largest; i++) {

        entry_table.addCell(String.valueOf(i));

        if (i == 1)
            first_rl = rl_list.get(i);
        if (i == largest)
            last_rl = rl_list.get(i);

        if (bs_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(bs_list.get(i)));
            total_bs += bs_list.get(i);
            Log.e("TABLE:", "BS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "BS not entered");
        }
        if (is_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(is_list.get(i)));
            Log.e("TABLE:", "IS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "IS not entered");
        }
        if (fs_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(fs_list.get(i)));
            total_fs += fs_list.get(i);
            Log.e("TABLE:", "FS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "FS not entered");
        }
        if (hi_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(hi_list.get(i)));
            Log.e("TABLE:", "HI");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "HI not entered");
        }
        if (rl_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(rl_list.get(i)));
            Log.e("TABLE:", "RL");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "RL not entered");
        }
        if (remarks_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(remarks_list.get(i)));
            Log.e("TABLE:", "REMARKS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "REMARKS not entered");
        }
    }
    subCatPart.add(entry_table);
    Log.e("Total BS:", String.valueOf(total_bs));
    Log.e("Total FS:", String.valueOf(total_fs));
    Log.e("First RL:", String.valueOf(first_rl));
    Log.e("Last RL:", String.valueOf(last_rl));
    Paragraph check_para = new Paragraph("Arithmetic Check:", subFont);
    addEmptyLine(check_para, 2);
    check_para.add("Summation(BS) - Summation(FS) = Last RL - First RL");
    addEmptyLine(check_para, 1);
    double bsfs_diff = Math.round((total_bs - total_fs) * 1000.0) / 1000.0;
    double rl_diff = Math.round((last_rl - first_rl) * 1000.0) / 1000.0;
    boolean checktrue = (bsfs_diff) == (rl_diff) ? true : false;
    check_para.add(String.valueOf(bsfs_diff) + " = " + String.valueOf(rl_diff));
    addEmptyLine(check_para, 1);
    if (checktrue) {
        check_para.setSpacingBefore(20);
        check_para.add("OK");
    } else {
        check_para.setSpacingBefore(20);
        check_para.add("Check Fail!");
    }
    addEmptyLine(check_para, 1);
    check_para.add("_______________________________________________________");
    subCatPart.add(check_para);
    Paragraph legend_para = new Paragraph("LEGEND:", subFont);
    addEmptyLine(legend_para, 2);
    legend_para.add("BS : Back Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("IS : Intermediate Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("FS : Fore Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("HI : Height of Instrument");
    addEmptyLine(legend_para, 1);
    legend_para.add("RL : Reduced Level");
    subCatPart.add(legend_para);
}

From source file:com.dexter.fms.mbean.ReportsMBean.java

@SuppressWarnings("unchecked")
public void createPDF(int type, String filename, int pageType) {
    try {//from w  w  w .j  a  va  2 s.  c  om
        FacesContext context = FacesContext.getCurrentInstance();
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new HeaderFooter());
        writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788));
        if (!document.isOpen()) {
            document.open();
        }

        switch (pageType) {
        case 1:
            document.setPageSize(PageSize.A4);
            break;
        case 2:
            document.setPageSize(PageSize.A4.rotate());
            break;
        }
        document.addAuthor("FMS");
        document.addCreationDate();
        document.addCreator("FMS");
        document.addSubject("Report");
        document.addTitle(getReport_title());

        PdfPTable headerTable = new PdfPTable(1);

        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
                + File.separator + "satraklogo.jpg";

        Hashtable<String, Object> params = new Hashtable<String, Object>();
        params.put("partner", dashBean.getUser().getPartner());
        GeneralDAO gDAO = new GeneralDAO();
        Object pSettingsObj = gDAO.search("PartnerSetting", params);
        PartnerSetting setting = null;
        if (pSettingsObj != null) {
            Vector<PartnerSetting> pSettingsList = (Vector<PartnerSetting>) pSettingsObj;
            for (PartnerSetting e : pSettingsList) {
                setting = e;
            }
        }
        gDAO.destroy();

        PdfPCell c = null;
        if (setting != null && setting.getLogo() != null) {
            Image logoImg = Image.getInstance(setting.getLogo());
            logoImg.scaleToFit(212, 51);
            c = new PdfPCell(logoImg);
        } else
            c = new PdfPCell(Image.getInstance(logo));
        c.setBorder(0);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        headerTable.addCell(c);

        Paragraph stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
            //font exception
        }
        Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD);

        c = new PdfPCell(new Paragraph(getReport_title(), font));
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        if (getReport_start_dt() != null && getReport_end_dt() != null) {
            stars = new Paragraph(20);
            stars.add(Chunk.NEWLINE);
            stars.setSpacingAfter(10);

            c = new PdfPCell(stars);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            c.setBorder(0);
            headerTable.addCell(c);

            new Font(helvetica, 12, Font.NORMAL);
            Paragraph ch = new Paragraph("From " + getReport_start_dt() + " to " + getReport_end_dt(), font);
            c = new PdfPCell(ch);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            headerTable.addCell(c);
        }
        stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);
        document.add(headerTable);

        PdfPTable pdfTable = exportPDFTable(type);
        if (pdfTable != null)
            document.add(pdfTable);

        //Keep modifying your pdf file (add pages and more)

        document.close();
        String fileName = filename + ".pdf";

        writeFileToResponse(context.getExternalContext(), baos, fileName, "application/pdf");

        context.responseComplete();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.dexter.fuelcard.mbean.UtilMBean.java

public byte[] createInvoicePDF(int pageType, String title, String dateperiod, String amount, String chargeType,
        String chargeAmount, String total) {
    try {/*  ww w .j  ava2 s.  co m*/
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new HeaderFooter());
        writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788));
        if (!document.isOpen()) {
            document.open();
        }

        switch (pageType) {
        case 1:
            document.setPageSize(PageSize.A4);
            break;
        case 2:
            document.setPageSize(PageSize.A4.rotate());
            break;
        }
        document.addAuthor("FUELCARD");
        document.addCreationDate();
        document.addCreator("FUELCARD");
        document.addSubject("Invoice");
        document.addTitle(title);

        PdfPTable headerTable = new PdfPTable(1);

        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
                + File.separator + "satraklogo.jpg";

        PdfPCell c = new PdfPCell(Image.getInstance(logo));
        c.setBorder(0);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        headerTable.addCell(c);

        Paragraph stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
            //font exception
        }
        Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD);

        c = new PdfPCell(new Paragraph(title, font));
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        if (dateperiod != null) {
            stars = new Paragraph(20);
            stars.add(Chunk.NEWLINE);
            stars.setSpacingAfter(10);

            c = new PdfPCell(stars);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            c.setBorder(0);
            headerTable.addCell(c);

            new Font(helvetica, 12, Font.NORMAL);
            Paragraph ch = new Paragraph("For " + dateperiod, font);
            c = new PdfPCell(ch);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            headerTable.addCell(c);
        }
        stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);
        document.add(headerTable);

        PdfPTable pdfTable = new PdfPTable(4);
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Charge Type", font)); // % per transaction or flat per license
        pdfTable.addCell(new Paragraph("Charge Amount", font)); // the amount of the charge setting

        if (chargeType.equalsIgnoreCase("Percent-Per-Tran")) {
            pdfTable.addCell(new Paragraph("Total Amount", font)); // the amount of the charge setting
        } else {
            pdfTable.addCell(new Paragraph("Total License", font)); // the amount of the charge setting
        }
        //pdfTable.addCell(new Paragraph("Description", font)); // the 
        pdfTable.addCell(new Paragraph("Amount Due", font));

        font = new Font(helvetica, 8, Font.NORMAL);
        pdfTable.addCell(new Paragraph(chargeType, font));
        pdfTable.addCell(new Paragraph(chargeAmount, font));
        pdfTable.addCell(new Paragraph(total, font));
        pdfTable.addCell(new Paragraph(amount, font));

        pdfTable.setWidthPercentage(100);
        if (pdfTable != null)
            document.add(pdfTable);

        //Keep modifying your pdf file (add pages and more)

        document.close();

        return baos.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.docdoku.server.extras.TitleBlockGenerator.java

License:Open Source License

protected void generateHeader(Paragraph preface, ResourceBundle bundle) {
    // Title + description
    preface.add(new Paragraph(title, BOLD_18));
    addEmptyLine(preface, 1);/*  w w w . j a  v  a 2 s.com*/

    if (!description.isEmpty()) {
        preface.add(new Paragraph(description, NORMAL_12));
    }

    // Separator
    LineSeparator separator = new LineSeparator();
    preface.add(separator);
    addEmptyLine(preface, 1);

}