Example usage for com.itextpdf.text Paragraph Paragraph

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

Introduction

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

Prototype

public Paragraph(Phrase phrase) 

Source Link

Document

Constructs a Paragraph with a certain Phrase.

Usage

From source file:PrintProjects.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {/* ww  w. ja va  2  s  .  c  om*/
        response.setContentType("Invoice.pdf");
        //Get the output stream for writing PDF object
        OutputStream out = response.getOutputStream();
        SystemDao dao = new SystemDao();

        String username_dbase = getServletContext().getInitParameter("username");
        String dbasepsw = getServletContext().getInitParameter("password");
        String dbase = getServletContext().getInitParameter("jdbcConnection");
        dao.open(username_dbase, dbasepsw, dbase);

        Document document = new Document();
        /* Basic PDF Creation inside servlet */

        ArrayList<User> users = dao.gettAllUsers();
        //tithes
        ArrayList<Donation> list = dao.getAllDonations();
        ArrayList<String> projects = dao.getProjects();

        PdfWriter.getInstance(document, out);

        document.open();
        document.addAuthor("LightHouse Chapel International");
        document.addCreationDate();
        document.addCreator("lci.com");

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

        document.add(new Paragraph("   NAME     " + "                  " + " NUMBER   "));
        for (int x = 0; x < projects.size(); ++x) {
            String[] data = projects.get(x).split("@");
            document.add(new Paragraph("  " + data[1] + "                  " + data[0]));
        }
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("Total Donations : " + projects.size()));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.close();
    } catch (Exception ex) {
        response.sendRedirect("systemError.jsp");
    }
}

From source file:pdfservlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request// www.  ja  v  a 2 s . c o m
 * @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:PDFmaker.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("Productielijst", catFont);
    //        anchor.setName("First Chapter");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 0);
    catPart.add(new Paragraph(
            "Productielijst gegenereerd door: " + System.getProperty("user.name") + ", " + LocalDate.now(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));/*from www  .j  a  v  a 2s  .  c  o  m*/
    //        Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    //        Section subCatPart = catPart.addSection(subPara);
    //        subCatPart.add(new Paragraph("Hello"));
    //
    //        subPara = new Paragraph("Subcategory 2", subFont);
    //        subCatPart = catPart.addSection(subPara);
    //        subCatPart.add(new Paragraph("Paragraph 1"));
    //        subCatPart.add(new Paragraph("Paragraph 2"));
    //        subCatPart.add(new Paragraph("Paragraph 3"));
    //
    //        // add a list
    //        createList(subCatPart);
    //        Paragraph paragraph = new Paragraph();
    //        addEmptyLine(paragraph, 5);
    //        subCatPart.add(paragraph);

    // add a table
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 1);
    catPart.add(paragraph);
    createTable(catPart);

    // now add all this to the document
    document.add(catPart);

    //        // Next section
    //        anchor = new Anchor("Second Chapter", catFont);
    //        anchor.setName("Second Chapter");
    //
    //        // Second parameter is the number of the chapter
    //        catPart = new Chapter(new Paragraph(anchor), 1);
    //
    //        subPara = new Paragraph("Subcategory", subFont);
    //        subCatPart = catPart.addSection(subPara);
    //        subCatPart.add(new Paragraph("This is a very important message"));
    //
    //        // now add all this to the document
    //        document.add(catPart);

}

From source file:PDFmaker.java

private static void addEmptyLine(Paragraph paragraph, int number) {
    for (int i = 0; i < number; i++) {
        paragraph.add(new Paragraph(" "));
    }//w ww.  j a v a2  s  .  com
}

From source file:FirstStatMain.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    Document document = new Document();
    try {// www. ja v  a2 s .  co m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf"));
        document.open();
        document.add(new Paragraph("A Hello World PDF document."));
        document.add(new Paragraph(tacomment.getText()));
        if (jRadioButton1.isSelected())
            document.add(new Paragraph("Performance Status:Good"));
        else
            document.add(new Paragraph("Performance Status:Bad"));
        document.close();
        writer.close();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:Pdfsave.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("First Chapter", catFont);
    anchor.setName("First Chapter");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategory 2", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragraph 1"));
    subCatPart.add(new Paragraph("Paragraph 2"));
    subCatPart.add(new Paragraph("Paragraph 3"));

    // add a list
    createList(subCatPart);//from  w ww. java  2s.c o  m
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // add a table
    createTable(subCatPart);

    // now add all this to the document
    document.add(catPart);

    // Next section
    anchor = new Anchor("Second Chapter", catFont);
    anchor.setName("Second Chapter");

    // Second parameter is the number of the chapter
    catPart = new Chapter(new Paragraph(anchor), 1);

    subPara = new Paragraph("Subcategory", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("This is a very important message"));

    // now add all this to the document
    document.add(catPart);

}

From source file:PrintAll.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  w  ww  . ja  v a 2 s  .  com
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {
        response.setContentType("Invoice.pdf");
        //Get the output stream for writing PDF object
        OutputStream out = response.getOutputStream();
        SystemDao dao = new SystemDao();

        String username_dbase = getServletContext().getInitParameter("username");
        String dbasepsw = getServletContext().getInitParameter("password");
        String dbase = getServletContext().getInitParameter("jdbcConnection");
        dao.open(username_dbase, dbasepsw, dbase);

        Document document = new Document();
        /* Basic PDF Creation inside servlet */

        ArrayList<User> users = dao.gettAllUsers();
        //tithes
        ArrayList<Donation> list = dao.getAllDonations();
        ArrayList<String> projects = dao.getProjects();
        //donaations
        Vector<String> donations = dao.get_donation();

        PdfWriter.getInstance(document, out);

        document.open();
        document.addAuthor("LightHouse Chapel International");
        document.addCreationDate();
        document.addCreator("lci.com");
        document.addTitle("USER INFORMATION SUMMARY");
        document.add(new Paragraph("LightHouse Chapel International"));

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

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

        document.add(new Paragraph(" "));
        document.add(new Paragraph("Amount " + "                  " + "Date "));
        document.add(new Paragraph(""));

        double total = 0.00;
        for (int x = 0; x < list.size(); ++x) {
            total += list.get(x).getAmount();
            document.add(new Paragraph(x + " " + list.get(x).getAmount() + "   " + list.get(x).getDate()));
        }

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

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

        document.add(new Paragraph(" "));
        document.add(new Paragraph("   NAME     " + "   SURNAME   " + "  ACCOUNT NUMBER  "));
        for (User user : users) {
            document.add(new Paragraph("  " + user.getName() + "  " + "  " + user.getSurname() + "  " + "  "
                    + user.getAccountNumber()));
        }

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

        document.add(new Paragraph(" "));
        document.add(new Paragraph("   NAME     " + "   NUMBER   " + "  COST  "));
        for (int x = 0; x < projects.size(); ++x) {
            String[] data = projects.get(x).split("@");
            document.add(new Paragraph("  " + data[1] + "  " + "  " + data[0] + "  " + "  " + data[4]));
        }

        document.close();
    } catch (Exception ex) {
        Logger.getLogger(PrintAll.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:PrintTitheReport.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from www .  j ava  2  s . c  o m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {
        response.setContentType("Invoice.pdf");
        //Get the output stream for writing PDF object
        OutputStream out = response.getOutputStream();
        SystemDao dao = new SystemDao();

        String username_dbase = getServletContext().getInitParameter("username");
        String dbasepsw = getServletContext().getInitParameter("password");
        String dbase = getServletContext().getInitParameter("jdbcConnection");
        dao.open(username_dbase, dbasepsw, dbase);

        Document document = new Document();
        /* Basic PDF Creation inside servlet */

        ArrayList<User> users = dao.gettAllUsers();
        //tithes
        ArrayList<Donation> list = dao.getAllDonations();
        ArrayList<String> projects = dao.getProjects();

        PdfWriter.getInstance(document, out);

        document.open();
        document.addAuthor("LightHouse Chapel International");
        document.addCreationDate();
        document.addCreator("lci.com");

        document.add(new Paragraph("=========== TITHES ==============="));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("Amount " + "                  " + "Date "));
        document.add(new Paragraph(""));
        document.add(new Paragraph(""));

        double total = 0.00;
        for (int x = 0; x < list.size(); ++x) {
            total += list.get(x).getAmount();

            document.add(new Paragraph(
                    (1 + x) + " " + list.get(x).getAmount() + "                  " + list.get(x).getDate()));
        }
        document.add(new Paragraph(""));
        document.add(new Paragraph(""));
        document.add(new Paragraph(""));
        document.add(new Paragraph(""));
        document.add(new Paragraph(""));
        document.add(new Paragraph(""));
        document.add(new Paragraph("Total Number of people who paid tithe :   " + list.size()));
        document.close();

    } catch (Exception ex) {
        response.sendRedirect("systemError.jsp");
    }

}

From source file:PrintingServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from ww  w  .  j  a  v a2  s . co m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, DocumentException {

    try {
        response.setContentType("Invoice.pdf");
        //Get the output stream for writing PDF object
        OutputStream out = response.getOutputStream();
        SystemDao dao = new SystemDao();

        String username_dbase = getServletContext().getInitParameter("username");
        String dbasepsw = getServletContext().getInitParameter("password");
        String dbase = getServletContext().getInitParameter("jdbcConnection");
        dao.open(username_dbase, dbasepsw, dbase);

        Document document = new Document();
        /* Basic PDF Creation inside servlet */

        ArrayList<User> users = dao.gettAllUsers();
        //tithes
        ArrayList<Donation> list = dao.getAllDonations();
        ArrayList<String> projects = dao.getProjects();
        //donaations
        Vector<String> donations = dao.get_donation();

        PdfWriter.getInstance(document, out);

        document.open();
        document.addAuthor("LightHouse Chapel International");
        document.addCreationDate();
        document.addCreator("lci.com");
        document.addTitle("USER INFORMATION SUMMARY");
        document.add(new Paragraph("LightHouse Chapel International"));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("INFORMATION SUMMARY"));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("=========== TITHES ==============="));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("Amount " + "                  " + "Date "));
        document.add(new Paragraph(""));
        document.add(new Paragraph(""));

        double total = 0.00;
        for (int x = 0; x < list.size(); ++x) {
            total += list.get(x).getAmount();
            document.add(new Paragraph(x + " " + list.get(x).getAmount() + "   " + list.get(x).getDate()));
        }

        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("============ USERS ==========="));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("   NAME     " + "   SURNAME   " + "  ACCOUNT NUMBER  "));
        for (User user : users) {
            document.add(new Paragraph("  " + user.getName() + "  " + "  " + user.getSurname() + "  " + "  "
                    + user.getAccountNumber()));
        }

        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("============ PROJECTS ==========="));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("   NAME     " + "   NUMBER   " + "  COST  "));
        for (int x = 0; x < projects.size(); ++x) {
            String[] data = projects.get(x).split("@");
            document.add(new Paragraph("  " + data[1] + "  " + "  " + data[0] + "  " + "  " + data[4]));
        }
    } catch (SQLException ex) {
        response.sendRedirect("systemError.jsp");
    } catch (ClassNotFoundException ex) {
        response.sendRedirect("systemError.jsp");
    }
}

From source file:pdf_demo2.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("First Chapter", titleFont);
    anchor.setName("First Chapter");

    // Second parameter is the number of the chapter ex: 1. Chapter 1 or 2. Chapter 2
    Chapter chapter = new Chapter(new Paragraph(anchor), 2);

    Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    Section subSection = chapter.addSection(subPara);
    subSection.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategory 2", subFont);
    subSection = chapter.addSection(subPara);
    subSection.add(new Paragraph("Paragraph 1"));
    subSection.add(new Paragraph("Paragraph 2"));
    subSection.add(new Paragraph("Paragraph 3"));

    // add a list
    createList(subSection);//  w  ww. jav  a2 s.co m
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subSection.add(paragraph);

    // add a table
    createTable(subSection);

    // now add all this to the document
    document.add(chapter);

    // Next section
    anchor = new Anchor("Second Chapter", titleFont);
    anchor.setName("Second Chapter");

    // Second parameter is the number of the chapter
    chapter = new Chapter(new Paragraph(anchor), 2);

    subPara = new Paragraph("Subcategory", subFont);
    subSection = chapter.addSection(subPara);
    subSection.add(new Paragraph("This is a very important message"));

    // now add all this to the document
    document.add(chapter);
}