ChunkWidthPDF.java Source code

Java tutorial

Introduction

Here is the source code for ChunkWidthPDF.java

Source

import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class ChunkWidthPDF {
    public static void main(String[] args) {
        Document document = new Document();
        try {
            PdfWriter.getInstance(document, new FileOutputStream("ChunkWidthPDF.pdf"));
            document.open();

            Chunk c = new Chunk("Text Text Text Text Text Text Text Text Text Text");
            float w = c.getWidthPoint();
            System.out.println(
                    "The width of the chunk: is " + String.valueOf(w) + " points or " + w / 72f + " inches.");
            document.add(c);
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
        document.close();
    }
}