Search in sources :

Example 1 with ListItem

use of com.itextpdf.layout.element.ListItem in project i7js-highlevel by itext.

the class C04E09_ListItemExample method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
    resultSet.remove(0);
    com.itextpdf.layout.element.List list = new com.itextpdf.layout.element.List(ListNumberingType.DECIMAL);
    for (List<String> record : resultSet) {
        ListItem li = new ListItem();
        li.setKeepTogether(true);
        String url = String.format("http://www.imdb.com/title/tt%s", record.get(0));
        Link movie = new Link(record.get(2), PdfAction.createURI(url));
        li.add(new Paragraph(movie.setFontSize(14))).add(new Paragraph(String.format("Directed by %s (%s, %s)", record.get(3), record.get(4), record.get(1))));
        File file = new File(String.format("src/main/resources/img/%s.jpg", record.get(0)));
        if (file.exists()) {
            Image img = new Image(ImageDataFactory.create(file.getPath()));
            img.scaleToFit(10000, 120);
            li.add(img);
        }
        list.add(li);
    }
    document.add(list);
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Image(com.itextpdf.layout.element.Image) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph) CsvTo2DList(com.itextpdf.highlevel.util.CsvTo2DList) List(java.util.List) ListItem(com.itextpdf.layout.element.ListItem) File(java.io.File) Link(com.itextpdf.layout.element.Link)

Example 2 with ListItem

use of com.itextpdf.layout.element.ListItem in project i7js-highlevel by itext.

the class C06E01_URIAction method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
    resultSet.remove(0);
    com.itextpdf.layout.element.List list = new com.itextpdf.layout.element.List(ListNumberingType.DECIMAL);
    for (List<String> record : resultSet) {
        ListItem li = new ListItem();
        li.setKeepTogether(true);
        li.add(new Paragraph().setFontSize(14).add(record.get(2))).add(new Paragraph(String.format("Directed by %s (%s, %s)", record.get(3), record.get(4), record.get(1))));
        File file = new File(String.format("src/main/resources/img/%s.jpg", record.get(0)));
        if (file.exists()) {
            Image img = new Image(ImageDataFactory.create(file.getPath()));
            img.scaleToFit(10000, 120);
            li.add(img);
        }
        String url = String.format("http://www.imdb.com/title/tt%s", record.get(0));
        li.setAction(PdfAction.createURI(url));
        list.add(li);
    }
    document.add(list);
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Image(com.itextpdf.layout.element.Image) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph) CsvTo2DList(com.itextpdf.highlevel.util.CsvTo2DList) List(java.util.List) ListItem(com.itextpdf.layout.element.ListItem) File(java.io.File)

Example 3 with ListItem

use of com.itextpdf.layout.element.ListItem in project i7js-highlevel by itext.

the class C06E02_NamedAction method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    Paragraph p = new Paragraph().add("Go to last page").setAction(PdfAction.createNamed(PdfName.LastPage));
    document.add(p);
    List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
    resultSet.remove(0);
    com.itextpdf.layout.element.List list = new com.itextpdf.layout.element.List(ListNumberingType.DECIMAL);
    for (List<String> record : resultSet) {
        ListItem li = new ListItem();
        li.setKeepTogether(true);
        li.add(new Paragraph().setFontSize(14).add(record.get(2))).add(new Paragraph(String.format("Directed by %s (%s, %s)", record.get(3), record.get(4), record.get(1))));
        File file = new File(String.format("src/main/resources/img/%s.jpg", record.get(0)));
        if (file.exists()) {
            Image img = new Image(ImageDataFactory.create(file.getPath()));
            img.scaleToFit(10000, 120);
            li.add(img);
        }
        list.add(li);
    }
    document.add(list);
    p = new Paragraph().add("Go to first page").setAction(PdfAction.createNamed(PdfName.FirstPage));
    document.add(p);
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Image(com.itextpdf.layout.element.Image) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph) CsvTo2DList(com.itextpdf.highlevel.util.CsvTo2DList) List(java.util.List) ListItem(com.itextpdf.layout.element.ListItem) File(java.io.File)

Example 4 with ListItem

use of com.itextpdf.layout.element.ListItem in project i7js-highlevel by itext.

the class C04E10_NestedLists method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    // Initialize document
    PageSize pagesize = PageSize.A6.rotate();
    Document document = new Document(pdf, pagesize);
    // Set column parameters
    float offSet = 36;
    float gutter = 23;
    float columnWidth = (pagesize.getWidth() - offSet * 2) / 2 - gutter;
    float columnHeight = pagesize.getHeight() - offSet * 2;
    // Define column areas
    Rectangle[] columns = { new Rectangle(offSet, offSet, columnWidth, columnHeight), new Rectangle(offSet + columnWidth + gutter, offSet, columnWidth, columnHeight) };
    document.setRenderer(new ColumnDocumentRenderer(document, columns));
    List list = new List();
    List list1 = new List(ListNumberingType.DECIMAL);
    List listEL = new List(ListNumberingType.ENGLISH_LOWER);
    listEL.add("Dr. Jekyll");
    listEL.add("Mr. Hyde");
    ListItem liEL = new ListItem();
    liEL.add(listEL);
    list1.add(liEL);
    List listEU = new List(ListNumberingType.ENGLISH_UPPER);
    listEU.add("Dr. Jekyll");
    listEU.add("Mr. Hyde");
    ListItem liEU = new ListItem();
    liEU.add(listEU);
    list1.add(liEU);
    ListItem li1 = new ListItem();
    li1.add(list1);
    list.add(li1);
    ListItem li = new ListItem();
    List listGL = new List(ListNumberingType.GREEK_LOWER);
    listGL.add("Dr. Jekyll");
    listGL.add("Mr. Hyde");
    li.add(listGL);
    List listGU = new List(ListNumberingType.GREEK_UPPER);
    listGU.add("Dr. Jekyll");
    listGU.add("Mr. Hyde");
    li.add(listGU);
    List listRL = new List(ListNumberingType.ROMAN_LOWER);
    listRL.add("Dr. Jekyll");
    listRL.add("Mr. Hyde");
    li.add(listRL);
    List listRU = new List(ListNumberingType.ROMAN_UPPER);
    listRU.add("Dr. Jekyll");
    listRU.add("Mr. Hyde");
    li.add(listRU);
    list.add(li);
    List listZ1 = new List(ListNumberingType.ZAPF_DINGBATS_1);
    listZ1.add("Dr. Jekyll");
    listZ1.add("Mr. Hyde");
    ListItem liZ1 = new ListItem();
    liZ1.add(listZ1);
    List listZ2 = new List(ListNumberingType.ZAPF_DINGBATS_2);
    listZ2.add("Dr. Jekyll");
    listZ2.add("Mr. Hyde");
    ListItem liZ2 = new ListItem();
    liZ2.add(listZ2);
    List listZ3 = new List(ListNumberingType.ZAPF_DINGBATS_3);
    listZ3.add("Dr. Jekyll");
    listZ3.add("Mr. Hyde");
    ListItem liZ3 = new ListItem();
    liZ3.add(listZ3);
    List listZ4 = new List(ListNumberingType.ZAPF_DINGBATS_4);
    listZ4.add("Dr. Jekyll");
    listZ4.add("Mr. Hyde");
    ListItem liZ4 = new ListItem();
    liZ4.add(listZ4);
    listZ3.add(liZ4);
    listZ2.add(liZ3);
    listZ1.add(liZ2);
    list.add(liZ1);
    document.add(list);
    // Close document
    document.close();
}
Also used : ColumnDocumentRenderer(com.itextpdf.layout.ColumnDocumentRenderer) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PageSize(com.itextpdf.kernel.geom.PageSize) Rectangle(com.itextpdf.kernel.geom.Rectangle) List(com.itextpdf.layout.element.List) ListItem(com.itextpdf.layout.element.ListItem) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument)

Example 5 with ListItem

use of com.itextpdf.layout.element.ListItem in project spring-learning by moon-zhou.

the class Demo002 method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF writer
    PdfWriter writer = new PdfWriter(dest);
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(writer);
    // Initialize document
    Document document = new Document(pdf);
    // Create a PdfFont
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    // Add a Paragraph
    document.add(new Paragraph("iText is:").setFont(font));
    // Create a List
    List list = new List().setSymbolIndent(12).setListSymbol("\u2022").setFont(font);
    // Add ListItem objects
    list.add(new ListItem("Never gonna give you up")).add(new ListItem("Never gonna let you down")).add(new ListItem("Never gonna run around and desert you")).add(new ListItem("Never gonna make you cry")).add(new ListItem("Never gonna say goodbye")).add(new ListItem("Never gonna tell a lie and hurt you"));
    // Add the list
    document.add(list);
    // Close document
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfFont(com.itextpdf.kernel.font.PdfFont) List(com.itextpdf.layout.element.List) ListItem(com.itextpdf.layout.element.ListItem) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Aggregations

PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)5 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)5 Document (com.itextpdf.layout.Document)5 ListItem (com.itextpdf.layout.element.ListItem)5 Paragraph (com.itextpdf.layout.element.Paragraph)4 CsvTo2DList (com.itextpdf.highlevel.util.CsvTo2DList)3 Image (com.itextpdf.layout.element.Image)3 File (java.io.File)3 List (java.util.List)3 List (com.itextpdf.layout.element.List)2 PdfFont (com.itextpdf.kernel.font.PdfFont)1 PageSize (com.itextpdf.kernel.geom.PageSize)1 Rectangle (com.itextpdf.kernel.geom.Rectangle)1 ColumnDocumentRenderer (com.itextpdf.layout.ColumnDocumentRenderer)1 Link (com.itextpdf.layout.element.Link)1