Chapter 5: examples AbstractElement (part 2)

Files: 
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.test.annotations.WrapToTest;
import java.io.File;
import java.io.IOException;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E01_MyFirstTable {
 
    public static final String DEST = "results/chapter05/my_first_table.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E01_MyFirstTable().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);
        Table table = new Table(new float[] {1, 1, 1});
        table.addCell(new Cell(1, 3).add("Cell with colspan 3"));
        table.addCell(new Cell(2, 1).add("Cell with rowspan 2"));
        table.addCell("row 1; cell 1");
        table.addCell("row 1; cell 2");
        table.addCell("row 2; cell 1");
        table.addCell("row 2; cell 2");
        document.add(table);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.test.annotations.WrapToTest;
import java.io.File;
import java.io.IOException;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E02_ColumnWidths1 {
 
    public static final String DEST = "results/chapter05/column_widths1.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E02_ColumnWidths1().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);
        Table table = new Table(new float[]{200, 100, 100});
        table.addCell(new Cell(1, 3).add("Cell with colspan 3"));
        table.addCell(new Cell(2, 1).add("Cell with rowspan 2"));
        table.addCell("row 1; cell 1");
        table.addCell("row 1; cell 2");
        table.addCell("row 2; cell 1");
        table.addCell("row 2; cell 2");
        document.add(table);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.test.annotations.WrapToTest;
import java.io.File;
import java.io.IOException;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E02_ColumnWidths2 {
 
    public static final String DEST = "results/chapter05/column_widths2.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E02_ColumnWidths2().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);
        Table table = new Table(UnitValue.createPercentArray(new float[]{1, 1, 1}));
        table.addCell(new Cell(1, 3).add("Cell with colspan 3"));
        table.addCell(new Cell(2, 1).add("Cell with rowspan 2"));
        table.addCell("row 1; cell 1");
        table.addCell("row 1; cell 2");
        table.addCell("row 2; cell 1");
        table.addCell("row 2; cell 2");
        document.add(table);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.test.annotations.WrapToTest;
import java.io.File;
import java.io.IOException;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E02_ColumnWidths3 {
 
    public static final String DEST = "results/chapter05/column_widths3.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E02_ColumnWidths3().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);
        Table table = new Table(UnitValue.createPercentArray(new float[]{2, 1, 1}));
        table.setWidth(450);
        table.setHorizontalAlignment(HorizontalAlignment.CENTER);
        table.addCell(new Cell(1, 3).add("Cell with colspan 3"));
        table.addCell(new Cell(2, 1).add("Cell with rowspan 2"));
        table.addCell("row 1; cell 1");
        table.addCell("row 1; cell 2");
        table.addCell("row 2; cell 1");
        table.addCell("row 2; cell 2");
        document.add(table);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.test.annotations.WrapToTest;
import java.io.File;
import java.io.IOException;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E02_ColumnWidths4 {
 
    public static final String DEST = "results/chapter05/column_widths4.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E02_ColumnWidths4().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);
        Table table = new Table(UnitValue.createPercentArray(new float[]{2, 1, 1}));
        table.setWidthPercent(80);
        table.setHorizontalAlignment(HorizontalAlignment.CENTER);
        table.addCell(new Cell(1, 3).add("Cell with colspan 3"));
        table.addCell(new Cell(2, 1).add("Cell with rowspan 2"));
        table.addCell("row 1; cell 1");
        table.addCell("row 1; cell 2");
        table.addCell("row 2; cell 1");
        table.addCell("row 2; cell 2");
        document.add(table);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.test.annotations.WrapToTest;
import java.io.File;
import java.io.IOException;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E02_ColumnWidths5 {
 
    public static final String DEST = "results/chapter05/column_widths5.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E02_ColumnWidths5().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);
        Table table = new Table(new float[]{2, 1, 1});
        table.setWidthPercent(80);
        table.setHorizontalAlignment(HorizontalAlignment.CENTER);
        table.addCell(new Cell(1, 3).add("Cell with colspan 3"));
        table.addCell(new Cell(2, 1).add("Cell with rowspan 2"));
        table.addCell("row 1; cell 1");
        table.addCell("row 1; cell 2");
        table.addCell("row 2; cell 1");
        table.addCell("row 2; cell 2");
        document.add(table);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.layout.property.TextAlignment;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.layout.property.VerticalAlignment;
import com.itextpdf.test.annotations.WrapToTest;
import java.io.File;
import java.io.IOException;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E03_CellAlignment {
 
    public static final String DEST = "results/chapter05/cell_alignment.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E03_CellAlignment().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);
        Table table = new Table(UnitValue.createPercentArray(new float[]{2, 1, 1}));
        table.setWidthPercent(80);
        table.setHorizontalAlignment(HorizontalAlignment.CENTER);
        table.setTextAlignment(TextAlignment.CENTER);
        table.addCell(new Cell(1, 3).add("Cell with colspan 3"));
        table.addCell(new Cell(2, 1).add("Cell with rowspan 2")
            .setTextAlignment(TextAlignment.RIGHT));
        table.addCell("row 1; cell 1");
        table.addCell("row 1; cell 2");
        table.addCell("row 2; cell 1");
        table.addCell("row 2; cell 2");
        Cell cell = new Cell()
            .add(new Paragraph("Left").setTextAlignment(TextAlignment.LEFT))
            .add(new Paragraph("Center"))
            .add(new Paragraph("Right").setTextAlignment(TextAlignment.RIGHT));
        table.addCell(cell);
        cell = new Cell().add("Middle")
            .setVerticalAlignment(VerticalAlignment.MIDDLE);
        table.addCell(cell);
        cell = new Cell().add("Bottom")
            .setVerticalAlignment(VerticalAlignment.BOTTOM);
        table.addCell(cell);
        document.add(table);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.border.DashedBorder;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.test.annotations.WrapToTest;
import java.io.File;
import java.io.IOException;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E04_ColumnHeights {
 
    public static final String DEST = "results/chapter05/column_heights.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E04_ColumnHeights().createPdf(DEST);
    }
 
    public void createPdf(String dest) throws IOException {
        //Initialize PDF document
        PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
 
        Paragraph p =
            new Paragraph("The Strange Case of\nDr. Jekyll\nand\nMr. Hyde")
            .setBorder(new DashedBorder(0.3f));
 
        // Initialize document
        Document document = new Document(pdf);
        Table table = new Table(UnitValue.createPercentArray(new float[]{1}));
        table.setWidthPercent(100);
        table.addCell(p);
        Cell cell = new Cell().setHeight(45).add(p);
        table.addCell(cell);
        cell = new Cell().setMinHeight(45).add(p);
        table.addCell(cell);
        cell = new Cell().setMinHeight(135).add(p);
        table.addCell(cell);
        cell = new Cell().setMaxHeight(45).add(p);
        table.addCell(cell);
        cell = new Cell().setMaxHeight(135).add(p);
        table.addCell(cell);
        cell = new Cell().add(p).setRotationAngle(Math.PI / 6);
        table.addCell(cell);
        document.add(table);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.kernel.color.Color;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.test.annotations.WrapToTest;
import java.io.File;
import java.io.IOException;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E05_CellPadding {
 
    public static final String DEST = "results/chapter05/cell_padding.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E05_CellPadding().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);
        Table table = new Table(UnitValue.createPercentArray(new float[]{2, 1, 1}));
        table.setBackgroundColor(Color.ORANGE);
        table.setWidthPercent(80);
        table.setHorizontalAlignment(HorizontalAlignment.CENTER);
        table.addCell(
            new Cell(1, 3).add("Cell with colspan 3")
                .setPadding(10).setBackgroundColor(Color.GREEN));
        table.addCell(new Cell(2, 1).add("Cell with rowspan 2")
            .setPaddingLeft(30)
            .setFontColor(Color.WHITE).setBackgroundColor(Color.BLUE));
        table.addCell(new Cell().add("row 1; cell 1")
            .setFontColor(Color.WHITE).setBackgroundColor(Color.RED));
        table.addCell(new Cell().add("row 1; cell 2"));
        table.addCell(new Cell().add("row 2; cell 1")
            .setFontColor(Color.WHITE).setBackgroundColor(Color.RED));
        table.addCell(new Cell().add("row 2; cell 2").setPadding(10)
            .setFontColor(Color.WHITE).setBackgroundColor(Color.RED));
        document.add(table);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.kernel.color.Color;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.layout.renderer.CellRenderer;
import com.itextpdf.layout.renderer.IRenderer;
import com.itextpdf.test.annotations.WrapToTest;
import java.io.File;
import java.io.IOException;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E05_CellPaddingMargin {
 
    public static final String DEST = "results/chapter05/cell_margin_padding.pdf";
 
    private class MarginCellRenderer extends CellRenderer {
        public MarginCellRenderer(Cell modelElement) {
            super(modelElement);
        }
 
        @Override
        public IRenderer getNextRenderer() {
        	return new MarginCellRenderer((Cell)getModelElement());
        }
 
        @Override
        protected Rectangle applyMargins(Rectangle rect, float[] margins, boolean reverse) {
            return rect.<Rectangle>applyMargins(margins[0], margins[1], margins[2], margins[3], reverse);
        }
    }
 
    private class MarginCell extends Cell {
        public MarginCell() {
            super();
        }
 
        public MarginCell(int rowspan, int colspan) {
            super(rowspan, colspan);
        }
 
        @Override
        protected IRenderer makeNewRenderer() {
            return new MarginCellRenderer(this);
        }
    }
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E05_CellPaddingMargin().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);
        Table table = new Table(UnitValue.createPercentArray(new float[]{2, 1, 1}));
        table.setBackgroundColor(Color.ORANGE);
        table.setWidthPercent(80);
        table.setHorizontalAlignment(HorizontalAlignment.CENTER);
        table.addCell(
            new MarginCell(1, 3).add("Cell with colspan 3")
                .setPadding(10).setMargin(5).setBackgroundColor(Color.GREEN));
        table.addCell(new MarginCell(2, 1).add("Cell with rowspan 2")
            .setMarginTop(5).setMarginBottom(5).setPaddingLeft(30)
            .setFontColor(Color.WHITE).setBackgroundColor(Color.BLUE));
        table.addCell(new MarginCell().add("row 1; cell 1")
            .setFontColor(Color.WHITE).setBackgroundColor(Color.RED));
        table.addCell(new MarginCell().add("row 1; cell 2"));
        table.addCell(new MarginCell().add("row 2; cell 1").setMargin(10)
            .setFontColor(Color.WHITE).setBackgroundColor(Color.RED));
        table.addCell(new MarginCell().add("row 2; cell 2").setPadding(10)
            .setFontColor(Color.WHITE).setBackgroundColor(Color.RED));
        document.add(table);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import java.io.File;
import java.io.IOException;
 
import com.itextpdf.kernel.color.Color;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.border.DashedBorder;
import com.itextpdf.layout.border.DottedBorder;
import com.itextpdf.layout.border.SolidBorder;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.layout.property.TextAlignment;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.layout.property.VerticalAlignment;
import com.itextpdf.test.annotations.WrapToTest;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E06_CellBorders1 {
 
    public static final String DEST = "results/chapter05/cell_borders1.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E06_CellBorders1().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);
 
        Table table = new Table(UnitValue.createPercentArray(new float[]{2, 1, 1}));
        table.setWidthPercent(80)
            .setHorizontalAlignment(HorizontalAlignment.CENTER)
            .setTextAlignment(TextAlignment.CENTER);
        table.addCell(new Cell(1, 3)
            .add("Cell with colspan 3")
            .setVerticalAlignment(VerticalAlignment.MIDDLE)
            .setBorder(new DashedBorder(0.5f)));
        table.addCell(new Cell(2, 1)
            .add("Cell with rowspan 2")
            .setVerticalAlignment(VerticalAlignment.MIDDLE)
            .setBorderBottom(new DottedBorder(0.5f))
            .setBorderLeft(new DottedBorder(0.5f)));
        table.addCell(new Cell()
            .add("row 1; cell 1")
            .setBorder(new DottedBorder(Color.ORANGE, 0.5f)));
        table.addCell(new Cell()
            .add("row 1; cell 2"));
        table.addCell(new Cell()
            .add("row 2; cell 1")
            .setBorderBottom(new SolidBorder(2)));
        table.addCell(new Cell()
            .add("row 2; cell 2")
            .setBorderBottom(new SolidBorder(2)));
        document.add(table);
 
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import java.io.File;
import java.io.IOException;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.border.Border;
import com.itextpdf.layout.border.SolidBorder;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.layout.property.TextAlignment;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.layout.property.VerticalAlignment;
import com.itextpdf.test.annotations.WrapToTest;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E06_CellBorders2 {
 
    public static final String DEST = "results/chapter05/cell_borders2.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E06_CellBorders2().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);
 
        Table table = new Table(UnitValue.createPercentArray(new float[]{2, 1, 1}));
        table.setBorder(new SolidBorder(3))
            .setWidthPercent(80)
            .setHorizontalAlignment(HorizontalAlignment.CENTER)
            .setTextAlignment(TextAlignment.CENTER);
        table.addCell(new Cell(1, 3)
            .add("Cell with colspan 3")
            .setVerticalAlignment(VerticalAlignment.MIDDLE)
            .setBorder(Border.NO_BORDER));
        table.addCell(new Cell(2, 1)
            .add("Cell with rowspan 2")
            .setVerticalAlignment(VerticalAlignment.MIDDLE)
            .setBorder(Border.NO_BORDER));
        table.addCell(new Cell().add("row 1; cell 1"));
        table.addCell(new Cell().add("row 1; cell 2"));
        table.addCell(new Cell().add("row 2; cell 1"));
        table.addCell(new Cell().add("row 2; cell 2"));
        document.add(table);
 
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import java.io.File;
import java.io.IOException;
 
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.border.Border;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.layout.property.TextAlignment;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.layout.property.VerticalAlignment;
import com.itextpdf.layout.renderer.CellRenderer;
import com.itextpdf.layout.renderer.DrawContext;
import com.itextpdf.layout.renderer.IRenderer;
import com.itextpdf.test.annotations.WrapToTest;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E06_CellBorders3 {
 
    private class RoundedCornersCellRenderer extends CellRenderer {
        public RoundedCornersCellRenderer(Cell modelElement) {
            super(modelElement);
        }
 
        @Override
        public void drawBorder(DrawContext drawContext) {
            Rectangle occupiedAreaBBox = getOccupiedAreaBBox();
            float[] margins = getMargins();
            Rectangle rectangle = applyMargins(occupiedAreaBBox, margins, false);
            PdfCanvas canvas = drawContext.getCanvas();
            canvas.roundRectangle(rectangle.getX(), rectangle.getY(),
                rectangle.getWidth(), rectangle.getHeight(), 5).stroke();
            super.drawBorder(drawContext);
        }
 
        @Override
        public IRenderer getNextRenderer() {
            return new RoundedCornersCellRenderer((Cell)getModelElement());
        }
 
        @Override
        protected Rectangle applyMargins(Rectangle rect, float[] margins, boolean reverse) {
            return rect.<Rectangle>applyMargins(margins[0], margins[1], margins[2], margins[3], reverse);
        }
    }
 
    private class RoundedCornersCell extends Cell {
        public RoundedCornersCell() {
            super();
            setBorder(Border.NO_BORDER);
            setMargin(2);
        }
 
        public RoundedCornersCell(int rowspan, int colspan) {
            super(rowspan, colspan);
            setBorder(Border.NO_BORDER);
            setVerticalAlignment(VerticalAlignment.MIDDLE);
            setMargin(5);
        }
 
        @Override
        protected IRenderer makeNewRenderer() {
            return new RoundedCornersCellRenderer(this);
        }
    }
 
    public static final String DEST = "results/chapter05/cell_borders3.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E06_CellBorders3().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);
 
        Table table = new Table(UnitValue.createPercentArray(new float[]{2, 1, 1}));
        table.setWidthPercent(80)
            .setHorizontalAlignment(HorizontalAlignment.CENTER)
            .setTextAlignment(TextAlignment.CENTER);
        Cell cell = new RoundedCornersCell(1, 3)
            .add("Cell with colspan 3");
        table.addCell(cell);
        cell = new RoundedCornersCell(2, 1)
            .add("Cell with rowspan 2");
        table.addCell(cell);
        cell = new RoundedCornersCell()
            .add("row 1; cell 1");
        table.addCell(cell);
        cell = new RoundedCornersCell()
            .add("row 1; cell 2");
        table.addCell(cell);
        cell = new RoundedCornersCell()
            .add("row 2; cell 1");
        table.addCell(cell);
        cell = new RoundedCornersCell()
            .add("row 2; cell 2");
        table.addCell(cell);
        document.add(table);
 
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import java.io.File;
import java.io.IOException;
 
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.layout.property.TextAlignment;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.layout.renderer.CellRenderer;
import com.itextpdf.layout.renderer.DrawContext;
import com.itextpdf.layout.renderer.IRenderer;
import com.itextpdf.layout.renderer.TableRenderer;
import com.itextpdf.test.annotations.WrapToTest;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E06_CellBorders4 {
 
    private class RoundedCornersTableRenderer extends TableRenderer {
 
        public RoundedCornersTableRenderer(Table modelElement) {
            super(modelElement);
        }
 
        @Override
        public IRenderer getNextRenderer() {
            return new RoundedCornersTableRenderer((Table)getModelElement());
        }
 
        @Override
        protected void drawBorders(DrawContext drawContext) {
            Rectangle occupiedAreaBBox = getOccupiedAreaBBox();
            float[] margins = getMargins();
            Rectangle rectangle = applyMargins(occupiedAreaBBox, margins, false);
            PdfCanvas canvas = drawContext.getCanvas();
            canvas.roundRectangle(rectangle.getX() + 1, rectangle.getY() + 1,
                    rectangle.getWidth() - 2, rectangle.getHeight() -2, 5).stroke();
            super.drawBorder(drawContext);
        }
 
    }
 
    private class RoundedCornersCellRenderer extends CellRenderer {
        public RoundedCornersCellRenderer(Cell modelElement) {
            super(modelElement);
        }
 
        @Override
        public void drawBorder(DrawContext drawContext) {
            Rectangle occupiedAreaBBox = getOccupiedAreaBBox();
            float[] margins = getMargins();
            Rectangle rectangle = applyMargins(occupiedAreaBBox, margins, false);
            PdfCanvas canvas = drawContext.getCanvas();
            canvas.roundRectangle(rectangle.getX() + 1, rectangle.getY() + 1,
                    rectangle.getWidth() - 2, rectangle.getHeight() -2, 5).stroke();
            super.drawBorder(drawContext);
        }
 
        @Override
        public IRenderer getNextRenderer() {
            return new RoundedCornersCellRenderer((Cell)getModelElement());
        }
 
        @Override
        protected Rectangle applyMargins(Rectangle rect, float[] margins, boolean reverse) {
            return rect.<Rectangle>applyMargins(margins[0], margins[1], margins[2], margins[3], reverse);
        }
    }
 
    private class RoundedCornersCell extends Cell {
        public RoundedCornersCell() {
            super();
            setMargin(2);
        }
 
        public RoundedCornersCell(int rowspan, int colspan) {
            super(rowspan, colspan);
            setMargin(2);
        }
 
        @Override
        protected IRenderer makeNewRenderer() {
            return new RoundedCornersCellRenderer(this);
        }
    }
 
    public static final String DEST = "results/chapter05/cell_borders4.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E06_CellBorders4().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);
 
        Table table = new Table(UnitValue.createPercentArray(new float[]{2, 1, 1}))
            .setWidthPercent(80)
            .setHorizontalAlignment(HorizontalAlignment.CENTER)
            .setTextAlignment(TextAlignment.CENTER);
        Cell cell = new RoundedCornersCell(1, 3)
            .add("Cell with colspan 3");
        table.addCell(cell);
        cell = new RoundedCornersCell(2, 1)
            .add("Cell with rowspan 2");
        table.addCell(cell);
        cell = new RoundedCornersCell()
            .add("row 1; cell 1");
        table.addCell(cell);
        cell = new RoundedCornersCell()
            .add("row 1; cell 2");
        table.addCell(cell);
        cell = new RoundedCornersCell()
            .add("row 2; cell 1");
        table.addCell(cell);
        cell = new RoundedCornersCell()
            .add("row 2; cell 2");
        table.addCell(cell);
        table.setNextRenderer(new RoundedCornersTableRenderer(table));
        document.add(table);
 
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.test.annotations.WrapToTest;
import java.io.File;
import java.io.IOException;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E07_NestedTable {
 
    public static final String DEST = "results/chapter05/nested_tables.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E07_NestedTable().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);
        Table table = new Table(new float[]{1, 1})
            .setWidthPercent(80)
            .setHorizontalAlignment(HorizontalAlignment.CENTER);
        table.addCell(new Cell(1, 2).add("Cell with colspan 2"));
        table.addCell(new Cell().add("Cell with rowspan 1"));
        Table inner = new Table(new float[]{1, 1});
        inner.addCell("row 1; cell 1");
        inner.addCell("row 1; cell 2");
        inner.addCell("row 2; cell 1");
        inner.addCell("row 2; cell 2");
        table.addCell(inner);
        document.add(table);
 
        table = new Table(new float[]{1, 1})
            .setMarginTop(10)
            .setWidthPercent(80)
            .setHorizontalAlignment(HorizontalAlignment.CENTER);
        table.addCell(new Cell(1, 2).add("Cell with colspan 2"));
        table.addCell(new Cell().add("Cell with rowspan 1"));
        inner = new Table(new float[]{1, 1});
        inner.addCell("row 1; cell 1");
        inner.addCell("row 1; cell 2");
        inner.addCell("row 2; cell 1");
        inner.addCell("row 2; cell 2");
        table.addCell(new Cell().add(inner).setPadding(0));
        document.add(table);
 
        table = new Table(new float[]{1, 1})
            .setMarginTop(10)
            .setWidthPercent(80)
            .setHorizontalAlignment(HorizontalAlignment.CENTER);
        table.addCell(new Cell(1, 2).add("Cell with colspan 2"));
        table.addCell(new Cell().add("Cell with rowspan 1"));
        inner = new Table(new float[]{1, 1})
            .setWidthPercent(100);
        inner.addCell("row 1; cell 1");
        inner.addCell("row 1; cell 2");
        inner.addCell("row 2; cell 1");
        inner.addCell("row 2; cell 2");
        table.addCell(new Cell().add(inner).setPadding(0));
        document.add(table);
 
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.highlevel.util.CsvTo2DList;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.test.annotations.WrapToTest;
 
import java.io.File;
import java.io.IOException;
import java.util.List;
 
/**
 * @author iText
 */
@WrapToTest
public class C05E08_JekyllHydeTableV1 {
 
    public static final String SRC = "src/main/resources/data/jekyll_hyde.csv";
    public static final String DEST = "results/chapter05/jekyll_hyde_table1.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E08_JekyllHydeTableV1().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, PageSize.A4.rotate());
        Table table = new Table(UnitValue.createPercentArray(new float[]{3, 2, 14, 9, 4, 3}))
                .useAllAvailableWidth();
        List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
        List<String> header = resultSet.remove(0);
        for (String field : header) {
            table.addHeaderCell(field);
        }
        Cell cell = new Cell(1, 6).add("Continued on next page...");
        table.addFooterCell(cell)
            .setSkipLastFooter(true);
        for (List<String> record : resultSet) {
            for (String field : record) {
                table.addCell(field);
            }
        }
        document.add(table);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.highlevel.util.CsvTo2DList;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.test.annotations.WrapToTest;
 
import java.io.File;
import java.io.IOException;
import java.util.List;
 
/**
 * @author iText
 */
@WrapToTest
public class C05E09_JekyllHydeTableV2 {
 
    public static final String SRC = "src/main/resources/data/jekyll_hyde.csv";
    public static final String DEST = "results/chapter05/jekyll_hyde_table2.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E09_JekyllHydeTableV2().createPdf(DEST);
    }
 
    public void createPdf(String dest) throws IOException {
        PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
        Document document = new Document(pdf, PageSize.A4.rotate());
        Table table = new Table(UnitValue.createPercentArray(new float[]{3, 2, 14, 9, 4, 3})).useAllAvailableWidth();
        List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
        List<String> header = resultSet.remove(0);
        for (String field : header) {
            table.addHeaderCell(field);
        }
        for (List<String> record : resultSet) {
            for (String field : record) {
                table.addCell(field);
            }
        }
        Table outerTable = new Table(new float[]{1})
            .addHeaderCell("Continued from previous page:")
            .setSkipFirstHeader(true)
            .addCell(new Cell().add(table).setPadding(0));
        document.add(outerTable);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.highlevel.util.CsvTo2DList;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.test.annotations.WrapToTest;
 
import java.io.File;
import java.io.IOException;
import java.util.List;
 
/**
 * @author iText
 */
@WrapToTest
public class C05E10_JekyllHydeTableV3 {
 
    public static final String SRC = "src/main/resources/data/jekyll_hyde.csv";
    public static final String DEST = "results/chapter05/jekyll_hyde_table3.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E10_JekyllHydeTableV3().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, PageSize.A4.rotate());
        Table table = new Table(UnitValue.createPercentArray(new float[]{3, 2, 14, 9, 4, 3}));
        List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
        List<String> header = resultSet.remove(0);
        for (String field : header) {
            table.addHeaderCell(field);
        }
        Cell cell;
        for (List<String> record : resultSet) {
            cell = new Cell();
            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.setAutoScaleWidth(true);
                img.setWidthPercent(100);
                cell.add(img);
            }
            else {
                cell.add(record.get(0));
            }
            table.addCell(cell);
            table.addCell(record.get(1));
            table.addCell(record.get(2));
            table.addCell(record.get(3));
            table.addCell(record.get(4));
            table.addCell(record.get(5));
        }
        document.add(table);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.highlevel.util.CsvTo2DList;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.test.annotations.WrapToTest;
 
import java.io.File;
import java.io.IOException;
import java.util.List;
 
/**
 * @author iText
 */
@WrapToTest
public class C05E11_JekyllHydeTableV4 {
 
    public static final String SRC = "src/main/resources/data/jekyll_hyde.csv";
    public static final String DEST = "results/chapter05/jekyll_hyde_table4.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E11_JekyllHydeTableV4().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, PageSize.A4.rotate());
        Table table = new Table(UnitValue.createPercentArray(new float[]{3, 32})).useAllAvailableWidth();
        List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
        resultSet.remove(0);
        table.addHeaderCell("imdb")
            .addHeaderCell("Information about the movie");
        Cell cell;
        for (List<String> record : resultSet) {
            table.addCell(record.get(0));
            cell = new Cell()
                .add(new Paragraph(record.get(1)))
                .add(new Paragraph(record.get(2)))
                .add(new Paragraph(record.get(3)))
                .add(new Paragraph(record.get(4)))
                .add(new Paragraph(record.get(5)));
            table.addCell(cell);
        }
        document.add(table);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.highlevel.util.CsvTo2DList;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.test.annotations.WrapToTest;
 
import java.io.File;
import java.io.IOException;
import java.util.List;
 
/**
 * @author iText
 */
@WrapToTest
public class C05E12_JekyllHydeTableV5 {
 
    public static final String SRC = "src/main/resources/data/jekyll_hyde.csv";
    public static final String DEST = "results/chapter05/jekyll_hyde_table5.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E12_JekyllHydeTableV5().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, PageSize.A4.rotate());
        Table table = new Table(UnitValue.createPercentArray(new float[]{3, 32})).useAllAvailableWidth();
        List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
        resultSet.remove(0);
        table.addHeaderCell("imdb")
            .addHeaderCell("Information about the movie");
        Cell cell;
        for (List<String> record : resultSet) {
            table.addCell(record.get(0));
            cell = new Cell()
                .add(new Paragraph(record.get(1)))
                .add(new Paragraph(record.get(2)))
                .add(new Paragraph(record.get(3)))
                .add(new Paragraph(record.get(4)))
                .add(new Paragraph(record.get(5)));
            cell.setKeepTogether(true);
            table.addCell(cell);
        }
        document.add(table);
        document.close();
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.highlevel.util.CsvTo2DList;
import com.itextpdf.kernel.color.Color;
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.kernel.pdf.canvas.PdfCanvas;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.layout.renderer.CellRenderer;
import com.itextpdf.layout.renderer.DrawContext;
import com.itextpdf.layout.renderer.TableRenderer;
import com.itextpdf.test.annotations.WrapToTest;
 
import java.io.File;
import java.io.IOException;
import java.util.List;
 
/**
 * @author iText
 */
@WrapToTest
public class C05E13_JekyllHydeTableV6 {
 
    public static final String SRC = "src/main/resources/data/jekyll_hyde.csv";
    public static final String DEST = "results/chapter05/jekyll_hyde_table6"
            + ".pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E13_JekyllHydeTableV6().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, PageSize.A4.rotate());
        List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
        List<String> header = resultSet.remove(0);
        Table table = new Table(UnitValue.createPercentArray(new float[]{3, 2, 14, 9, 4, 3}));
        int nRows = resultSet.size();
        table.setNextRenderer(new AlternatingBackgroundTableRenderer(
            table, new Table.RowRange(0, nRows - 1)));
        table.setWidthPercent(100);
        for (String field : header) {
            table.addHeaderCell(field);
        }
        for (List<String> record : resultSet) {
            for (String field : record) {
                table.addCell(field);
            }
        }
        document.add(table);
        document.close();
    }
}
 
class AlternatingBackgroundTableRenderer extends TableRenderer {
    private boolean isOdd = true;
 
    public AlternatingBackgroundTableRenderer(Table modelElement, Table.RowRange rowRange) {
        super(modelElement, rowRange);
    }
 
    public AlternatingBackgroundTableRenderer(Table modelElement) {
        super(modelElement);
    }
 
    @Override
    public AlternatingBackgroundTableRenderer getNextRenderer() {
        return new AlternatingBackgroundTableRenderer((Table) modelElement);
    }
 
    @Override
    public void draw(DrawContext drawContext) {
        for (int i = 0; i < rows.size() && null != rows.get(i) && null != rows.get(i)[0]; i++) {
            CellRenderer[] renderers = rows.get(i);
            Rectangle leftCell =
                renderers[0].getOccupiedAreaBBox();
            Rectangle rightCell =
                renderers[renderers.length - 1].getOccupiedAreaBBox();
            Rectangle rect = new Rectangle(
                leftCell.getLeft(), leftCell.getBottom(),
                rightCell.getRight() - leftCell.getLeft(),
                leftCell.getHeight());
            PdfCanvas canvas = drawContext.getCanvas();
            canvas.saveState();
            if (isOdd) {
                canvas.setFillColor(Color.LIGHT_GRAY);
                isOdd = false;
            } else {
                canvas.setFillColor(Color.YELLOW);
                isOdd = true;
            }
            canvas.rectangle(rect);
            canvas.fill();
            canvas.restoreState();
        }
        super.draw(drawContext);
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.highlevel.util.CsvTo2DList;
import com.itextpdf.kernel.color.Color;
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.kernel.pdf.canvas.PdfCanvas;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.layout.renderer.CellRenderer;
import com.itextpdf.layout.renderer.DrawContext;
import com.itextpdf.test.annotations.WrapToTest;
 
import java.io.File;
import java.io.IOException;
import java.util.List;
 
/**
 * @author iText
 */
@WrapToTest
public class C05E14_JekyllHydeTableV7 {
 
    public static final String SRC = "src/main/resources/data/jekyll_hyde.csv";
    public static final String DEST = "results/chapter05/jekyll_hyde_table7.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E14_JekyllHydeTableV7().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, PageSize.A4.rotate());
        Table table = new Table(UnitValue.createPercentArray(new float[]{3, 2, 14, 9, 4, 3})).useAllAvailableWidth();
        List<List<String>> resultSet = CsvTo2DList.convert(SRC, "|");
        List<String> header = resultSet.remove(0);
        for (String field : header) {
            table.addHeaderCell(field);
        }
        for (List<String> record : resultSet) {
            table.addCell(record.get(0));
            table.addCell(record.get(1));
            Cell cell = new Cell().add(record.get(2));
            cell.setNextRenderer(new RunlengthRenderer(cell, record.get(5)));
            table.addCell(cell);
            table.addCell(record.get(3));
            table.addCell(record.get(4));
            table.addCell(record.get(5));
        }
        document.add(table);
        document.close();
    }
 
    private class RunlengthRenderer extends CellRenderer {
        private int runlength;
 
        public RunlengthRenderer(Cell modelElement, String duration) {
            super(modelElement);
            if (duration.trim().isEmpty()) runlength = 0;
            else runlength = Integer.parseInt(duration);
        }
 
        @Override
        public CellRenderer getNextRenderer() {
            return new RunlengthRenderer(getModelElement(), String.valueOf(runlength));
        }
 
        @Override
        public void drawBackground(DrawContext drawContext) {
            if (runlength == 0) return;
            PdfCanvas canvas = drawContext.getCanvas();
            canvas.saveState();
            if (runlength < 90) {
                canvas.setFillColor(Color.GREEN);
            } else if (runlength > 240) {
                runlength = 240;
                canvas.setFillColor(Color.RED);
            } else {
                canvas.setFillColor(Color.ORANGE);
            }
            Rectangle rect = getOccupiedAreaBBox();
            canvas.rectangle(rect.getLeft(), rect.getBottom(),
                    rect.getWidth() * runlength / 240, rect.getHeight());
            canvas.fill();
            canvas.restoreState();
            super.drawBackground(drawContext);
        }
    }
}
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
/*
 * This example was written by Bruno Lowagie
 * in the context of the book: iText 7 building blocks
 */
package com.itextpdf.highlevel.chapter05;
 
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Table;
import com.itextpdf.test.annotations.WrapToTest;
import java.io.File;
import java.io.IOException;
 
/**
 * @author Bruno Lowagie (iText Software)
 */
@WrapToTest
public class C05E15_LargeTable {
 
    public static final String DEST = "results/chapter05/large_table.pdf";
 
    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C05E15_LargeTable().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);
        Table table = new Table(new float[]{100, 100, 100}, true);
        table.addHeaderCell("Table header 1");
        table.addHeaderCell("Table header 2");
        table.addHeaderCell("Table header 3");
        table.addFooterCell("Table footer 1");
        table.addFooterCell("Table footer 2");
        table.addFooterCell("Table footer 3");
        document.add(table);
        for (int i = 0; i < 1000; i++) {
            table.addCell(String.format("Row %s; column 1", i + 1));
            table.addCell(String.format("Row %s; column 2", i + 1));
            table.addCell(String.format("Row %s; column 3", i + 1));
            if (i %50 == 0) {
                table.flush();
            }
        }
        table.complete();
        document.close();
    }
}
File nameRaw URLUpdated
C05E01_MyFirstTable.javaC05E01_MyFirstTable.java2017-09-12 12:15 pm
C05E02_ColumnWidths1.javaC05E02_ColumnWidths1.java2017-09-12 12:15 pm
C05E02_ColumnWidths2.javaC05E02_ColumnWidths2.java2017-09-12 12:15 pm
C05E02_ColumnWidths3.javaC05E02_ColumnWidths3.java2017-09-12 12:15 pm
C05E02_ColumnWidths4.javaC05E02_ColumnWidths4.java2017-09-12 12:15 pm
C05E02_ColumnWidths5.javaC05E02_ColumnWidths5.java2017-09-12 12:15 pm
C05E03_CellAlignment.javaC05E03_CellAlignment.java2017-09-12 2:03 pm
C05E04_ColumnHeights.javaC05E04_ColumnHeights.java2017-09-12 2:03 pm
C05E05_CellPadding.javaC05E05_CellPadding.java2017-09-13 3:26 pm
C05E05_CellPaddingMargin.javaC05E05_CellPaddingMargin.java2017-09-13 3:26 pm
C05E06_CellBorders1.javaC05E06_CellBorders1.java2017-09-13 3:26 pm
C05E06_CellBorders2.javaC05E06_CellBorders2.java2017-09-13 3:26 pm
C05E06_CellBorders3.javaC05E06_CellBorders3.java2017-09-13 3:26 pm
C05E06_CellBorders4.javaC05E06_CellBorders4.java2017-09-13 3:26 pm
C05E07_NestedTable.javaC05E07_NestedTable.java2017-09-12 2:03 pm
C05E08_JekyllHydeTableV1.javaC05E08_JekyllHydeTableV1.java2017-09-12 2:03 pm
C05E09_JekyllHydeTableV2.javaC05E09_JekyllHydeTableV2.java2017-09-12 2:03 pm
C05E10_JekyllHydeTableV3.javaC05E10_JekyllHydeTableV3.java2017-09-12 2:03 pm
C05E11_JekyllHydeTableV4.javaC05E11_JekyllHydeTableV4.java2017-09-12 2:03 pm
C05E12_JekyllHydeTableV5.javaC05E12_JekyllHydeTableV5.java2017-09-12 2:03 pm
C05E13_JekyllHydeTableV6.javaC05E13_JekyllHydeTableV6.java2017-09-12 2:03 pm
C05E14_JekyllHydeTableV7.javaC05E14_JekyllHydeTableV7.java2017-09-12 2:03 pm
C05E15_LargeTable.javaC05E15_LargeTable.java2017-09-12 2:03 pm
Resources: 
File nameRaw URLUpdated
jekyll_hyde.csvjekyll_hyde.csv2016-06-20 6:51 pm
0002143.jpg0002143.jpg2016-07-02 5:07 pm
0011130.jpg0011130.jpg2016-07-02 5:07 pm
0011131.jpg0011131.jpg2016-07-02 5:07 pm
0011348.jpg0011348.jpg2016-07-02 5:07 pm
0022835.jpg0022835.jpg2016-07-02 5:07 pm
0033553.jpg0033553.jpg2016-07-02 5:07 pm
0039338.jpg0039338.jpg2016-07-02 5:07 pm
0043515.jpg0043515.jpg2016-07-02 5:07 pm
0045469.jpg0045469.jpg2016-07-02 5:07 pm
0053348.jpg0053348.jpg2016-07-02 5:07 pm
0054416.jpg0054416.jpg2016-07-02 5:07 pm
0062908.jpg0062908.jpg2016-07-02 5:07 pm
0068172.jpg0068172.jpg2016-07-02 5:07 pm
0068502.jpg0068502.jpg2016-07-02 5:07 pm
0068727.jpg0068727.jpg2016-07-02 5:07 pm
0068911.jpg0068911.jpg2016-07-02 5:07 pm
0079068.jpg0079068.jpg2016-07-02 5:07 pm
0082272.jpg0082272.jpg2016-07-02 5:07 pm
0084171.jpg0084171.jpg2016-07-02 5:07 pm
0090086.jpg0090086.jpg2016-07-02 5:07 pm
0097263.jpg0097263.jpg2016-07-02 5:07 pm
0099875.jpg0099875.jpg2016-07-02 5:07 pm
0112895.jpg0112895.jpg2016-07-02 5:07 pm
0117002.jpg0117002.jpg2016-06-25 4:38 pm
0230158.jpg0230158.jpg2016-07-02 5:07 pm
0346899.jpg0346899.jpg2016-07-02 5:07 pm
0365137.jpg0365137.jpg2016-07-02 5:07 pm
0385664.jpg0385664.jpg2016-07-02 5:07 pm
0393394.jpg0393394.jpg2016-07-02 5:07 pm
0425150.jpg0425150.jpg2016-07-02 5:07 pm
0443656.jpg0443656.jpg2016-07-02 5:07 pm
0472186.jpg0472186.jpg2016-07-02 5:07 pm
0821767.jpg0821767.jpg2016-07-02 5:07 pm
1159984.jpg1159984.jpg2016-07-02 5:07 pm
2090535.jpg2090535.jpg2016-07-02 5:07 pm
3132614.jpg3132614.jpg2016-07-02 5:07 pm
3281326.jpg3281326.jpg2016-07-02 5:07 pm
4357294.jpg4357294.jpg2016-07-02 5:07 pm
5227978.jpg5227978.jpg2016-07-02 5:07 pm