Example usage for com.itextpdf.text List UNORDERED

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

Introduction

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

Prototype

boolean UNORDERED

To view the source code for com.itextpdf.text List UNORDERED.

Click Source Link

Document

a possible value for the numbered parameter

Usage

From source file:com.havoc.hotel.util.BookingPdf.java

public static String generateBookingPDF(Booking booking)
        throws DocumentException, FileNotFoundException, IOException {
    Document document = new Document(PageSize.A4);
    String bookingname = booking.getFirstName() + " " + booking.getLastName();
    document.addHeader("HOTEL HAVOC", "Hotel havoc Booking confirmation");
    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(FILE + "Booking" + "" + booking.getCustomer().getFirstName() + ".pdf "));
    writer.setViewerPreferences(PdfWriter.PageModeUseOC);
    writer.setPdfVersion(PdfWriter.VERSION_1_7);
    document.open();//  w  w  w .  j  a v a 2 s .  com
    String html = htmlTemplate(booking);

    List unorderedList = new List(List.UNORDERED);

    unorderedList.add(new ListItem("Name       :" + booking.getFirstName() + " " + booking.getLastName()));
    //        unorderedList.add(new ListItem("Room Price :" + booking.getRoom().getRoomPrice()));
    unorderedList.add(new ListItem("Total Price :" + booking.getTotalPrice()));
    unorderedList.add(new ListItem("check in   :" + booking.getCheckinDate()));
    unorderedList.add(new ListItem("Total Nights:" + booking.getTotalNights()));
    unorderedList.add(new ListItem("check out  :" + booking.getCheckoutDate()));
    unorderedList.add(new ListItem("Booked By  :" + booking.getCustomer().getUsername()));

    document.add(unorderedList);
    document.close();
    return bookingname;

}

From source file:Controller.CrearPDF.java

/**
 * We create a PDF document with iText using different elements to learn 
 * to use this library.//from   w w w. ja v  a2  s. co  m
 * Creamos un documento PDF con iText usando diferentes elementos para aprender 
 * a usar esta librera.
 * @param pdfNewFile  <code>String</code> 
 *      pdf File we are going to write. 
 *      Fichero pdf en el que vamos a escribir. 
 */
//    public void createPDF(File pdfNewFile, ReparacionEntity reparacion) throws Exception {
public void createPDF(File pdfNewFile) throws Exception {
    // We create the document and set the file name.        
    // Creamos el documento e indicamos el nombre del fichero.
    try {
        //            ClienteController cc = new ClienteController();
        //            Cliente cliente = cc.buscarPorId(reparacion.getCliente());
        Document document = new Document();
        try {

            PdfWriter.getInstance(document, new FileOutputStream(pdfNewFile));

        } catch (FileNotFoundException fileNotFoundException) {
            System.out.println("No such file was found to generate the PDF "
                    + "(No se encontr el fichero para generar el pdf)" + fileNotFoundException);
        }
        document.open();
        // We add metadata to PDF
        // Aadimos los metadatos del PDF
        document.addTitle("Table export to PDF (Exportamos la tabla a PDF)");
        document.addSubject("Using iText (usando iText)");
        document.addKeywords("Java, PDF, iText");
        document.addAuthor("Cdigo Xules");
        document.addCreator("Cdigo Xules");

        // First page
        // Primera pgina 
        Chunk chunk = new Chunk("RDEN DE TRABAJO", categoryFont);
        Chunk c2 = new Chunk("\n\n\nCentro de Formacin SATCAR6\n" + "Calle Artes Grficas n1 Nave 12 A\n"
                + "Pinto (28320), Madrid", smallFont);

        Chunk c3 = new Chunk("Datos del Cliente", smallBold);
        //            Chunk c4 = new Chunk("Nombre: "+cliente.getRazonSocial(),smallBold);
        //            Chunk c5 = new Chunk("Poblacin: "+cliente.getPoblacion(),smallBold);
        //            Chunk c6 = new Chunk("Provincia: "+cliente.getProvincia(),smallBold);
        //            Chunk c7 = new Chunk("Cdigo Postal: "+cliente.getCp(),smallBold);
        //            Chunk c8 = new Chunk("Num Telfono: Pepito"+cliente.getTlf1(),smallBold);
        Chunk c4 = new Chunk("Nombre: Jesus Eduardo Garcia Toril", smallBold);
        Chunk c5 = new Chunk("Poblacin: Pinto", smallBold);
        Chunk c6 = new Chunk("Provincia: Madrid", smallBold);
        Chunk c7 = new Chunk("Cdigo Postal: 28320", smallBold);
        Chunk c8 = new Chunk("Num Telfono: 659408182", smallBold);

        Paragraph parrafo = new Paragraph(chunk);
        Paragraph p2 = new Paragraph(c2);
        Paragraph p3 = new Paragraph(c3);
        Phrase ph1 = new Phrase(c4);
        Phrase ph2 = new Phrase(c5);
        Phrase ph3 = new Phrase(c6);
        Phrase ph4 = new Phrase(c7);
        Phrase ph5 = new Phrase(c8);

        // Let's create de first Chapter (Creemos el primer captulo)

        // We add an image (Aadimos una imagen)
        Image image;
        try {
            parrafo.setAlignment(Element.ALIGN_CENTER);
            image = Image.getInstance(iTextExampleImage);
            image.setAbsolutePosition(0, 750);
            p2.setAlignment(Element.ALIGN_LEFT);
            document.add(parrafo);
            document.add(image);
            document.add(p2);
            document.add(p3);
            document.add(ph1);
            document.add(ph2);
            document.add(ph3);
            document.add(ph4);
            document.add(ph5);

        } catch (BadElementException ex) {
            System.out.println("Image BadElementException" + ex);
        }

        // Second page - some elements
        // Segunda pgina - Algunos elementos

        // List by iText (listas por iText)
        String text = "test 1 2 3 ";
        for (int i = 0; i < 5; i++) {
            text = text + text;
        }
        List list = new List(List.UNORDERED);
        ListItem item = new ListItem(text);
        item.setAlignment(Element.ALIGN_JUSTIFIED);
        list.add(item);
        text = "a b c align ";
        for (int i = 0; i < 5; i++) {
            text = text + text;
        }
        item = new ListItem(text);
        item.setAlignment(Element.ALIGN_JUSTIFIED);
        list.add(item);
        text = "supercalifragilisticexpialidocious ";
        for (int i = 0; i < 3; i++) {
            text = text + text;
        }
        item = new ListItem(text);
        item.setAlignment(Element.ALIGN_JUSTIFIED);
        list.add(item);

        // How to use PdfPTable
        // Utilizacin de PdfPTable

        // We use various elements to add title and subtitle
        // Usamos varios elementos para aadir ttulo y subttulo
        Anchor anchor = new Anchor("Table export to PDF (Exportamos la tabla a PDF)", categoryFont);
        anchor.setName("Table export to PDF (Exportamos la tabla a PDF)");
        Chapter chapTitle = new Chapter(new Paragraph(anchor), 1);
        Paragraph paragraph = new Paragraph("Do it by Xules (Realizado por Xules)", subcategoryFont);
        Section paragraphMore = chapTitle.addSection(paragraph);
        paragraphMore.add(new Paragraph("This is a simple example (Este es un ejemplo sencillo)"));
        Integer numColumns = 6;
        Integer numRows = 120;
        // We create the table (Creamos la tabla).
        PdfPTable table = new PdfPTable(numColumns);
        // Now we fill the PDF table 
        // Ahora llenamos la tabla del PDF
        PdfPCell columnHeader;
        // Fill table rows (rellenamos las filas de la tabla).                
        for (int column = 0; column < numColumns; column++) {
            columnHeader = new PdfPCell(new Phrase("COL " + column));
            columnHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(columnHeader);
        }
        table.setHeaderRows(1);
        // Fill table rows (rellenamos las filas de la tabla).                
        for (int row = 0; row < numRows; row++) {
            for (int column = 0; column < numColumns; column++) {
                table.addCell("Row " + row + " - Col" + column);
            }
        }
        // We add the table (Aadimos la tabla)
        paragraphMore.add(table);
        // We add the paragraph with the table (Aadimos el elemento con la tabla).
        document.add(chapTitle);
        document.close();
        System.out.println("Your PDF file has been generated!(Se ha generado tu hoja PDF!");
    } catch (DocumentException documentException) {
        System.out.println(
                "The file not exists (Se ha producido un error al generar un documento): " + documentException);
    }
}

From source file:edu.clemson.lph.pdfgen.PDFGen.java

License:Open Source License

private void printDoc() {
    if (sSourceFile == null || osDest == null) {
        logger.error("Cannot print nothing");
        return;/*from   w  ww  .  j  av a  2 s  . c om*/
    }
    boolean bBold = false;
    boolean bCenter = false;
    boolean bItalic = false;
    boolean bSmallItalic = false;
    boolean bUnderline = false;
    try {
        Document doc = new Document();
        float fCorr = doc.getPageSize().getWidth() / 8.5f;
        doc.setMargins(1.0f * fCorr, 1.0f * fCorr, 1.0f * fCorr, 1.0f * fCorr);

        PdfWriter.getInstance(doc, osDest);
        doc.open();
        BufferedReader br = new BufferedReader(new FileReader(sSourceFile));
        String sLine = br.readLine();
        while (sLine != null) {
            bBold = false;
            bCenter = false;
            if (sLine.startsWith(".")) {
                String sRest = sLine.substring(1);
                String sCodes = sRest.substring(0, sRest.indexOf('.'));
                sLine = sRest.substring(sRest.indexOf('.') + 1);
                if ("image".equals(sCodes)) {
                    String sFileName = sLine;
                    com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(sFileName);
                    image.setAlignment(Element.ALIGN_CENTER);
                    doc.add(image);
                    sLine = br.readLine();
                    continue;
                } else if ("himage".equals(sCodes)) {
                    String sFileName = sLine;
                    com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(sFileName);
                    image.scaleToFit(500, 40);
                    image.setAlignment(Element.ALIGN_CENTER);
                    doc.add(image);
                    Paragraph p = new Paragraph(" ");
                    doc.add(p);
                    sLine = br.readLine();
                    continue;
                } else if ("fimage".equals(sCodes)) {
                    int iBlanks = 9; // How do I figure out how many to get to end?
                    for (int i = 0; i < iBlanks; i++) {
                        Paragraph p = new Paragraph(" ");
                        doc.add(p);
                    }
                    String sFileName = sLine;
                    com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(sFileName);
                    image.scaleToFit(500, 40);
                    image.setAlignment(Element.ALIGN_CENTER);
                    doc.add(image);
                    sLine = br.readLine();
                    continue;
                } else if ("list".equals(sCodes)) {
                    String sFullLine = doSub(sLine);
                    StringTokenizer tok = new StringTokenizer(sFullLine, "\n");
                    List list = new List(List.UNORDERED);
                    while (tok.hasMoreTokens()) {
                        String sNextLine = tok.nextToken();
                        ListItem listItem = new ListItem(sNextLine, fNormal);
                        list.add(listItem);
                    }
                    doc.add(list);
                    sLine = br.readLine();
                    continue;
                }
                if (sCodes.contains("b"))
                    bBold = true;
                if (sCodes.contains("c"))
                    bCenter = true;
                if (sCodes.contains("i"))
                    bItalic = true;
                if (sCodes.contains("si"))
                    bSmallItalic = true;
                if (sCodes.contains("u"))
                    bUnderline = true;
            }
            if (sLine.trim().length() == 0)
                sLine = " ";

            String sFullLine = doSub(sLine);
            Paragraph p = new Paragraph();
            if (bBold)
                p.setFont(fBold);
            else if (bSmallItalic)
                p.setFont(fSmallItalic);
            else if (bItalic)
                p.setFont(fItalic);
            else if (bUnderline)
                p.setFont(fUnderline);
            else
                p.setFont(fNormal);
            if (bCenter) {
                p.setAlignment(Element.ALIGN_CENTER);
            } else {
                p.setAlignment(Element.ALIGN_LEFT);
            }
            p.add(sFullLine);
            doc.add(p);
            sLine = br.readLine();
        }
        br.close();
        doc.close();
    } catch (FileNotFoundException e) {
        logger.error("Could not find source file " + sSourceFile + " or destination", e);
    } catch (IOException e) {
        logger.error("Could not read file " + sSourceFile, e);
    } catch (DocumentException e) {
        logger.error("Error creating iText Document", e);
    }
}

From source file:jfx_horario.jefatura.JefaturaController.java

private void crearListaClasesDiariasPDF(Document document, Font fuente) throws DocumentException {
    if (lstHorario.getItems().size() > 0) {
        Paragraph clasesHoy = new Paragraph("Clases de hoy:", fuente);
        document.add(clasesHoy);//from  w  w w .j ava 2  s .  c  o  m
        document.add(new Paragraph(" "));

        List list = new List(List.UNORDERED);
        for (int i = 0; i < lstHorario.getItems().size(); i++) {
            ListItem item = new ListItem((String) lstHorario.getItems().get(i));
            item.setAlignment(Element.ALIGN_JUSTIFIED);
            list.add(item);
        }
        document.add(list);
    }
}

From source file:project1.GENERALCV.java

private void createcvActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createcvActionPerformed
    String firstname, lastname, contactno, email, phonenumber, address;
    String dob, martialStatus, cast, careerObjectives;
    String university, city, startdatee, enddatee, coursesAndQualification;
    String acedemicQualification, certificates, experience, techskills, addSkills;
    String achivements, additionalCertificates, references, hobbies;
    firstname = txtname.getText();//from w  w  w  .j  av a  2  s .  c o  m
    lastname = txtlastname.getText();

    email = txtemail.getText();
    phonenumber = txtMobileNo.getText();

    address = txtAddress.getText();

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

    String link = txtLink.getText();

    // dob= dateFormat.format(dateOfBirth.getDate());
    martialStatus = cmbMartialStatus.getSelectedItem().toString();
    // cast=txtcast.getText();
    //  careerObjectives=txtcareer.getText();

    university = txtCollegeName.getText();
    city = txtCity.getText();
    // startdatee=dateFormat.format(startdate.getDate());
    // enddatee=dateFormat.format(enddate.getDate());
    coursesAndQualification = txtExtraCourses.getText();

    //  certificates=txtcertificats.getText();
    // experience=txtexperience.getText();
    techskills = txttechnical.getText();
    // addSkills=txtadditional.getText();

    references = txtreference.getText();

    try {
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/cvmaker", "root", "12345");

        pInsertPerson = con
                .prepareStatement("INSERT INTO PERSONS(NAMEE,CONTACTNO,EMAILID,ADDRESS) VALUES(?,?,?,?)");

        pInsertPerson.setString(1, firstname + lastname);
        pInsertPerson.setString(2, phonenumber);
        pInsertPerson.setString(3, email);
        pInsertPerson.setString(4, address);
        pInsertPerson.executeUpdate();

        JOptionPane.showMessageDialog(null, "Data Is Alo Saved In Database....");

        showRecords();

    } catch (Exception e) {

        System.out.println(e.toString());

    }

    Statement statement;

    String selectTableSQL = "SELECT ID FROM PERSONS";
    int ss = 0;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/cvmaker", "root", "12345");

        statement = con.createStatement();

        //System.out.println(selectTableSQL);
        // execute select SQL stetementS
        ResultSet rs = statement.executeQuery(selectTableSQL);

        while (rs.next()) {

            ss = rs.getInt("ID");
        }
    } catch (SQLException e) {
        System.out.println(e.toString());

    } catch (ClassNotFoundException ex) {
        Logger.getLogger(FRESHERCV.class.getName()).log(Level.SEVERE, null, ex);
    }

    int newcvid = ss;

    try {

        OutputStream file = new FileOutputStream(new File("D:\\PDFFILES\\" + firstname + lastname + ".pdf"));

        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();
        //     Image im=Image.getInstance("E:\\PDFFILES\\FUUAST.png");
        //   document.add(new Paragraph(""));
        // document.add(im);

        Paragraph title1 = new Paragraph(firstname + " " + lastname + " Cv", FontFactory
                .getFont(FontFactory.HELVETICA, 36, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));

        Chapter chapter1 = new Chapter(title1, 1);

        chapter1.setNumberDepth(0);
        document.add(chapter1);

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

        List unorderedList = new List(List.UNORDERED);
        unorderedList.add(new ListItem("Mobile No:" + phonenumber));
        unorderedList.add(new ListItem("Email:" + city));
        unorderedList.add(new ListItem("Address:" + address));
        //    unorderedList.add(new ListItem("End Date:" + enddatee));
        document.add(unorderedList);

        //  document.add(new Paragraph("Address:"+address));
        Paragraph title2 = new Paragraph("Personal Information", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title2.setAlignment(Element.ALIGN_CENTER);

        document.add(title2);
        //   document.add(new Paragraph("Date Of Birth:" + dob));

        document.add(new Paragraph("Martial Status:" + martialStatus));
        //   document.add(new Paragraph("Cast:"+cast));
        //   document.add(new Paragraph("Career Objectives:"+careerObjectives));

        Paragraph title3 = new Paragraph("Qualification", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title3.setAlignment(Element.ALIGN_CENTER);
        document.add(title3);
        PdfPTable table = new PdfPTable(2); // 3 columns.
        document.add(new Paragraph("\n\n"));
        PdfPCell cell1 = new PdfPCell(new Paragraph("Insituite Name:"));
        PdfPCell cell2 = new PdfPCell(new Paragraph(university));

        PdfPCell cell3 = new PdfPCell(new Paragraph("City:"));
        PdfPCell cell4 = new PdfPCell(new Paragraph(city));

        PdfPCell cell5 = new PdfPCell(new Paragraph("Start Date:"));
        // PdfPCell cell6 = new PdfPCell(new Paragraph(startdatee));

        PdfPCell cell7 = new PdfPCell(new Paragraph("End Date:"));
        //PdfPCell cell8 = new PdfPCell(new Paragraph(enddatee));

        PdfPCell cell71 = new PdfPCell(new Paragraph("Extra Courses:"));
        PdfPCell cell81 = new PdfPCell(new Paragraph(coursesAndQualification));
        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);
        table.addCell(cell4);
        table.addCell(cell5);
        //   table.addCell(cell6);
        table.addCell(cell7);
        //   table.addCell(cell8);
        table.addCell(cell71);
        table.addCell(cell81);

        document.add(table);

        //  document.add(new Paragraph("Extra Courses:"+coursesAndQualification));
        //   document.add(new Paragraph("Certificates:"+certificates));
        //
        Paragraph title4 = new Paragraph("Experience", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title4.setAlignment(Element.ALIGN_CENTER);
        document.add(title4);
        //      document.add(new Paragraph(""+experience));

        Paragraph title5 = new Paragraph("Skills", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title5.setAlignment(Element.ALIGN_CENTER);
        document.add(title5);

        document.add(new Paragraph("Technical Skills:" + techskills));
        //    document.add(new Paragraph("Additional Skills:"+addSkills));
        Paragraph title6 = new Paragraph("References", FontFactory.getFont(FontFactory.HELVETICA, 24,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        title6.setAlignment(Element.ALIGN_CENTER);
        document.add(title6);
        document.add(new Paragraph("References:" + references));

        //     Anchor anchor;
        //     anchor = new Anchor(link, FontFactory.getFont(FontFactory.HELVETICA,12, Font.UNDERLINE, new CMYKColor(0, 0,0,255)));
        //    anchor.setReference( link);
        Paragraph paragraph = new Paragraph("Profile Link:");
        //     paragraph.add(anchor);
        document.add(paragraph);
        Paragraph title11 = new Paragraph(
                "                                                 Cv Number:" + newcvid, FontFactory
                        .getFont(FontFactory.HELVETICA, 15, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));

        document.add(new Paragraph("\n\n"));
        document.add(title11);
        try {
            Desktop desktop = Desktop.getDesktop();
            if (desktop.isSupported(Desktop.Action.OPEN)) {
                desktop.open(new File("D:\\PDFFILES\\" + firstname + lastname + ".pdf"));
            } else {
                System.out.println("Open is not supported");
            }
        } catch (IOException exp) {
            exp.printStackTrace();
        }
        document.close();
        file.close();

    } catch (Exception e) {

        e.printStackTrace();
    }
}