Example usage for com.lowagie.text Chunk Chunk

List of usage examples for com.lowagie.text Chunk Chunk

Introduction

In this page you can find the example usage for com.lowagie.text Chunk Chunk.

Prototype

public Chunk(DrawInterface separator, float tabPosition, boolean newline) 

Source Link

Document

Creates a tab Chunk.

Usage

From source file:questions.separators.TOCExample.java

public static void main(String[] args) {
    Document document = new Document();
    try {/* ww  w .  j  a  v a 2 s  . c om*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();

        Chunk tab0 = new Chunk(new VerticalPositionMark(), 0, true);
        Chunk tab1 = new Chunk(new LineSeparator(), 40, true);
        Chunk tab2 = new Chunk(new DottedLineSeparator(), 120, true);

        Paragraph p1 = new Paragraph();
        p1.add(new Chunk("1"));
        p1.add(tab1);
        p1.add(new Chunk("Chapter 1"));
        p1.add(tab2);
        p1.add(new Chunk("p1"));
        Paragraph p2 = new Paragraph();
        p2.add(tab1);
        p2.add(new Chunk("Introduction"));
        p2.add(tab2);
        p2.add(new Chunk("p2"));
        Paragraph p3 = new Paragraph();
        p3.add(tab1);
        p3.add(new Chunk("Let us test the tab functionality in iText with a long line"));
        p3.add(tab2);
        p3.add(new Chunk("p3"));
        Paragraph p4 = new Paragraph();
        p4.add(tab1);
        p4.add(new Chunk("test"));
        p4.add(tab2);
        Paragraph p5 = new Paragraph();
        p5.add(new Chunk("2"));
        p5.add(tab1);
        p5.add(tab2);
        Paragraph p6 = new Paragraph();
        p6.add(tab1);
        p6.add(tab2);
        p6.add(new Chunk("p4"));
        Paragraph p7 = new Paragraph();
        p7.add(tab1);
        p7.add(tab2);
        Paragraph p8 = new Paragraph();
        p8.add(new Chunk("3"));
        p8.add(tab1);
        p8.add(new Chunk("Chapter 3"));
        p8.add(tab2);
        p8.add(new Chunk("p5"));
        p8.add(tab0);
        p8.add(new Chunk("4"));
        p8.add(tab1);
        p8.add(new Chunk("Chapter 4 - the final chapter"));
        p8.add(tab2);
        p8.add(new Chunk("p6"));

        document.add(p1);
        document.add(p2);
        document.add(p3);
        document.add(p4);
        document.add(p5);
        document.add(p6);
        document.add(p7);
        document.add(p8);

        PdfContentByte canvas = writer.getDirectContent();
        ColumnText column = new ColumnText(canvas);
        column.addElement(p1);
        column.addElement(p2);
        column.addElement(p3);
        column.addElement(p4);
        column.addElement(p5);
        column.addElement(p6);
        column.addElement(p7);
        column.addElement(p8);
        column.setSimpleColumn(36, 500, 200, 600);
        column.go();
        column.setSimpleColumn(260, 500, 460, 600);
        column.go();

        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:view.ViewCodigobarras.java

public void gerarCodigoBarras(ArrayList<String> pListaCodigos) {

    System.out.println("Barcode Linha de Cdigo ");

    // criando um objeto da classe Document
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    try {/*from w  ww. ja  v a2s .c  o m*/

        //Aqui comeamos a utilizar as classes do iText: o documento
        //criado acima ser
        //direcionado para um arquivo PDF.
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("C://Codigo_Barra_Java_Linha_Codigo.pdf"));

        //abrindo o documento.
        document.open();

        //adicionando um novo paragrafo.
        for (int i = 0; i < pListaCodigos.size(); i++) {
            document.add(new Paragraph("CDIGOS DE BARRA"));

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

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

            //Comecando a configurar o cod de barras
            PdfContentByte cb = writer.getDirectContent();

            BarcodeEAN codeEAN = new BarcodeEAN();

            //O iText suporta os principais tipos de cdigo de barra, como Barcode39,
            //  Barcode128 (128, 128_UCC, 128_RAW),  BarcodeEAN (EAN13, EAN8, UPCA, UPCE), EANSUP, etc
            if (jcbTipoCodigo.getSelectedItem().toString() == "EAN13") {
                codeEAN.setCodeType(codeEAN.EAN13);
            } else if ("EAN8".equals(jcbTipoCodigo.getSelectedItem().toString())) {
                codeEAN.setCodeType(codeEAN.EAN8);
            } else if ("UPCA".equals(jcbTipoCodigo.getSelectedItem().toString())) {
                codeEAN.setCodeType(codeEAN.UPCA);
            } else if ("UPCE".equals(jcbTipoCodigo.getSelectedItem().toString())) {
                codeEAN.setCodeType(codeEAN.UPCE);
            }

            codeEAN.setCode("1234567890123");

            Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);

            document.add(new Phrase(new Chunk(imageEAN, 0, 0)));
        }
        //abrir o arquivo
        File file = new File("C://Codigo_Barra_Java_Linha_Codigo.pdf");
        try {
            Desktop.getDesktop().open(file);
        } catch (Exception e) {
            JOptionPane.showConfirmDialog(null, e);
        }
        file.deleteOnExit();

    } catch (Exception de) {
        de.printStackTrace();

    }
    document.close();

}