Example usage for com.itextpdf.text Phrase Phrase

List of usage examples for com.itextpdf.text Phrase Phrase

Introduction

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

Prototype

public Phrase(final float leading, final String string) 

Source Link

Document

Constructs a Phrase with a certain leading and a certain String.

Usage

From source file:pdfservlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*w  w  w . java 2  s. c  om*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ResultSet resultSet = null;
    Statement statement = null;
    try {
        Connection connection = ConnectionManager.createConnectionToDB();

        String query = "SELECT * FROM employees";
        statement = connection.createStatement();
        resultSet = statement.executeQuery(query);
    } catch (SQLException e) {
        e.printStackTrace();
    }

    response.setContentType("application/pdf");
    Document document = new Document();
    Font font3 = new Font(Font.FontFamily.TIMES_ROMAN, 8);
    Font font4 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
    Font font2 = new Font(Font.FontFamily.COURIER, 10, Font.UNDERLINE);

    try {

        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();
        document.add(new Phrase(new Date().toString() + "\n", font3));
        String imageUrl = "http://www.technolinks.in/images/bhel_logo.jpg";

        Image image2 = Image.getInstance(new URL(imageUrl));
        image2.scaleAbsolute(100f, 100f);
        image2.setAbsolutePosition(25f, 725f);
        document.add(image2);

        document.add(new Phrase(
                "                                                                                                               BHEL Recruitment for Medical Professionals \n                                                              ",
                font3));
        document.add(new Phrase("Admit Card for Interview of Medical Professional in BHEL\n", font2));
        document.add(
                new Phrase("                                                 Acknowledgement No :", font3));

        document.addCreator("Shivin");
        document.addTitle("BHEL");

        resultSet.next();
        String trade_id = "100003";
        do {
            if (trade_id.matches(resultSet.getString("TRADE")))
                break;

        } while (resultSet.next());

        document.add(new Phrase("Post Applied:           " + resultSet.getString("TRADE") + "\n"));
        document.add(new Phrase("Name:                   " + resultSet.getString("FIRSTNAME") + "\n"));
        document.add(new Phrase("Father's/Husband's Name:" + resultSet.getString("FATHERNAME")));
        document.add(new Phrase("Address:                " + resultSet.getString("ADDRESS1") + "\n"
                + resultSet.getString("ADDRESS2") + "\n" + resultSet.getString("DISTRICT")
                + resultSet.getString("CITY") + "\n"));
        document.add(new Phrase("State:                  " + resultSet.getString("STATE") + "\n"));
        document.add(new Phrase("Pin:                    " + resultSet.getString("PIN") + "\n"));
        document.add(new Phrase("Caste:                  " + resultSet.getString("CASTE") + "\n"));
        document.add(new Phrase("Interview Date:         " + resultSet.getString("INTERVIEW_DATE") + "\n"));
        document.add(
                new Phrase("Interview Time:                  " + resultSet.getString("INTERVIEW_TIME") + "\n"));
        document.add(
                new Phrase("Reporting Time:                  " + resultSet.getString("REPORTING_TIME") + "\n"));
        document.add(new Phrase("Interview Venue:          " + resultSet.getString("INTERVIEW_VENUE") + "\n"));

        document.add(new Phrase("Important Instructions: \n", font4));
        document.add(
                new Paragraph("1.You must bring along with you the original documents and 01 selfattested\n"
                        + "photocopy of the following :\n"
                        + "Xth Certificate/ Birth Certificate mentioning Date of Birth\n"
                        + "MBBS Degree Certificate / Marksheets of all year\n"
                        + "PG Diploma / PG Degree / DNB Certificate in relevant discipline\n"
                        + "Medical Council Registration Certificate\n"
                        + "Post Qualification Experience Certificate in support of the experience being claimed\n"
                        + "Certificate for SC/ST in the prescribed format, if applicable\n"
                        + "Certificate for OBC indicating Non Creamy Layer status in the prescribed format, if applicable\n"
                        + "Self Undertaking for Non Creamy Layer status of OBC in the prescribed format, if applicable\n"
                        + "Medical Certificate for Physically Handicapped candidates for their disability from Government Hospital or Medical Board, if applicable.\n"
                        + "Discharge Certificate for ExServicemen\n"
                        + "NOC from the present employer, if applicable\n"
                        + "2. The shortlisted candidates after attending the interviews will be reimbursed train fare to the extent of single AC 2nd class return train fare\n"
                        + "from the address mentioned in the Application form to Interview Centre, by the shortest route subject to submission of rail/bus Ticket\n"
                        + "3. Please ensure that you fulfill all the prescribed job specifications as advertised and produce all the relevant documents thereof as aforesaid (as\n"
                        + "applicable to you), failing which we will not be able to interview you nor reimburse the Travelling Allowance. In case it is found that a\n"
                        + "candidate does not possess the qualification and /or other specification as prescribed in our advertisement, their candidature will be cancelled abinitio\n"
                        + "and no Travelling Allowance will be paid.\n"
                        + "4. You have the option to answer either in English or in Hindi during the Interview. Please note that no change of Interview place and/or date of\n"
                        + "interview will be possible. Also, we will not be able to respond to any individual queries regarding the results of personal Interview."));
        document.add(new Phrase("Declaration by the candidate: \n", font4));
        document.add(new Paragraph(
                "I understand that my permission to this test interview is provisional and if it is found at the later date that I do not fulfill the essential eligibility\n"
                        + "criteria regarding qualification, marks, age, caste, Experience etc. as per requirement of the Company, I will be debarred abinitio\n"
                        + "and I will not\n" + "be able to make any claim to the post."));
        document.add(new Phrase("DATE:", font2));
        document.add(new Phrase("\n"));
        document.add(new Phrase("PLACE:", font2));
        document.add(new Phrase("\n"));

        /* PdfPTable table2 = new PdfPTable(1);
                 
         table2.addCell("1.");
         table2.addCell("2.");
         table2.addCell("3.");
                
                 
                
          document.add(new Paragraph("                                                 \n\n\n\n            \n\n\n\n\n\n"));
                
          document.add(new Paragraph("             *Terms and Conditions      \n                               "));
                  
          document.add(table2); 
          document.close();
                  
                  
                  
        */
    } catch (Exception e) {
        e.printStackTrace();

    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */

}

From source file:araword.classes.HeaderFooter.java

/**
 * Increase the page number.//from  w ww  . j a  v  a 2s.c om
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onStartPage(
 *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
@Override
public void onStartPage(PdfWriter writer, Document document) {
    pagenumber++;
    System.out.println("ON Start Page PDF");
    Rectangle rect = writer.getBoxSize("art");

    /* header     
    ColumnText.showTextAligned(writer.getDirectContent(),                      
            com.itextpdf.text.Element.ALIGN_RIGHT, header[0],
              rect.getRight(), rect.getTop(), 0);
     */
    Font font = new Font();
    font.setSize(8);
    if (G.licensePDF) {
        ColumnText.showTextAligned(writer.getDirectContent(), com.itextpdf.text.Element.ALIGN_CENTER,
                new Phrase(String.format(TLanguage.getString("EXPORT_PDF_LICENCIA")), font),
                (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 18, 0);
        ColumnText.showTextAligned(writer.getDirectContent(), com.itextpdf.text.Element.ALIGN_CENTER,
                new Phrase(String.format(TLanguage.getString("EXPORT_PDF_LICENCIA2")), font),
                (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 9, 0);
    }

}

From source file:be.mxs.common.util.pdf.general.oc.examinations.PDFDrivingLicenseDeclaration.java

private void addQuestionnaire() {
    if (isAtLeastOneQuestionAnswered()) {
        contentTable = new PdfPTable(1);
        table = new PdfPTable(5);

        PdfPTable questions = new PdfPTable(40);

        // header
        questions.addCell(createTitleCell(
                getTran("medwan.common.driving-license-declaration.candidate-questionnaire"), 40));

        // questions
        String questionPrefix = "medwan.common.driving-license-declaration.candidate-questionnaire.question-";
        for (int i = 1; i <= 20; i++) {
            questions = addQuestion(questions, i, getTran(questionPrefix + i),
                    IConstants_PREFIX + "ITEM_TYPE_DLD_Q" + i);
        }//  w  ww  .  ja  va2  s. co  m

        // commitment
        String commPart1 = getTran(
                "medwan.common.driving-license-declaration.candidate-questionnaire.commitment") + " ";
        String commPart2 = getTran(
                "medwan.common.driving-license-declaration.candidate-questionnaire.commitment1");

        cell = new PdfPCell(new Phrase(commPart1 + commPart2, FontFactory.getFont(FontFactory.HELVETICA,
                Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD)));
        cell.setColspan(40);
        cell.setBorder(PdfPCell.BOX);
        cell.setBorderColor(innerBorderColor);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        questions.addCell(cell);

        // add content to document
        if (questions.size() > 0) {
            contentTable
                    .addCell(createCell(new PdfPCell(questions), 1, PdfPCell.ALIGN_CENTER, PdfPCell.NO_BORDER));
            tranTable.addCell(createContentCell(contentTable));
        }
    }
}

From source file:be.mxs.common.util.pdf.general.oc.examinations.PDFDrivingLicenseDeclaration.java

private PdfPTable addQuestion(PdfPTable table, int id, String question, String answer) {
    // cel 1 : nr
    cell = new PdfPCell(new Phrase(id + "", FontFactory.getFont(FontFactory.HELVETICA,
            Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL)));
    cell.setColspan(1);/*  ww w.  j  a v a2 s . c  om*/
    cell.setBorder(PdfPCell.BOX);
    cell.setBorderColor(innerBorderColor);
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell);

    // cel 2-38 : question
    cell = new PdfPCell(new Phrase(question, FontFactory.getFont(FontFactory.HELVETICA,
            Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL)));
    cell.setColspan(37);
    cell.setBorder(PdfPCell.BOX);
    cell.setBorderColor(innerBorderColor);
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell);

    // cel 39 and 40 : answer
    cell = new PdfPCell(new Phrase(getTran(getItemValue(answer)), FontFactory.getFont(FontFactory.HELVETICA,
            Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL)));
    cell.setColspan(2);
    cell.setBorder(PdfPCell.BOX);
    cell.setBorderColor(innerBorderColor);
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell);

    return table;
}

From source file:be.rheynaerde.poolsheets.AbstractPoolSheet.java

License:Open Source License

protected void buildTitle(Document document) throws DocumentException {
    //the title is placed in a one-column table of width 100%
    PdfPTable table = new PdfPTable(1);
    table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
    table.setWidthPercentage(100f);// w  ww.  j  ava2s  .  c  o  m

    //one row for the title
    PdfPCell cell = new PdfPCell(new Phrase(configuration.getTitle(), configuration.getTitleFont()));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setPaddingBottom(10f);
    table.addCell(cell);

    //one row for the subtitle
    cell = new PdfPCell(new Phrase(configuration.getSubtitle(), configuration.getSubtitleFont()));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setBorder(Rectangle.TOP);
    table.addCell(cell);

    //make sure that there is some spacing between the title and the scores
    //20f just seems to work allright, but maybe something more configurable
    //would be better.
    table.setSpacingAfter(20f);
    document.add(table);
}

From source file:be.rheynaerde.poolsheets.AbstractPoolSheet.java

License:Open Source License

protected PdfPCell getHeaderCell(String text) {
    PdfPCell headerCell = new PdfPCell(new Phrase(text, configuration.getHeaderFont()));
    headerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    headerCell.setFixedHeight(configuration.getSquareCellSize());
    return headerCell;
}

From source file:be.roots.taconic.pricingguide.util.iTextUtil.java

License:Open Source License

public static byte[] setPageNumbers(byte[] pdfDocument) throws IOException, DocumentException {

    final int numberOfPages = numberOfPages(pdfDocument);

    if (numberOfPages > 1) {

        try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {

            final PdfReader reader = new PdfReader(pdfDocument);
            final PdfStamper stamper = new PdfStamper(reader, baos);

            for (int pageNumber = 2; pageNumber <= numberOfPages; pageNumber++) {
                // get the first page
                final PdfContentByte canvas = stamper.getOverContent(pageNumber);

                // stamp the footer on the page
                final ColumnText ct = new ColumnText(canvas);

                ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
                        new Phrase(pageNumber + "", getFontPageNumber()), 550, 22, 0);
                ct.go();/*  w w w .  j  av  a 2s. c  o m*/

            }

            // close out
            stamper.close();
            reader.close();

            return baos.toByteArray();

        }

    }

    return pdfDocument;

}

From source file:be.thomasmore.controller.PdfController.java

public void createPdfKlas() {

    Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext()
            .getRequestParameterMap();/*from  w  w  w.  j  av  a 2 s .  c  o m*/
    String KlasId = params.get("klasId");
    int id = Integer.parseInt(KlasId);
    Document document = new Document();
    Klas klas = service.getKlas(id);
    List<Klastest> klastesten = klas.getKlastestList();
    List<Test> testen = new ArrayList<Test>();

    HttpServletResponse res = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext()
            .getResponse();
    res.setHeader("Content-Disposition", "attachement; filename=" + klas.getNummer() + "-resultaten.pdf");
    res.setContentType("application/pdf");

    try {
        PdfWriter.getInstance(document, res.getOutputStream());

        document.open();

        Font font = FontFactory.getFont("Calibri");
        Font fontbold = FontFactory.getFont("Calibri", Font.BOLD);

        PdfPTable table = new PdfPTable(3); // 3 columns.

        PdfPCell cell1 = new PdfPCell(new Paragraph("Vak", font));
        PdfPCell cell2 = new PdfPCell(new Paragraph("Student", font));
        PdfPCell cell3 = new PdfPCell(new Paragraph("Behaald", font));

        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);

        for (Klastest klastest : klastesten) {
            Test test = klastest.getTestId();
            testen.add(service.getTest(test.getId()));
        }

        for (Test test : testen) {
            List<Score> scores = test.getScoreList();
            Vak vak = test.getVakId();
            for (Score score : scores) {
                Student student = score.getStudentId();
                PdfPCell cellVak = new PdfPCell(new Paragraph(vak.getNaam(), font));
                PdfPCell cellStudent = new PdfPCell(new Paragraph(student.getVoornaam(), font));
                PdfPCell cellScore = new PdfPCell(new Paragraph(score.getScore().toString(), font));

                table.addCell(cellVak);
                table.addCell(cellStudent);
                table.addCell(cellScore);
            }
        }

        document.add(new Phrase("Klas: ", font));
        document.add(new Phrase(klas.getNummer(), font));
        document.add(table);

        document.close();
    } catch (Exception e) {

    }

}

From source file:be.thomasmore.controller.PdfController.java

public void createPdfTest() {
    Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext()
            .getRequestParameterMap();/*  w  w  w.  j  av  a2 s  .  c  o m*/
    String KlasId = params.get("klasId3");
    String TestId = params.get("testId");
    int klasId = Integer.parseInt(KlasId);
    int id = Integer.parseInt(TestId);
    Document document = new Document();
    Test test = service.getTest(id);
    List<Score> scores = test.getScoreList();
    Klas klas = service.getKlas(klasId);
    Vak vak = test.getVakId();

    HttpServletResponse res = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext()
            .getResponse();
    res.setHeader("Content-Disposition", "attachement; filename=" + test.getBeschrijving() + "-resultaten.pdf");
    res.setContentType("application/pdf");

    try {
        PdfWriter.getInstance(document, res.getOutputStream());

        document.open();

        Font font = FontFactory.getFont("Calibri");
        Font fontbold = FontFactory.getFont("Calibri", Font.BOLD);

        PdfPTable table = new PdfPTable(3); // 3 columns.

        PdfPCell cell1 = new PdfPCell(new Paragraph("Test", font));
        PdfPCell cell2 = new PdfPCell(new Paragraph("Student", font));
        PdfPCell cell3 = new PdfPCell(new Paragraph("Score", font));

        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);

        for (Score score : scores) {
            Student student = score.getStudentId();
            PdfPCell cellTest = new PdfPCell(new Paragraph(test.getBeschrijving(), font));
            PdfPCell cellStudent = new PdfPCell(new Paragraph(student.getVoornaam(), font));
            PdfPCell cellScore = new PdfPCell(new Paragraph(score.getScore().toString()));

            table.addCell(cellTest);
            table.addCell(cellStudent);
            table.addCell(cellScore);
        }

        document.add(new Phrase("Klas: ", font));
        document.add(new Phrase(klas.getNummer(), font));
        document.add(new Phrase("  Vak: ", font));
        document.add(new Phrase(vak.getNaam(), font));
        document.add(table);

        document.close();
    } catch (Exception e) {

    }

}

From source file:be.thomasmore.controller.PdfController.java

public void createPdfVak() {
    Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext()
            .getRequestParameterMap();/*from   w ww .java  2 s .c o m*/
    String KlasId = params.get("klasId2");
    String VakId = params.get("vakId");
    int klasId = Integer.parseInt(KlasId);
    int id = Integer.parseInt(VakId);
    Document document = new Document();
    Vak vak = service.getVak(id);
    List<Test> testen = vak.getTestList();
    Klas klas = service.getKlas(klasId);

    HttpServletResponse res = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext()
            .getResponse();
    res.setHeader("Content-Disposition", "attachement; filename=" + vak.getNaam() + "-resultaten.pdf");
    res.setContentType("application/pdf");

    try {
        PdfWriter.getInstance(document, res.getOutputStream());

        document.open();

        Font font = FontFactory.getFont("Calibri");
        Font fontbold = FontFactory.getFont("Calibri", Font.BOLD);

        PdfPTable table = new PdfPTable(3); // 3 columns.

        PdfPCell cell1 = new PdfPCell(new Paragraph("Test", font));
        PdfPCell cell2 = new PdfPCell(new Paragraph("Student", font));
        PdfPCell cell3 = new PdfPCell(new Paragraph("Score", font));

        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);

        for (Test test : testen) {
            List<Score> scores = test.getScoreList();
            for (Score score : scores) {
                Student student = score.getStudentId();
                PdfPCell cellTest = new PdfPCell(new Paragraph(test.getBeschrijving(), font));
                PdfPCell cellStudent = new PdfPCell(new Paragraph(student.getVoornaam(), font));
                PdfPCell cellScore = new PdfPCell(new Paragraph(score.getScore().toString()));

                table.addCell(cellTest);
                table.addCell(cellStudent);
                table.addCell(cellScore);
            }
        }

        document.add(new Phrase("Klas: ", font));
        document.add(new Phrase(klas.getNummer(), font));
        document.add(new Phrase("  Vak: ", font));
        document.add(new Phrase(vak.getNaam(), font));
        document.add(table);

        document.close();
    } catch (Exception e) {

    }
}