Example usage for com.itextpdf.text List add

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

Introduction

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

Prototype

public boolean add(final Element o) 

Source Link

Document

Adds an Element to the List.

Usage

From source file:PDFmaker.java

private static void createList(Section subCatPart) {
    List list = new List(true, false, 10);
    list.add(new ListItem("First point"));
    list.add(new ListItem("Second point"));
    list.add(new ListItem("Third point"));
    subCatPart.add(list);/*from w  w w .  ja v a2  s  .c o m*/
}

From source file:EmployeeInfo.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
    String value1 = txt_empID.getText();
    String value2 = txt_firstName.getText();
    String value3 = txt_lastName.getText();
    String value4 = txt_age.getText();

    try {/* w  ww .  ja v a  2s . c  o  m*/
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Report1.pdf"));
        document.open();
        //add barcode
        PdfContentByte CB = writer.getDirectContent();
        BarcodeEAN codEAN = new BarcodeEAN();
        codEAN.setCode("1234567891023"); //this value must be 13 digits
        Paragraph para = new Paragraph();
        document.add(new Paragraph("Barcode UDCA"));
        codEAN.setCodeType(BarcodeEAN.UPCA);
        codEAN.setCode("1098765432112");
        document.add(codEAN.createImageWithBarcode(CB, BaseColor.BLACK, BaseColor.BLACK));
        document.add(para);

        Image image = Image.getInstance("images/Cherry.png");
        document.add(new Paragraph("Image"));
        document.add(image);

        // write tile with style
        document.add(new Paragraph("Hello World",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED)));
        // write date
        document.add(new Paragraph(new Date().toString()));
        document.add(new Paragraph("--------------------------------------------"));
        PdfPTable table = new PdfPTable(2);// 2 columns
        // set title , column sapn, aliignment,background color
        PdfPCell cell = new PdfPCell(new Paragraph("Title"));
        cell.setColspan(4);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(BaseColor.BLUE);
        table.addCell(cell);
        // PdfPTable table = new PdfPTable(x); should add multiple of x
        table.addCell("EmployeeID");
        table.addCell(value1);
        table.addCell("Name");
        table.addCell(value2);
        table.addCell("Last Name");
        table.addCell(value3);
        table.addCell("Age");
        table.addCell(value4);
        document.add(table);
        List list = new List(true, 20);
        list.add("First Item");
        list.add("Second Item");
        list.add("Third Item");
        list.add("Fourth Item");
        document.add(list);
        document.close();
        JOptionPane.showMessageDialog(null, "Report saved");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

}

From source file:bd.gov.forms.web.FormBuilder.java

License:Open Source License

public List getEntryListHeaders(Form form) {
    List list = new ArrayList();

    list.add("Date");
    list.add("Time");
    list.add("Status");
    for (Field field : form.getFields()) {
        list.add(field.getLabel());/*from w w  w .  ja  v  a  2  s.c o m*/
    }

    return list;
}

From source file:bl.pdf.PDFFile.java

private void createList(Section subCatPart) {
    List list = new List(true, false, 10);
    list.add(new ListItem("First point"));
    list.add(new ListItem("Second point"));
    list.add(new ListItem("Third point"));
    subCatPart.add(list);/*from  w w  w .  j  a  v  a  2s  . c o  m*/
}

From source file:cl.preguntame.clases.ListadoPDF.java

public List getListado() {

    List listado = new List();
    for (int i = 0; i < items.size(); i++) {
        listado.add(items.get(i));
    }/* w  w  w.  j  a va 2s . c om*/

    listado.setIndentationLeft(20);
    return listado;
}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * /*w ww  .  java  2 s.  c  om*/
 *  list 
 *
 * @param section list  section ?
 * @param e list   element
 * @throws Exception
 */
public static void setList(Section section, Element e) throws Exception {
    List list = new List(false, 15);
    list.setIndentationLeft(23);
    for (Element e1 : e.getChildren()) {
        ListItem item = new ListItem(e1.getText(), fnNormal);

        if (e1.getChild("url") != null) {
            item.add(getUrl(e1.getChild("url")));
        }

        item.setMultipliedLeading(1.8F);
        list.add(item);
    }
    list.getFirstItem().setSpacingBefore(-14);
    list.getLastItem().setSpacingAfter(14);

    section.add(list);
}

From source file:com.biblio.web.rest.PdfResources.java

@RequestMapping(value = "livre", method = RequestMethod.GET)
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, WriterException {
    response.setContentType("application/pdf");
    GenerateQRCode ge = new GenerateQRCode();

    try {/*  w  ww . j  av  a2 s.c  o m*/

        Document document = new Document();
        String param = request.getParameter("isbn");
        Livre livre = livreRepository.findOneByIsbn(param).get();
        PdfWriter e = PdfWriter.getInstance(document, response.getOutputStream());

        document.open();

        Font font = new Font();

        font.setStyle(Font.BOLD);
        font.setSize(12);

        List list = new List(15);

        //  document.left(12);
        list.add(new ListItem("Titre  :" + livre.getTitre(), font));
        list.add(new ListItem("Categorie  :" + livre.getCategorie().getDescription(), font));
        list.add(new ListItem("Auteurs   :" + livre.getAuteurs(), font));
        list.add(new ListItem("Edition   :" + livre.getEdition(), font));
        list.add(new ListItem("Editeur   :" + livre.getEditeur(), font));
        list.add(new ListItem("Collection   :" + livre.getCollection(), font));
        list.add(new ListItem("Date parution   :" + livre.getDateParution(), font));
        list.add(new ListItem("Isbn   " + livre.getIsbn(), font));
        list.add(new ListItem("Resume   : " + livre.getResume(), font));

        document.add(list);
        document.addTitle(livre.getTitre());
        document.setMargins(100, 20, 0, 0);
        document.addCreationDate();
        System.out.println("TTT v " + document.addTitle(param));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(ge.createQRImage(param, 125), "jpg", baos);
        Image image = Image.getInstance(baos.toByteArray());
        document.add(image);
        document.close();

    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }
}

From source file:com.example.pdfcreate.MainActivity.java

private static void createList(Section subCatPart) {
    List list = new List(true, false, 10);
    list.add(new ListItem("First point"));
    list.add(new ListItem("Second point"));
    list.add(new ListItem("Third point"));
    // subCatPart.add(list);
}

From source file:com.farouk.projectapp.ManagerGUI.java

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
    String pdfName = JOptionPane.showInputDialog(rootPane, "Enter Title", "Please enter a title", WIDTH);
    if (pdfName.isEmpty()) {
        pdfName = "Global Report";
    }//from  w  ww  .j a v  a 2s . c  o m
    Document document = new Document();
    int numEMployees = 1;

    try {
        PdfWriter.getInstance(document, new FileOutputStream(pdfName + ".pdf"));

        document.open();
        document.addAuthor("TeamPirates");
        document.addTitle("Global Report");

        Font font1 = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD);
        Font font2 = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.UNDERLINE);

        for (User u : SQLConnectMana.getEmployeesFromDb()) {
            JTable jTableTran = new JTable();
            JTable jTableReport = new JTable();

            Chapter chapter = new Chapter(
                    new Paragraph(new Phrase("Employee : " + u.getLogin() + "\n\n", font1)), numEMployees);

            Section section1 = chapter.addSection(new Paragraph(new Phrase("Recent Transactions :\n", font2)),
                    9);

            Section section2 = chapter.addSection(new Paragraph(new Phrase("Reported Companies :\n", font2)),
                    9);

            // Transactions :
            DefaultTableModel modelPDFtrans = new DefaultTableModel();
            modelPDFtrans.setColumnIdentifiers(
                    new String[] { "Name", "Operation", "Quantity", "Price Paid", "Date" });
            for (Transaction t : SQLConnectMana.getTransactions(u.getId())) {
                modelPDFtrans.addRow(new String[] { t.getSymbol(), t.getOperation(),
                        Integer.toString(t.getQuantity()), Double.toString(t.getPricePaid()), t.getDate() });
            }
            jTableTran.setModel(modelPDFtrans);

            PdfPTable pdfTableTrans = new PdfPTable(jTableTran.getColumnCount());

            for (int i = 0; i < jTableTran.getColumnCount(); i++) {
                pdfTableTrans.addCell(jTableTran.getColumnName(i));
            }
            //extracting data from the JTable and inserting it to PdfPTable
            for (int rows = 0; rows < jTableTran.getRowCount(); rows++) {
                for (int cols = 0; cols < jTableTran.getColumnCount(); cols++) {
                    pdfTableTrans.addCell(jTableTran.getModel().getValueAt(rows, cols).toString());

                }
            }
            Paragraph blank = new Paragraph("\n\n");
            section1.add(blank);
            section1.add(pdfTableTrans);

            section1.add(blank);
            //Reported Companies :
            DefaultTableModel modelPDFReported = new DefaultTableModel();
            modelPDFReported.setColumnIdentifiers(
                    new String[] { "Name", "Symbol", "Stock Price ()", "Quantity Bought" });
            for (Company c : SQLConnectMana.getNameOfReported(u.getId())) {
                modelPDFReported.addRow(new String[] { c.getName(), c.getSymbol(),
                        String.valueOf(c.getStockPrice().doubleValue()),
                        Integer.toString(c.getNumberOwned()) });
            }
            jTableReport.setModel(modelPDFReported);
            PdfPTable pdfTableReport = new PdfPTable(jTableReport.getColumnCount());

            for (int i = 0; i < jTableReport.getColumnCount(); i++) {
                pdfTableReport.addCell(jTableReport.getColumnName(i));
            }
            //extracting data from the JTable and inserting it to PdfPTable
            for (int rows = 0; rows < jTableReport.getRowCount(); rows++) {
                for (int cols = 0; cols < jTableReport.getColumnCount(); cols++) {
                    pdfTableReport.addCell(jTableReport.getModel().getValueAt(rows, cols).toString());
                }
            }
            section2.add(blank);
            section2.add(pdfTableReport);
            section2.add(blank);
            //End of doc for a single employee
            document.add(chapter);

            numEMployees++;

        }
        Chapter ban = new Chapter(new Paragraph(new Phrase("Prohibited Companies :\n\n", font1)),
                ++numEMployees);

        com.itextpdf.text.List bannedCompanies = new List(List.ORDERED);
        for (String lii : SQLConnectMana.getBannedCompForAll()) {
            bannedCompanies.add(new com.itextpdf.text.ListItem(lii));
        }
        ban.add(bannedCompanies);
        document.add(ban);
        document.close();
    } catch (DocumentException | FileNotFoundException e) {
        System.err.println("Sorry Problem in pdf.\n" + e);
    }

}

From source file:com.github.wolfposd.imsqti2pdf.PDFCreator.java

License:Open Source License

private void addAnswerTexts(Paragraph paragraph, boolean showCorrectAnswer, Question question) {
    if (question.basetype == BaseType.IDENTIFIER) {
        List list = new List(false, 20);

        list.setListSymbol(SQUARE_CHUNK);
        for (String key : question.answers.keySet()) {
            String answer = question.answers.get(key);

            Double points = question.points.get(key);
            points = points == null ? 0 : points;
            if (showCorrectAnswer) {
                ListItem item = new ListItem(answer);
                item.getFont().setSize(OVERALLFONTSIZE);

                if (points > 0) {
                    item.getFont().setColor(39, 158, 35);
                } else {
                    // item.getFont().setColor(255, 0, 0);
                }//from   w  w w.ja v a2  s . com
                list.add(item);
            } else {
                ListItem item = new ListItem(answer);
                item.getFont().setSize(OVERALLFONTSIZE);
                list.add(item);
            }
        }

        paragraph.add(Chunk.NEWLINE);
        paragraph.add(list);
    } else if (question.basetype == BaseType.STRING) {
        paragraph.add(Chunk.NEWLINE);
        paragraph.add(Chunk.NEWLINE);

        if (showCorrectAnswer) {
            String key = question.points.keySet().iterator().next();
            Double points = question.points.get(key);

            paragraph.add(new Phrase(getXes(points) + " " + LocaleStrings.getString("answer") + " " + key));
        } else {
            paragraph.add(new Phrase(LocaleStrings.getString("answerLine")));
        }
    }
}