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.planfeed.services.MeetingServiceImpl.java

License:Apache License

public ByteArrayOutputStream getActa(String meetingId) throws Exception {
    Meeting meeting;//  w  w  w.j a  v a  2s  .com
    try {
        meeting = this.getMeeting(meetingId);
    } catch (Exception e) {
        throw new MeetingNotFound();
    }

    Document document = new Document();
    ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
    PdfWriter docWriter = null;
    HeaderFooter event = new HeaderFooter(meeting.getDate());
    docWriter = PdfWriter.getInstance(document, baosPDF);
    docWriter.setBoxSize("art", new Rectangle(36, 54, 559, 788));
    docWriter.setPageEvent(event);
    document.open();

    //metadata
    document.addTitle(meeting.getTitle() + " Acta");

    document.add(new Paragraph(" "));

    //Title
    Paragraph title = new Paragraph("Acta of " + meeting.getTitle(), titleFont);
    title.setAlignment(Element.ALIGN_CENTER);

    addEmptyLine(title, 1);

    document.add(title);

    //Description
    Paragraph descriptionPar = new Paragraph();
    descriptionPar.add(new Paragraph("Description", titlePointFont));
    descriptionPar.add(new Paragraph(meeting.getDescription(), textFont));
    addEmptyLine(descriptionPar, 1);
    document.add(descriptionPar);

    //Points
    int index = 1;
    for (PointOfAgenda point : meeting.getAgenda()) {
        Paragraph pointPar = new Paragraph();
        pointPar.add(new Paragraph(index + ". " + point.getName(), titlePointFont));
        pointPar.add(new Paragraph(point.getComment(), textFont));
        addEmptyLine(pointPar, 2);
        document.add(pointPar);
        index += 1;
    }

    document.close();

    return baosPDF;

}

From source file:com.planning.project.controller.CreatePDF.java

public static Document createPDFActivity(String file, Long activityId) throws Exception {

    Document document = null;/*  w w w.  j  a  v a 2 s  .  com*/

    try {
        document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();

        addMetaData(document);

        addTitlePageProject(document);

        Paragraph created = new Paragraph();
        created.setFont(TIME_ROMAN_SMALL);
        created.add(activityId.toString());
        created.setAlignment(Element.ALIGN_RIGHT);
        document.add(created);
        document.close();

    } catch (FileNotFoundException e) {

        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    return document;
}

From source file:com.planning.project.controller.CreatePDF.java

private static void addTitlePage(Document document) throws DocumentException, IOException {

    Font font = new Font(BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
    font.setSize(24);//from w  w  w  .  java 2 s .  c  o m

    String imagepath = "src/main/webapp/resources/images/curt.gif";
    Image img = Image.getInstance(imagepath);
    img.scaleToFit(70f, 70f);

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy");

    Paragraph created = new Paragraph();
    created.setFont(TIME_ROMAN_SMALL);
    created.add("Report created on " + simpleDateFormat.format(new Date()));
    created.setAlignment(Element.ALIGN_RIGHT);

    Paragraph logo = new Paragraph();
    logo.setFont(TIME_ROMAN_SMALL);
    logo.add(img);
    logo.setAlignment(Element.ALIGN_LEFT);
    document.add(created);
    document.add(logo);

    // Paragraph created = new Paragraph();
    // created.setFont(TIME_ROMAN_SMALL);
    // created.add("Report created on " + simpleDateFormat.format(new
    // Date()));
    // created.setAlignment(Element.ALIGN_RIGHT);

    Paragraph paragraph = new Paragraph();
    paragraph.setFont(font);
    paragraph.add("FormProject ");

    paragraph.setAlignment(Element.ALIGN_CENTER);
    document.add(paragraph);
    creteEmptyLine(created, 1);

}

From source file:com.planning.project.controller.CreatePDF.java

private static void creteEmptyLine(Paragraph paragraph, int number) {
    for (int i = 0; i < number; i++) {
        paragraph.add(new Paragraph(" "));
    }//from   ww w  . ja v a2 s . c o m
}

From source file:com.planning.project.controller.CreatePDF.java

private static void creteLine(Paragraph paragraph, int number) {
    for (int i = 0; i < number; i++) {

        paragraph.add(
                new Paragraph("_____________________________________________________________________________"));

    }//from  ww w .j a va 2s  .com
}

From source file:com.planning.project.controller.CreatePDF.java

private static void createTable(Document document) throws DocumentException, IOException {
    Font font = new Font(BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
    font.setSize(16);//from w  w w. ja  v a 2  s  .  c  om

    Paragraph paragraph = new Paragraph();
    paragraph.setFont(font);
    creteEmptyLine(paragraph, 2);
    document.add(paragraph);
    PdfPTable table = new PdfPTable(7);

    paragraph.add("");

    PdfPCell c1 = new PdfPCell(new Phrase("asasas", font));

    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("/?", font));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("?", font));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    TbActivity ac = new TbActivity();

    c1 = new PdfPCell(new Phrase("", font));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("", font));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("", font));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("", font));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    paragraph.add("");

    for (int i = 0; i < 7; i++) {
        table.setWidthPercentage(100);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(paragraph);

    }

    document.add(table);
}

From source file:com.planning.project.controller.CreatePDF.java

private static void createPagePDFFormProject(Document document, TbFormProject tbFormProject,
        List<TbActivity> activity, List<TbDetailSka> detailSka, List<TbDetailSm> detailSms,
        TbFormSubproject subProject) throws DocumentException, IOException {

    Font font = new Font(BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
    font.setSize(16);/*  ww w.  j  ava 2s .co m*/
    int acNo = 0;

    Paragraph openning = new Paragraph();
    Paragraph ska = new Paragraph();
    Paragraph sms = new Paragraph();
    Paragraph notice = new Paragraph();
    Paragraph address = new Paragraph();
    Paragraph readyTodo = new Paragraph();

    readyTodo.setFont(font);
    address.setFont(font);
    ska.setFont(font);
    sms.setFont(font);
    notice.setFont(font);
    openning.setFont(font);
    openning.add("  : " + tbFormProject.getTbFaculty().getFacultyName());
    creteEmptyLine(openning, 1);
    openning.add("?"
            + tbFormProject.getTbStrBud().getStrBudName());
    creteEmptyLine(openning, 1);
    openning.add("?  : " + tbFormProject.getTbPlan().getPlansName());
    creteEmptyLine(openning, 1);
    openning.add("? : "
            + tbFormProject.getTbStrMin().getStrMinName());
    creteEmptyLine(openning, 1);
    openning.add("? : "
            + tbFormProject.getTbMisUni().getMisUniName());
    creteEmptyLine(openning, 1);
    openning.add(" : "
            + tbFormProject.getTbSubUni().getSubUniName());
    creteEmptyLine(openning, 1);
    openning.add("? : " + tbFormProject.getTbProduct().getProductName());
    creteEmptyLine(openning, 1);
    openning.add(
            "? : " + tbFormProject.getTbProjectname().getProjectnameName());
    creteEmptyLine(openning, 1);
    openning.add("? : "
            + tbFormProject.getTbPerson().getPersonName() + " "
            + tbFormProject.getTbPerson().getPersonLastname());
    creteEmptyLine(openning, 1);
    openning.add("  : " + tbFormProject.getTotal());
    creteEmptyLine(openning, 1);
    openning.add("? : "
            + tbFormProject.getAllocateMoney());
    creteEmptyLine(openning, 1);
    openning.add(" : "
            + (Long.parseLong(tbFormProject.getAllocateMoney())
                    - Long.parseLong(tbFormProject.getMoneyBalance())));
    creteEmptyLine(openning, 1);
    openning.add(" : " + tbFormProject.getMoneyBalance());

    creteLine(openning, 1);
    creteEmptyLine(openning, 1);
    for (TbActivity ac : activity) {
        acNo++;
        openning.add("??" + acNo + ":" + ac.getActivityName()
                + "?? : " + ac.getAddressName());
        creteEmptyLine(openning, 1);
        openning.add("?? : " + ac.getStartdate()
                + "?? : " + ac.getEnddate());
        creteEmptyLine(openning, 1);
        openning.add("? : "
                + ac.getAllocateMoney() + " : "
                + ac.getMoneyBalance());
        creteEmptyLine(openning, 1);
        openning.add(" : "
                + (Long.parseLong(ac.getAllocateMoney()) - Long.parseLong(ac.getMoneyBalance())));

        creteLine(openning, 1);
        creteEmptyLine(openning, 1);
    }
    ska.add("      ?? (?)");
    creteEmptyLine(ska, 1);
    for (TbDetailSka de : detailSka) {
        ska.add(de.getTbSkaType().getSkaTypeName() + "  : "
                + de.getTbSkaIndicatorsFac().getSkaIndicatorsFacName() + "  : "
                + de.getTbSkaIndicatorsHouse().getSkaIndicatorsHouseName());
        creteEmptyLine(ska, 1);
    }
    sms.add("      ??? ()");
    creteEmptyLine(sms, 1);
    for (TbDetailSm sm : detailSms) {
        sms.add(sm.getTbSmsCategory().getSmsCategoryName() + " " + "  "
                + sm.getTbSmsIndicator().getSmsIndicatorsName());
        creteEmptyLine(sms, 1);
    }

    notice.add(
            " : ???????  ?????? ");
    creteEmptyLine(notice, 1);

    address.add("? : " + " : "
            + subProject.getTbAmphur().getAmphurTh() + " : "
            + subProject.getTbProvince().getProvinceTh());
    creteEmptyLine(address, 1);

    readyTodo.add("?");
    creteEmptyLine(readyTodo, 1);
    readyTodo.add("? : "
            + subProject.getTbApproPlaceType().getApproPlaceTypeName());
    creteEmptyLine(readyTodo, 1);
    readyTodo.add("?/ : "
            + subProject.getTbApproPoint1().getApproPointName());
    creteEmptyLine(readyTodo, 1);
    readyTodo.add("/?  : "
            + subProject.getTbApproPoint2().getApproPointName());
    creteEmptyLine(readyTodo, 1);
    readyTodo.add("?? : "
            + subProject.getTbApproProjectType().getApproProjectTypeName());
    creteEmptyLine(readyTodo, 1);

    document.add(openning);
    document.add(ska);
    document.add(sms);
    document.add(notice);
    document.add(address);
    document.add(readyTodo);

}

From source file:com.planning.project.controller.CreatePDF.java

private static void createPagePDFFormProject2(Document document, TbFormProject tbFormProject,
        List<TbActivity> activity, List<TbDetailSka> detailSka, List<TbDetailSm> detailSms,
        TbFormSubproject subProject) throws DocumentException, IOException {

    Font font = new Font(BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
    font.setSize(16);//from   w  w w.  j  av a 2 s  .co  m

    Paragraph openning = new Paragraph();
    openning.setFont(font);

    creteLine(openning, 1);
    openning.add("??? ");
    creteEmptyLine(openning, 1);
    openning.add("????");
    creteEmptyLine(openning, 1);
    openning.add("???  : "
            + subProject.getTbMonth1().getMonthLong());
    creteEmptyLine(openning, 1);
    openning.add(
            "? : " + subProject.getTbMonth2().getMonthLong());
    creteEmptyLine(openning, 1);
    openning.add(
            "??????? : "
                    + subProject.getTbMonth3().getMonthLong());
    creteEmptyLine(openning, 1);
    openning.add("??");
    creteEmptyLine(openning, 1);
    openning.add(
            "? ????  : "
                    + subProject.getTbMonth4().getMonthLong());
    creteEmptyLine(openning, 1);
    openning.add(
            "???   : "
                    + subProject.getTbMonth5().getMonthLong());
    creteEmptyLine(openning, 1);
    openning.add(
            "//?????   : "
                    + subProject.getTbMonth6().getMonthLong());
    creteEmptyLine(openning, 1);
    openning.add(
            "??? : ( 3 ?)    : "
                    + subProject.getWorkflowPlanBudget());
    creteLine(openning, 1);
    creteEmptyLine(openning, 1);
    document.add(openning);
}

From source file:com.planning.project.controller.CreatePDF.java

private static void createPagePDFFormProject3(Document document, TbFormProject tbFormProject,
        List<TbActivity> activity, List<TbDetailSka> detailSka, List<TbDetailSm> detailSms,
        TbFormSubproject subProject) throws DocumentException, IOException {

    Font font = new Font(BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
    font.setSize(16);//w  w  w.  ja  v  a 2 s  . c o m

    Paragraph openning = new Paragraph();
    openning.setFont(font);

    creteLine(openning, 1);
    creteEmptyLine(openning, 1);
    openning.add(
            "(?????)");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getResults());
    creteEmptyLine(openning, 1);
    openning.add(
            "?/ ? ()");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getProblem());
    creteEmptyLine(openning, 1);
    openning.add(
            "??/? ()");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getDevelopmentPlan());
    creteEmptyLine(openning, 1);

    openning.add(
            "???");
    creteEmptyLine(openning, 1);
    document.add(openning);

    openning.add(
            "?? (???? ? ? ??? ??  ?)");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getRiskPolitics());
    creteEmptyLine(openning, 1);
    openning.add(
            "????/?");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getRiskDefPolitics());
    creteLine(openning, 1);
    creteEmptyLine(openning, 1);

    openning.add(
            "??/? (??? ?/? /?? ?? ?)");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getRiskPolicy());
    creteEmptyLine(openning, 1);
    openning.add(
            "????/?");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getRiskDefPolicy());
    creteLine(openning, 1);
    creteEmptyLine(openning, 1);

    openning.add(
            "??? (? ??? ? ? ??)");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getRiskWorkflow());
    creteEmptyLine(openning, 1);
    openning.add(
            "????/?");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getRiskDefWorkflow());
    creteLine(openning, 1);
    creteEmptyLine(openning, 1);

    openning.add(
            "???? (? ?? ?????)");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getRiskFinance());
    creteEmptyLine(openning, 1);
    openning.add(
            "????/?");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getRiskDefFinance());
    creteLine(openning, 1);
    creteEmptyLine(openning, 1);

    openning.add(
            " (?   ???)");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getRiskTechnology());
    creteEmptyLine(openning, 1);
    openning.add(
            "????/?");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getRiskDefTechnology());
    creteLine(openning, 1);
    creteEmptyLine(openning, 1);

    openning.add(
            "? (?????    ?)");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getRiskEnvironment());
    creteEmptyLine(openning, 1);
    openning.add(
            "????/?");
    creteEmptyLine(openning, 1);
    openning.add(": " + tbFormProject.getRiskDefEnvironment());
    creteLine(openning, 1);
    creteEmptyLine(openning, 1);
    document.add(openning);
}

From source file:com.planning.project.controller.CreatePDF.java

private static void addTitlePageProject(Document document) throws DocumentException, IOException {

    Font font = new Font(BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
    font.setSize(24);// ww  w .  j a va  2s.c  o  m

    String imagepath = "src/main/webapp/resources/images/logo.jpg";
    Image img = Image.getInstance(imagepath);
    img.scaleToFit(70f, 70f);

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy");

    Paragraph created = new Paragraph();
    created.setFont(TIME_ROMAN_SMALL);
    created.add("Report created on " + simpleDateFormat.format(new Date()));
    created.setAlignment(Element.ALIGN_RIGHT);

    Paragraph logo = new Paragraph();
    logo.setFont(TIME_ROMAN_SMALL);
    logo.add(img);
    logo.setAlignment(Element.ALIGN_LEFT);
    document.add(created);
    document.add(logo);

    // Paragraph created = new Paragraph();
    // created.setFont(TIME_ROMAN_SMALL);
    // created.add("Report created on " + simpleDateFormat.format(new
    // Date()));
    // created.setAlignment(Element.ALIGN_RIGHT);

    Paragraph paragraph = new Paragraph();
    paragraph.setFont(font);
    paragraph.add(
            "??");

    paragraph.setAlignment(Element.ALIGN_CENTER);
    document.add(paragraph);
    creteEmptyLine(created, 1);

}