Example usage for com.itextpdf.text Chunk setCharacterSpacing

List of usage examples for com.itextpdf.text Chunk setCharacterSpacing

Introduction

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

Prototype

public Chunk setCharacterSpacing(final float charSpace) 

Source Link

Document

Sets the character spacing.

Usage

From source file:util.ImageExample.java

public ImageExample(Calendar date, int settings, ArrayList<String> courses, String time, String eventAddress,
        int totalPrice, String comments, boolean kunde) throws Exception {
    this.date = date;
    this.settings = settings;
    this.courses = courses;
    this.time = time;
    this.eventAddress = eventAddress;
    this.totalPrice = totalPrice;
    this.comments = comments;
    this.fileName = "";
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    ge.getAllFonts();//from  w  ww .  j  av a  2  s  .  c o  m
    FontFactory.register("C:/Windows/Fonts/ARLRDBD.TTF", "Arial Rounded");
    Font font = FontFactory.getFont("Arial Rounded", 22, Font.NORMAL, new BaseColor(51, 102, 102));
    Document document = new Document();

    System.out.println("Pdf creation startet");
    try {
        if (kunde) {
            fileName = "grill" + new SimpleDateFormat("dd. MMMMM yyyy hhmm").format(date.getTime()) + ".pdf";
        } else {
            fileName = "grill" + new SimpleDateFormat("dd. MMMMM yyyy hhmm").format(date.getTime())
                    + "Prisliste.pdf";
        }

        FileOutputStream file = new FileOutputStream(new File("C:/Users/Mark/Desktop", fileName));
        PdfWriter writer = PdfWriter.getInstance(document, file);
        document.open();

        Image img = Image.getInstance("src/pictures/cirkles.png");
        img.scaleToFit(277, 277);
        img.setAbsolutePosition(40, PageSize.A4.getHeight() - img.getHeight());
        document.add(img);
        Chunk chunk = new Chunk("Grillmester 'Frankie'", font);
        chunk.setCharacterSpacing(3);
        Paragraph header = new Paragraph(chunk);
        header.setAlignment(Element.ALIGN_RIGHT);
        header.setSpacingBefore(15);
        document.add(header);
        Paragraph title = new Paragraph(
                "Tilbud angende d. " + new SimpleDateFormat("dd. MMMMM yyyy").format(date.getTime()) + ".",
                new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD));
        title.setAlignment(Element.ALIGN_LEFT);
        title.setIndentationLeft(235);
        title.setSpacingBefore(100);
        title.setLeading(17);
        document.add(title);
        Paragraph subtitle = new Paragraph("(Arrangement til " + settings + " personer).",
                new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.ITALIC));
        subtitle.setAlignment(Element.ALIGN_LEFT);
        subtitle.setIndentationLeft(235);
        subtitle.setLeading(17);
        document.add(subtitle);
        Paragraph body = new Paragraph("\n\nDer er aftalt:\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 18));
        body.setAlignment(Element.ALIGN_LEFT);
        body.setIndentationLeft(235);
        body.setLeading(17);
        for (String course : courses) {
            body.add(course + "\n\n");
        }
        body.add("\nServeres klokken " + time + " i " + eventAddress + ".");
        document.add(body);
        Paragraph ending = new Paragraph("\n\n\nPris: " + totalPrice + ",-kr.",
                new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
        ending.setAlignment(Element.ALIGN_LEFT);
        ending.setIndentationLeft(235);
        ending.setLeading(17);
        document.add(ending);
        if (!comments.equals("null")) {
            if (!comments.equals("")) {
                Paragraph comment = new Paragraph("\n\nKommentarer\n" + comments,
                        new Font(Font.FontFamily.TIMES_ROMAN, 18));
                comment.setAlignment(Element.ALIGN_LEFT);
                comment.setIndentationLeft(235);
                comment.setLeading(17);
                document.add(comment);
            }
        }

        Image footerImg = Image.getInstance("src/pictures/grillmester.png");
        footerImg.scaleToFit(210, 210);
        footerImg.setAbsolutePosition(40, 40);
        document.add(footerImg);

        Image img2 = Image.getInstance("src/pictures/Contact.png");
        img2.scaleToFit(250, 250);
        img2.setAbsolutePosition(20, PageSize.A4.getHeight() - img.getHeight() - 250);
        document.add(img2);

        document.close();

        System.out.println("Pdf finish");
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(e.getLocalizedMessage());
    }
}