Skip to main content
Skip table of contents

iText Building Blocks - Chapter 4: AbstractElement examples (part 1)

c04e01_divexample1

JAVA
JAVA
package com.itextpdf.highlevel.chapter04;

import com.itextpdf.highlevel.util.CsvTo2DList;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.action.PdfAction;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.borders.SolidBorder;
import com.itextpdf.layout.element.Div;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.element.Link;
import com.itextpdf.layout.element.Paragraph;
import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * @author Bruno Lowagie (iText Software)
 */
public class C04E01_DivExample1 {
    
    public static final String SRC = "src/main/resources/data/jekyll_hyde.csv";
    public static final String DEST = "results/chapter04/jekyll_hyde_overviewV1.pdf";
       
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C04E01_DivExample1().createPdf(DEST);
    }
    
    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);
        for (List<String> record : resultSet) {
            Div div = new Div()
                .setBorderLeft(new SolidBorder(2))
                .setPaddingLeft(3)
                .setMarginBottom(10);
            String url = String.format(
                "http://www.imdb.com/title/tt%s", record.get(0));
            Link movie = new Link(record.get(2), PdfAction.createURI(url));
            div.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);
                div.add(img);
            }
            document.add(div);
        }
        document.close();
    }
    
}
C#
C#
using System;
using System.Collections.Generic;
using System.IO;
using iText.Highlevel.Util;
using iText.IO.Image;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Action;
using iText.Layout;
using iText.Layout.Borders;
using iText.Layout.Element;

namespace iText.Highlevel.Chapter04 {
    /// <author>Bruno Lowagie (iText Software)</author>
    public class C04E01_DivExample1 {
        public const String SRC = "../../../resources/data/jekyll_hyde.csv";

        public const String DEST = "../../../results/chapter04/jekyll_hyde_overviewV1.pdf";

        public static void Main(String[] args) {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
            new C04E01_DivExample1().CreatePdf(DEST);
        }

        public virtual void CreatePdf(String dest) {
            PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
            Document document = new Document(pdf);
            IList<IList<String>> resultSet = CsvTo2DList.Convert(SRC, "|");
            resultSet.RemoveAt(0);
            foreach (IList<String> record in resultSet) {
                Div div = new Div().SetBorderLeft(new SolidBorder(2)).SetPaddingLeft(3).SetMarginBottom(10);
                String url = String.Format("http://www.imdb.com/title/tt{0}", record[0]);
                Link movie = new Link(record[2], PdfAction.CreateURI(url));
                div.Add(new Paragraph(movie.SetFontSize(14))).Add(new Paragraph(String.Format("Directed by {0} ({1}, {2})", record
                    [3], record[4], record[1])));
                FileInfo file = new FileInfo(String.Format("../../../resources/img/{0}.jpg", record[0]));
                if (file.Exists) {
                    iText.Layout.Element.Image img = new Image(ImageDataFactory.Create(file.FullName));
                    img.ScaleToFit(10000, 120);
                    div.Add(img);
                }
                document.Add(div);
            }
            document.Close();
        }
    }
}

c04e02_divexample2

JAVA
JAVA
package com.itextpdf.highlevel.chapter04;

import com.itextpdf.highlevel.util.CsvTo2DList;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.action.PdfAction;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.borders.SolidBorder;
import com.itextpdf.layout.element.Div;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.element.Link;
import com.itextpdf.layout.element.Paragraph;
import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * @author Bruno Lowagie (iText Software)
 */
public class C04E02_DivExample2 {
    
    public static final String SRC = "src/main/resources/data/jekyll_hyde.csv";
    public static final String DEST = "results/chapter04/jekyll_hyde_overviewV2.pdf";
       
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C04E02_DivExample2().createPdf(DEST);
    }
    
    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);
        for (List<String> record : resultSet) {
            Div div = new Div()
                .setKeepTogether(true)
                .setBorderLeft(new SolidBorder(2))
                .setPaddingLeft(3)
                .setMarginBottom(10);
            String url = String.format(
                "http://www.imdb.com/title/tt%s", record.get(0));
            Link movie = new Link(record.get(2), PdfAction.createURI(url));
            div.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);
                div.add(img);
            }
            document.add(div);
        }
        document.close();
    }
    
}
C#
C#
using System;
using System.Collections.Generic;
using System.IO;
using iText.Highlevel.Util;
using iText.IO.Image;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Action;
using iText.Layout;
using iText.Layout.Borders;
using iText.Layout.Element;

namespace iText.Highlevel.Chapter04 {
    /// <author>Bruno Lowagie (iText Software)</author>
    public class C04E02_DivExample2 {
        public const String SRC = "../../../resources/data/jekyll_hyde.csv";

        public const String DEST = "../../../results/chapter04/jekyll_hyde_overviewV2.pdf";

        public static void Main(String[] args) {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
            new C04E02_DivExample2().CreatePdf(DEST);
        }

        public virtual void CreatePdf(String dest) {
            PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
            Document document = new Document(pdf);
            IList<IList<String>> resultSet = CsvTo2DList.Convert(SRC, "|");
            resultSet.RemoveAt(0);
            foreach (IList<String> record in resultSet) {
                Div div = new Div().SetKeepTogether(true).SetBorderLeft(new SolidBorder(2)).SetPaddingLeft(3).SetMarginBottom
                    (10);
                String url = String.Format("http://www.imdb.com/title/tt{0}", record[0]);
                Link movie = new Link(record[2], PdfAction.CreateURI(url));
                div.Add(new Paragraph(movie.SetFontSize(14))).Add(new Paragraph(String.Format("Directed by {0} ({1}, {2})", record
                    [3], record[4], record[1])));
                FileInfo file = new FileInfo(String.Format("../../../resources/img/{0}.jpg", record[0]));
                if (file.Exists) {
                    iText.Layout.Element.Image img = new Image(ImageDataFactory.Create(file.FullName));
                    img.ScaleToFit(10000, 120);
                    div.Add(img);
                }
                document.Add(div);
            }
            document.Close();
        }
    }
}

c04e03_lineseparatorexample

JAVA
JAVA
package com.itextpdf.highlevel.chapter04;

import com.itextpdf.highlevel.util.CsvTo2DList;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.action.PdfAction;
import com.itextpdf.kernel.pdf.canvas.draw.SolidLine;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.borders.SolidBorder;
import com.itextpdf.layout.element.*;
import com.itextpdf.layout.properties.UnitValue;
import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * @author Bruno Lowagie (iText Software)
 */
public class C04E03_LineSeparatorExample {

    public static final String SRC = "src/main/resources/data/jekyll_hyde.csv";
    public static final String DEST = "results/chapter04/jekyll_hyde_overviewV3.pdf";

    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C04E03_LineSeparatorExample().createPdf(DEST);
    }

    public void createPdf(String dest) throws IOException {
        PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
        Document document = new Document(pdf);
        SolidLine line = new SolidLine(1f);
        line.setColor(ColorConstants.RED);
        LineSeparator ls = new LineSeparator(line);
        ls.setWidth(UnitValue.createPercentValue(50));
        ls.setMarginTop(5);
        List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
        resultSet.remove(0);
        for (List<String> record : resultSet) {
            String url = String.format(
                "http://www.imdb.com/title/tt%s", record.get(0));
            Link movie = new Link(record.get(2), PdfAction.createURI(url));
            Div div = new Div()
                .setKeepTogether(true)
                .setBorderLeft(new SolidBorder(2))
                .setPaddingLeft(3)
                .setMarginBottom(10)
                .add(new Paragraph(movie.setFontSize(14f)))
                .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);
                div.add(img);
            }
            div.add(ls);
            document.add(div);
        }
        document.close();
    }

}
C#
C#
using System;
using System.Collections.Generic;
using System.IO;
using iText.Highlevel.Util;
using iText.IO.Image;
using iText.Kernel.Colors;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Action;
using iText.Kernel.Pdf.Canvas.Draw;
using iText.Layout;
using iText.Layout.Borders;
using iText.Layout.Element;
using iText.Layout.Properties;

namespace iText.Highlevel.Chapter04 {
    /// <author>Bruno Lowagie (iText Software)</author>
    public class C04E03_LineSeparatorExample {
        public const String SRC = "../../../resources/data/jekyll_hyde.csv";

        public const String DEST = "../../../results/chapter04/jekyll_hyde_overviewV3.pdf";

        public static void Main(String[] args) {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
            new C04E03_LineSeparatorExample().CreatePdf(DEST);
        }

        public virtual void CreatePdf(String dest) {
            PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
            Document document = new Document(pdf);
            SolidLine line = new SolidLine(1f);
            line.SetColor(ColorConstants.RED);
            LineSeparator ls = new LineSeparator(line);
            ls.SetWidth(UnitValue.CreatePercentValue(50));
            ls.SetMarginTop(5);
            IList<IList<String>> resultSet = CsvTo2DList.Convert(SRC, "|");
            resultSet.RemoveAt(0);
            foreach (IList<String> record in resultSet) {
                String url = String.Format("http://www.imdb.com/title/tt{0}", record[0]);
                Link movie = new Link(record[2], PdfAction.CreateURI(url));
                Div div = new Div().SetKeepTogether(true).SetBorderLeft(new SolidBorder(2)).SetPaddingLeft(3).SetMarginBottom
                    (10).Add(new Paragraph(movie.SetFontSize(14f))).Add(new Paragraph(String.Format("Directed by {0} ({1}, {2})"
                    , record[3], record[4], record[1])));
                FileInfo file = new FileInfo(String.Format("../../../resources/img/{0}.jpg", record[0]));
                if (file.Exists) {
                    iText.Layout.Element.Image img = new Image(ImageDataFactory.Create(file.FullName));
                    img.ScaleToFit(10000, 120);
                    div.Add(img);
                }
                div.Add(ls);
                document.Add(div);
            }
            document.Close();
        }
    }
}

c04e04_paragraphanddiv1

JAVA
JAVA
package com.itextpdf.highlevel.chapter04;

import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Div;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.hyphenation.HyphenationConfig;
import com.itextpdf.layout.properties.TextAlignment;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author Bruno Lowagie (iText Software)
 */
public class C04E04_ParagraphAndDiv1 {
    public static final String SRC = "src/main/resources/txt/jekyll_hyde.txt";
    public static final String DEST = "results/chapter04/jekyll_hydeV1.pdf";
    
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C04E04_ParagraphAndDiv1().createPdf(DEST);
    }
    
    public void createPdf(String dest) throws IOException {
        //Initialize PDF document
        PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
        
        // Initialize document
        Document document = new Document(pdf);
        PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
        PdfFont bold = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
        document.setTextAlignment(TextAlignment.JUSTIFIED)
            .setHyphenation(new HyphenationConfig("en", "uk", 3, 3));
        
        BufferedReader br = new BufferedReader(new FileReader(SRC));
        String line;
        Div div = new Div();
        while ((line = br.readLine()) != null) {
            Paragraph title = new Paragraph(line)
                .setFont(bold).setFontSize(12)
                .setMarginBottom(0);
            div = new Div()
                .add(title)
                .setFont(font).setFontSize(11)
                .setMarginBottom(18);
            while ((line = br.readLine()) != null) {
                div.add(
                    new Paragraph(line)
                        .setMarginBottom(0)
                        .setFirstLineIndent(36)
                );
                if (line.isEmpty()) {
                    document.add(div);
                    break;
                }
            }
        }
        document.add(div);

        //Close document
        document.close();
    }

}
C#
C#
using System;
using System.IO;

using iText.IO.Font.Constants;
using iText.Kernel.Font;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Hyphenation;
using iText.Layout.Properties;

namespace iText.Highlevel.Chapter04 {
    /// <author>Bruno Lowagie (iText Software)</author>
    public class C04E04_ParagraphAndDiv1 {
        public const String SRC = "../../../resources/txt/jekyll_hyde.txt";

        public const String DEST = "../../../results/chapter04/jekyll_hydeV1.pdf";

        public static void Main(String[] args) {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
            new C04E04_ParagraphAndDiv1().CreatePdf(DEST);
        }

        public virtual void CreatePdf(String dest) {
            //Initialize PDF document
            PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
            // Initialize document
            Document document = new Document(pdf);
            PdfFont font = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
            PdfFont bold = PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD);
            document.SetTextAlignment(TextAlignment.JUSTIFIED).SetHyphenation(new HyphenationConfig("en", "uk", 3, 3));
            StreamReader sr = File.OpenText(SRC);
            String line;
            Div div = new Div();
            while ((line = sr.ReadLine()) != null) {
                Paragraph title = new Paragraph(line).SetFont(bold).SetFontSize(12).SetMarginBottom(0);
                div = new Div().Add(title).SetFont(font).SetFontSize(11).SetMarginBottom(18);
                while ((line = sr.ReadLine()) != null) {
                    div.Add(new Paragraph(line).SetMarginBottom(0).SetFirstLineIndent(36));
                    if (String.IsNullOrEmpty(line)) {
                        document.Add(div);
                        break;
                    }
                }
            }
            document.Add(div);
            //Close document
            document.Close();
        }
    }
}

c04e05_paragraphanddiv2

JAVA
JAVA
package com.itextpdf.highlevel.chapter04;

import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Div;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.hyphenation.HyphenationConfig;
import com.itextpdf.layout.properties.TextAlignment;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author Bruno Lowagie (iText Software)
 */
public class C04E05_ParagraphAndDiv2 {
    public static final String SRC = "src/main/resources/txt/jekyll_hyde.txt";
    public static final String DEST = "results/chapter04/jekyll_hydeV2.pdf";
    
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C04E05_ParagraphAndDiv2().createPdf(DEST);
    }
    
    public void createPdf(String dest) throws IOException {
        //Initialize PDF document
        PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
        
        // Initialize document
        Document document = new Document(pdf);
        PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
        PdfFont bold = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
        document.setTextAlignment(TextAlignment.JUSTIFIED)
            .setHyphenation(new HyphenationConfig("en", "uk", 3, 3));
        
        BufferedReader br = new BufferedReader(new FileReader(SRC));
        String line;
        Div div = new Div();
        while ((line = br.readLine()) != null) {
            document.add(new Paragraph(line)
                .setFont(bold).setFontSize(12)
                .setMarginBottom(0)
                .setKeepWithNext(true));
            div = new Div()
                .setFont(font).setFontSize(11)
                .setMarginBottom(18);
            while ((line = br.readLine()) != null) {
                div.add(
                    new Paragraph(line)
                        .setMarginBottom(0)
                        .setFirstLineIndent(36)
                );
                if (line.isEmpty()) {
                    document.add(div);
                    break;
                }
            }
        }
        document.add(div);

        //Close document
        document.close();
    }

}
C#
C#
using System;
using System.IO;

using iText.IO.Font.Constants;
using iText.Kernel.Font;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Hyphenation;
using iText.Layout.Properties;

namespace iText.Highlevel.Chapter04 {
    /// <author>Bruno Lowagie (iText Software)</author>
    public class C04E05_ParagraphAndDiv2 {
        public const String SRC = "../../../resources/txt/jekyll_hyde.txt";

        public const String DEST = "../../../results/chapter04/jekyll_hydeV2.pdf";

        public static void Main(String[] args) {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
            new C04E05_ParagraphAndDiv2().CreatePdf(DEST);
        }

        public virtual void CreatePdf(String dest) {
            //Initialize PDF document
            PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
            // Initialize document
            Document document = new Document(pdf);
            PdfFont font = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
            PdfFont bold = PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD);
            document.SetTextAlignment(TextAlignment.JUSTIFIED).SetHyphenation(new HyphenationConfig("en", "uk", 3, 3));
            StreamReader sr = File.OpenText(SRC);
            String line;
            Div div = new Div();
            while ((line = sr.ReadLine()) != null) {
                document.Add(new Paragraph(line).SetFont(bold).SetFontSize(12).SetMarginBottom(0).SetKeepWithNext(true));
                div = new Div().SetFont(font).SetFontSize(11).SetMarginBottom(18);
                while ((line = sr.ReadLine()) != null) {
                    div.Add(new Paragraph(line).SetMarginBottom(0).SetFirstLineIndent(36));
                    if (String.IsNullOrEmpty(line)) {
                        document.Add(div);
                        break;
                    }
                }
            }
            document.Add(div);
            //Close document
            document.Close();
        }
    }
}

c04e05_paragraphanddiv3

JAVA
JAVA
package com.itextpdf.highlevel.chapter04;

import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Div;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.hyphenation.HyphenationConfig;
import com.itextpdf.layout.properties.TextAlignment;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author Bruno Lowagie (iText Software)
 */
public class C04E05_ParagraphAndDiv3 {
    public static final String SRC = "src/main/resources/txt/jekyll_hyde.txt";
    public static final String DEST = "results/chapter04/jekyll_hydeV3.pdf";
    
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C04E05_ParagraphAndDiv3().createPdf(DEST);
    }
    
    public void createPdf(String dest) throws IOException {
        //Initialize PDF document
        PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
        
        // Initialize document
        Document document = new Document(pdf);
        PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
        PdfFont bold = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
        document.setTextAlignment(TextAlignment.JUSTIFIED)
            .setHyphenation(new HyphenationConfig("en", "uk", 3, 3));
        
        BufferedReader br = new BufferedReader(new FileReader(SRC));
        String line;
        Div div = new Div();
        while ((line = br.readLine()) != null) {
            document.add(new Paragraph(line)
                .setFont(bold).setFontSize(12)
                .setMarginBottom(0)
                .setKeepWithNext(true));
            div = new Div()
                .setFont(font).setFontSize(11)
                .setMarginBottom(18);
            while ((line = br.readLine()) != null) {
                div.add(
                    new Paragraph(line)
                        .setMarginBottom(0)
                        .setFirstLineIndent(36)
                        .setMultipliedLeading(1.2f)
                );
                if (line.isEmpty()) {
                    document.add(div);
                    break;
                }
            }
        }
        document.add(div);

        //Close document
        document.close();
    }

}
C#
C#
using System;
using System.IO;

using iText.IO.Font.Constants;
using iText.Kernel.Font;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Hyphenation;
using iText.Layout.Properties;

namespace iText.Highlevel.Chapter04 {
    /// <author>Bruno Lowagie (iText Software)</author>
    public class C04E05_ParagraphAndDiv3 {
        public const String SRC = "../../../resources/txt/jekyll_hyde.txt";

        public const String DEST = "../../../results/chapter04/jekyll_hydeV3.pdf";

        public static void Main(String[] args) {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
            new C04E05_ParagraphAndDiv3().CreatePdf(DEST);
        }

        public virtual void CreatePdf(String dest) {
            //Initialize PDF document
            PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
            // Initialize document
            Document document = new Document(pdf);
            PdfFont font = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
            PdfFont bold = PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD);
            document.SetTextAlignment(TextAlignment.JUSTIFIED).SetHyphenation(new HyphenationConfig("en", "uk", 3, 3));
            StreamReader sr = File.OpenText(SRC);
            String line;
            Div div = new Div();
            while ((line = sr.ReadLine()) != null) {
                document.Add(new Paragraph(line).SetFont(bold).SetFontSize(12).SetMarginBottom(0).SetKeepWithNext(true));
                div = new Div().SetFont(font).SetFontSize(11).SetMarginBottom(18);
                while ((line = sr.ReadLine()) != null) {
                    div.Add(new Paragraph(line).SetMarginBottom(0).SetFirstLineIndent(36).SetMultipliedLeading(1.2f));
                    if (String.IsNullOrEmpty(line)) {
                        document.Add(div);
                        break;
                    }
                }
            }
            document.Add(div);
            //Close document
            document.Close();
        }
    }
}

c04e06_customparagraph

JAVA
JAVA
package com.itextpdf.highlevel.chapter04;

import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.canvas.CanvasArtifact;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.properties.Background;
import com.itextpdf.layout.properties.Property;
import com.itextpdf.layout.renderer.DrawContext;
import com.itextpdf.layout.renderer.ParagraphRenderer;
import java.io.File;
import java.io.IOException;

/**
 * @author Bruno Lowagie (iText Software)
 */
public class C04E06_CustomParagraph {

    class MyParagraphRenderer extends ParagraphRenderer {

        public MyParagraphRenderer(Paragraph modelElement) {
            super(modelElement);
        }

        @Override
        public void drawBackground(DrawContext drawContext) {
            Background background = this.<Background>getProperty(Property.BACKGROUND);
            if (background != null) {
                Rectangle bBox = getOccupiedAreaBBox();
                boolean isTagged =
                    drawContext.isTaggingEnabled();
                if (isTagged) {
                    drawContext.getCanvas().openTag(new CanvasArtifact());
                }
                Rectangle bgArea = applyMargins(bBox, false);
                if (bgArea.getWidth() <= 0 || bgArea.getHeight() <= 0) {
                    return;
                }
                drawContext.getCanvas().saveState()
                    .setFillColor(background.getColor())
                    .roundRectangle(
                    (double)bgArea.getX() - background.getExtraLeft(),
                    (double)bgArea.getY() - background.getExtraBottom(),
                    (double)bgArea.getWidth()
                        + background.getExtraLeft() + background.getExtraRight(),
                    (double)bgArea.getHeight()
                        + background.getExtraTop() + background.getExtraBottom(),
                    5)
                    .fill().restoreState();
                if (isTagged) {
                    drawContext.getCanvas().closeTag();
                }
            }
        }
    }

    public static final String DEST = "results/chapter04/custom_paragraph.pdf";

    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C04E06_CustomParagraph().createPdf(DEST);
    }

    public void createPdf(String dest) throws IOException {
        // Initialize PDF document
        PdfDocument pdf = new PdfDocument(new PdfWriter(dest));

        // Initialize document
        Document document = new Document(pdf);

        Paragraph p1 = new Paragraph(
            "The Strange Case of Dr. Jekyll and Mr. Hyde");
        p1.setBackgroundColor(ColorConstants.ORANGE);
        document.add(p1);

        Paragraph p2 = new Paragraph(
            "The Strange Case of Dr. Jekyll and Mr. Hyde");
        p2.setBackgroundColor(ColorConstants.ORANGE);
        p2.setNextRenderer(new MyParagraphRenderer(p2));
        document.add(p2);

        document.close();
    }
}
C#
C#
using System;
using System.IO;
using iText.Kernel.Colors;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas;
using iText.Kernel.Pdf.Tagutils;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;
using iText.Layout.Renderer;

namespace iText.Highlevel.Chapter04 {
    /// <author>Bruno Lowagie (iText Software)</author>
    public class C04E06_CustomParagraph {
        internal class MyParagraphRenderer : ParagraphRenderer {
            public MyParagraphRenderer(Paragraph modelElement)
                : base(modelElement) {
            }

            public override void DrawBackground(DrawContext drawContext) {
                Background background = this.GetProperty<Background>(Property.BACKGROUND);
                if (background != null) {
                    Rectangle bBox = this.GetOccupiedAreaBBox();
                    bool isTagged = drawContext.IsTaggingEnabled();
                    if (isTagged) {
                        drawContext.GetCanvas().OpenTag(new CanvasArtifact());
                    }
                    Rectangle bgArea = this.ApplyMargins(bBox, false);
                    if (bgArea.GetWidth() <= 0 || bgArea.GetHeight() <= 0) {
                        return;
                    }
                    drawContext.GetCanvas().SaveState().SetFillColor(background.GetColor()).RoundRectangle((double)bgArea.GetX
                        () - background.GetExtraLeft(), (double)bgArea.GetY() - background.GetExtraBottom(), (double)bgArea.GetWidth
                        () + background.GetExtraLeft() + background.GetExtraRight(), (double)bgArea.GetHeight() + background.GetExtraTop
                        () + background.GetExtraBottom(), 5).Fill().RestoreState();
                    if (isTagged) {
                        drawContext.GetCanvas().CloseTag();
                    }
                }
            }
        }

        public const String DEST = "../../../results/chapter04/custom_paragraph.pdf";

        public static void Main(String[] args) {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
            new C04E06_CustomParagraph().CreatePdf(DEST);
        }

        public virtual void CreatePdf(String dest) {
            // Initialize PDF document
            PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
            // Initialize document
            Document document = new Document(pdf);
            Paragraph p1 = new Paragraph("The Strange Case of Dr. Jekyll and Mr. Hyde");
            p1.SetBackgroundColor(ColorConstants.ORANGE);
            document.Add(p1);
            Paragraph p2 = new Paragraph("The Strange Case of Dr. Jekyll and Mr. Hyde");
            p2.SetBackgroundColor(ColorConstants.ORANGE);
            p2.SetNextRenderer(new C04E06_CustomParagraph.MyParagraphRenderer(p2));
            document.Add(p2);
            document.Close();
        }
    }
}

c04e07_listtypes

JAVA
JAVA
package com.itextpdf.highlevel.chapter04;

import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.ColumnDocumentRenderer;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.List;
import com.itextpdf.layout.properties.ListNumberingType;
import java.io.File;
import java.io.IOException;

/**
 * @author Bruno Lowagie (iText Software)
 */
public class C04E07_ListTypes {
    
    public static final String DEST = "results/chapter04/list_types.pdf";
    
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C04E07_ListTypes().createPdf(DEST);
    }
    
    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.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);
        
        list = new List(ListNumberingType.DECIMAL);
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);
        
        list = new List(ListNumberingType.ENGLISH_LOWER);
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);
        
        list = new List(ListNumberingType.ENGLISH_UPPER);
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);
        
        list = new List(ListNumberingType.GREEK_LOWER);
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);
        
        list = new List(ListNumberingType.GREEK_UPPER);
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);
        
        list = new List(ListNumberingType.ROMAN_LOWER);
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);
        
        list = new List(ListNumberingType.ROMAN_UPPER);
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);
        
        list = new List(ListNumberingType.ZAPF_DINGBATS_1);
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);
        
        list = new List(ListNumberingType.ZAPF_DINGBATS_2);
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);
        
        list = new List(ListNumberingType.ZAPF_DINGBATS_3);
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);
        
        list = new List(ListNumberingType.ZAPF_DINGBATS_4);
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);
        //Close document
        document.close();
    }
}
C#
C#
using System;
using System.IO;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;

namespace iText.Highlevel.Chapter04 {
    /// <author>Bruno Lowagie (iText Software)</author>
    public class C04E07_ListTypes {
        public const String DEST = "../../../results/chapter04/list_types.pdf";

        public static void Main(String[] args) {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
            new C04E07_ListTypes().CreatePdf(DEST);
        }

        public virtual void CreatePdf(String dest) {
            //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[] { 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.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List(ListNumberingType.DECIMAL);
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List(ListNumberingType.ENGLISH_LOWER);
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List(ListNumberingType.ENGLISH_UPPER);
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List(ListNumberingType.GREEK_LOWER);
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List(ListNumberingType.GREEK_UPPER);
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List(ListNumberingType.ROMAN_LOWER);
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List(ListNumberingType.ROMAN_UPPER);
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List(ListNumberingType.ZAPF_DINGBATS_1);
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List(ListNumberingType.ZAPF_DINGBATS_2);
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List(ListNumberingType.ZAPF_DINGBATS_3);
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List(ListNumberingType.ZAPF_DINGBATS_4);
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            //Close document
            document.Close();
        }
    }
}

c04e08_customlistsymbols

JAVA
JAVA
package com.itextpdf.highlevel.chapter04;

import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.ColumnDocumentRenderer;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.element.List;
import com.itextpdf.layout.element.Text;
import com.itextpdf.layout.properties.ListNumberingType;
import com.itextpdf.layout.properties.ListSymbolAlignment;
import java.io.File;
import java.io.IOException;

/**
 * @author Bruno Lowagie (iText Software)
 */
public class C04E08_CustomListSymbols {

    public static final String DEST = "results/chapter04/custom_list_symbols.pdf";
    public static final String INFO = "src/main/resources/img/test/info.png";

    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C04E08_CustomListSymbols().createPdf(DEST);
    }

    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.setListSymbol("\u2022");
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);

        list = new List();
        PdfFont font = PdfFontFactory.createFont(StandardFonts.ZAPFDINGBATS);
        list.setListSymbol(new Text("*").setFont(font).setFontColor(ColorConstants.ORANGE));
        list.setSymbolIndent(10);
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);

        Image info = new Image(ImageDataFactory.create(INFO));
        info.scaleAbsolute(12, 12);
        list = new List().setSymbolIndent(3);
        list.setListSymbol(info);
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);

        list = new List();
        list.setListSymbol(ListNumberingType.ENGLISH_LOWER);
        list.setPostSymbolText("- ");
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);

        list = new List(ListNumberingType.DECIMAL);
        list.setPreSymbolText("Part ");
        list.setPostSymbolText(": ");
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);

        list = new List(ListNumberingType.DECIMAL);
        list.setItemStartIndex(5);
        list.add("Dr. Jekyll");
        list.add("Mr. Hyde");
        document.add(list);

        list = new List(ListNumberingType.ROMAN_LOWER);
        list.setListSymbolAlignment(ListSymbolAlignment.LEFT);
        for (int i = 0; i < 6; i++) {
            list.add("Dr. Jekyll");
            list.add("Mr. Hyde");
        }
        document.add(list);
        //Close document
        document.close();
    }
}
C#
C#
using System;
using System.IO;
using iText.IO.Font.Constants;
using iText.IO.Image;
using iText.Kernel.Colors;
using iText.Kernel.Font;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;

namespace iText.Highlevel.Chapter04 {
    /// <author>Bruno Lowagie (iText Software)</author>
    public class C04E08_CustomListSymbols {
        public const String DEST = "../../../results/chapter04/custom_list_symbols.pdf";

        public const String INFO = "../../../resources/img/test/info.png";

        public static void Main(String[] args) {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
            new C04E08_CustomListSymbols().CreatePdf(DEST);
        }

        public virtual void CreatePdf(String dest) {
            //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[] { 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.SetListSymbol("\u2022");
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List();
            PdfFont font = PdfFontFactory.CreateFont(StandardFonts.ZAPFDINGBATS);
            list.SetListSymbol(new Text("*").SetFont(font).SetFontColor(ColorConstants.ORANGE));
            list.SetSymbolIndent(10);
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            iText.Layout.Element.Image info = new Image(ImageDataFactory.Create(INFO));
            info.ScaleAbsolute(12, 12);
            list = new List().SetSymbolIndent(3);
            list.SetListSymbol(info);
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List();
            list.SetListSymbol(ListNumberingType.ENGLISH_LOWER);
            list.SetPostSymbolText("- ");
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List(ListNumberingType.DECIMAL);
            list.SetPreSymbolText("Part ");
            list.SetPostSymbolText(": ");
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List(ListNumberingType.DECIMAL);
            list.SetItemStartIndex(5);
            list.Add("Dr. Jekyll");
            list.Add("Mr. Hyde");
            document.Add(list);
            list = new List(ListNumberingType.ROMAN_LOWER);
            list.SetListSymbolAlignment(ListSymbolAlignment.LEFT);
            for (int i = 0; i < 6; i++) {
                list.Add("Dr. Jekyll");
                list.Add("Mr. Hyde");
            }
            document.Add(list);
            //Close document
            document.Close();
        }
    }
}

c04e09_listitemexample

JAVA
JAVA
package com.itextpdf.highlevel.chapter04;

import com.itextpdf.highlevel.util.CsvTo2DList;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.action.PdfAction;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.element.Link;
import com.itextpdf.layout.element.ListItem;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.properties.ListNumberingType;
import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * @author Bruno Lowagie (iText Software)
 */
public class C04E09_ListItemExample {
    
    public static final String SRC = "src/main/resources/data/jekyll_hyde.csv";
    public static final String DEST = "results/chapter04/jekyll_hyde_overviewV4.pdf";
       
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C04E09_ListItemExample().createPdf(DEST);
    }
    
    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();
    }
    
}
C#
C#
using System;
using System.Collections.Generic;
using System.IO;
using iText.Highlevel.Util;
using iText.IO.Image;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Action;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;

namespace iText.Highlevel.Chapter04 {
    /// <author>Bruno Lowagie (iText Software)</author>
    public class C04E09_ListItemExample {
        public const String SRC = "../../../resources/data/jekyll_hyde.csv";

        public const String DEST = "../../../results/chapter04/jekyll_hyde_overviewV4.pdf";

        public static void Main(String[] args) {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
            new C04E09_ListItemExample().CreatePdf(DEST);
        }

        public virtual void CreatePdf(String dest) {
            PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
            Document document = new Document(pdf);
            IList<IList<String>> resultSet = CsvTo2DList.Convert(SRC, "|");
            resultSet.RemoveAt(0);
            List list = new List(ListNumberingType.DECIMAL);
            foreach (IList<String> record in resultSet) {
                ListItem li = new ListItem();
                li.SetKeepTogether(true);
                String url = String.Format("http://www.imdb.com/title/tt{0}", record[0]);
                Link movie = new Link(record[2], PdfAction.CreateURI(url));
                li.Add(new Paragraph(movie.SetFontSize(14))).Add(new Paragraph(String.Format("Directed by {0} ({1}, {2})", record
                    [3], record[4], record[1])));
                FileInfo file = new FileInfo(String.Format("../../../resources/img/{0}.jpg", record[0]));
                if (file.Exists) {
                    iText.Layout.Element.Image img = new Image(ImageDataFactory.Create(file.FullName));
                    img.ScaleToFit(10000, 120);
                    li.Add(img);
                }
                list.Add(li);
            }
            document.Add(list);
            document.Close();
        }
    }
}

c04e10_nestedlists

JAVA
JAVA
package com.itextpdf.highlevel.chapter04;

import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.ColumnDocumentRenderer;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.List;
import com.itextpdf.layout.element.ListItem;
import com.itextpdf.layout.properties.ListNumberingType;
import java.io.File;
import java.io.IOException;

/**
 * @author Bruno Lowagie (iText Software)
 */
public class C04E10_NestedLists {
    
    public static final String DEST = "results/chapter04/nested_list.pdf";
    
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C04E10_NestedLists().createPdf(DEST);
    }
    
    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();
    }
}
C#
C#
using System;
using System.IO;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;

namespace iText.Highlevel.Chapter04 {
    /// <author>Bruno Lowagie (iText Software)</author>
    public class C04E10_NestedLists {
        public const String DEST = "../../../results/chapter04/nested_list.pdf";

        public static void Main(String[] args) {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
            new C04E10_NestedLists().CreatePdf(DEST);
        }

        public virtual void CreatePdf(String dest) {
            //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[] { 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();
        }
    }
}

Resources

jekyll_hyde.csv
0002143.jpg
0011130.jpg
0011131.jpg
0011348.jpg
0022835.jpg
0033553.jpg
0039338.jpg
0043515.jpg
0045469.jpg
0053348.jpg
0054416.jpg
0062908.jpg
0068172.jpg
0068502.jpg
0068727.jpg
0068911.jpg
0079068.jpg
0082272.jpg
0084171.jpg
0090086.jpg
0097263.jpg
0099875.jpg
0112895.jpg
0117002.jpg
0230158.jpg
0346899.jpg
0365137.jpg
0385664.jpg
0393394.jpg
0425150.jpg
0443656.jpg
0472186.jpg
0821767.jpg
1159984.jpg
2090535.jpg
3132614.jpg
3281326.jpg
4357294.jpg
5227978.jpg
jekyll_hyde.txt
info.png

Results

cmp_jekyll_hyde_overviewV1.pdf

cmp_jekyll_hyde_overviewV2.pdf

cmp_jekyll_hyde_overviewV3.pdf

cmp_jekyll_hydeV1.pdf

cmp_jekyll_hydeV2.pdf

cmp_jekyll_hydeV3.pdf

cmp_custom_paragraph.pdf

cmp_list_types.pdf

cmp_custom_list_symbols.pdf

cmp_jekyll_hyde_overviewV4.pdf

cmp_nested_list.pdf


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.