Example usage for com.itextpdf.text Chunk Chunk

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

Introduction

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

Prototype

private Chunk(final Float tabInterval, final boolean isWhitespace) 

Source Link

Document

Creates a tab Chunk.

Usage

From source file:de.jost_net.JVerein.io.Reporter.java

License:Open Source License

/**
 * Erzeugt eine Zelle der Tabelle./*from  w w w.  j  a  va  2s  .c  o m*/
 * 
 * @param text
 *          der anzuzeigende Text.
 * @param align
 *          die Ausrichtung.
 * @param backgroundcolor
 *          die Hintergundfarbe.
 * @return die erzeugte Zelle.
 */
private PdfPCell getDetailCell(String text, int align, BaseColor backgroundcolor, boolean silbentrennung) {
    PdfPCell cell = null;
    if (silbentrennung) {
        cell = new PdfPCell(new Phrase(new Chunk(notNull(text), getFreeSans(8)).setHyphenation(hyph)));
    } else {
        cell = new PdfPCell(new Phrase(new Chunk(notNull(text), getFreeSans(8))));
    }
    cell.setHorizontalAlignment(align);
    cell.setBackgroundColor(backgroundcolor);
    return cell;
}

From source file:de.jost_net.JVerein.io.Reporter.java

License:Open Source License

private PdfPCell getDetailCell(String text, int align, BaseColor backgroundcolor, int colspan) {
    PdfPCell cell = new PdfPCell(new Phrase(new Chunk(notNull(text), getFreeSans(8)).setHyphenation(hyph)));
    cell.setHorizontalAlignment(align);//from   ww w  .  j  ava 2 s .  c om
    cell.setBackgroundColor(backgroundcolor);
    cell.setColspan(colspan);
    return cell;
}

From source file:de.knurt.heinzelmann.util.itext.TextBlock.java

License:Creative Commons License

private List<Chunk> getChunks(String content) {
    Font italic = new Font(this.font);
    italic.setStyle(Font.ITALIC);
    Font normal = new Font(this.font);
    normal.setStyle(Font.NORMAL);
    Font bold = new Font(this.font);
    bold.setStyle(Font.BOLD);/*  w w w  .java2 s  . c  o  m*/
    Font bolditalic = new Font(this.font);
    bolditalic.setStyle(Font.BOLDITALIC);
    Font markfont = null;
    boolean markModus = false;

    List<Chunk> result = new ArrayList<Chunk>();
    List<Chunk> tmp = new ArrayList<Chunk>();

    StringTokenizer tokenizer = new StringTokenizer(content, "\\*", true);
    while (tokenizer.hasMoreTokens()) {
        String tok = tokenizer.nextToken();
        if (tok.equals("*")) {
            if (markModus) {
                if (markfont.getStyle() == Font.ITALIC) {
                    markfont = bold;
                } else {
                    markfont = bolditalic;
                }
            } else {
                if (markfont == null) {
                    markfont = italic;
                    markModus = true;
                } else if (markfont.getStyle() == Font.BOLDITALIC) {
                    markfont = bold;
                } else if (markfont.getStyle() == Font.BOLD) {
                    markfont = italic;
                } else if (markfont.getStyle() == Font.ITALIC) {
                    markfont = null;
                }
            }
            continue;
        }
        if (markfont != null) {
            tmp.add(new Chunk(tok, markfont));
            markModus = false;
        } else {
            tmp.add(new Chunk(tok, normal));
        }
    }
    result.addAll(tmp);
    return result;
}

From source file:ECS.create.java

create() {
    //geting the file path from Page.
    String dpath = Page.dpath;//from  ww w  . ja v a 2 s  .c o m
    try {
        //define program "information" as data
        information data = new information();

        //crate a PDF File
        Document cs = new Document();
        //locate where the PDF save.
        FileOutputStream local = new FileOutputStream(dpath);
        //New PDF location
        PdfWriter writer = PdfWriter.getInstance(cs, local);

        //Edit Propety of the PDF
        cs.addTitle("Title@CoverSheet");
        cs.addAuthor("Author@rensanning");
        cs.addSubject("Subject@iText sample");
        cs.addKeywords("Keywords@iText");
        cs.addCreator("Creator@iText");

        //Seting the Font of the text in the PDF
        Font title = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD);
        //Font stitle = new Font(Font.FontFamily.COURIER, 18,Font.ITALIC | Font.UNDERLINE);
        Font stitle = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
        Font usual = new Font(Font.FontFamily.TIMES_ROMAN, 18);

        // open the PDF File
        cs.open();

        PdfContentByte canvas = writer.getDirectContent();

        // insert the information in the PDF
        //group the information into paragrph
        Paragraph sinfo = new Paragraph();
        //using the data form the database which geting by program "information"
        sinfo.add(new Chunk("Name: " + data.fn + " " + data.ln, title));
        //cs.add(Chunk.NEWLINE);
        sinfo.add(new Chunk("               "));
        sinfo.add(new Chunk("SID: " + data.sid, title));
        sinfo.setLeading(40);
        //sinfo.add(Chunk.NEWLINE);
        cs.add(sinfo);

        Paragraph cinfo = new Paragraph();
        cinfo.add(new Chunk("Course: " + data.cid + "   " + data.cn, stitle));
        cinfo.setLeading(30);
        cinfo.add(Chunk.NEWLINE);
        cs.add(cinfo);

        Paragraph minfo = new Paragraph();
        minfo.add(new Chunk("Module: ", stitle));
        minfo.add(new Chunk(data.mid + " " + data.mn, usual));
        minfo.setLeading(30);
        minfo.add(Chunk.NEWLINE);
        cs.add(minfo);

        // insert the information in the PDF
        Paragraph cwinfo = new Paragraph();
        cwinfo.add(new Chunk("Coursework ID: ", stitle));
        cwinfo.add(new Chunk(data.cwid, usual));
        cwinfo.add(Chunk.NEWLINE);
        cwinfo.add(new Chunk("Coursework Tile: ", stitle));
        cwinfo.add(new Chunk(data.cwt, usual));
        cwinfo.add(Chunk.NEWLINE);
        cwinfo.add(new Chunk("Coursework Deadline is on ", stitle));
        cwinfo.add(new Chunk(data.cwed, usual));
        cwinfo.setLeading(30);
        cs.add(cwinfo);

        cs.add(new Paragraph("Rule: \n" + " I am the Boss", usual));

        //Phrase phrase1= new Phrase("This is sentence 1. ", title);
        //ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase1, 30, 600, 0); 
        //cs.add(new Paragraph("Name: " + data.fn + " " + data.ln, title));
        //cs.add(new Chunk("SID: " + data.sid));

        //Close the PDF file
        cs.close();
    } catch (DocumentException | FileNotFoundException ex) {
        System.out.println(ex);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java

License:Open Source License

public PDFDocument(String authorName, Map<String, Integer> yearToPublicationCount, Document document,
        PdfWriter pdfWriter) {//from w  w w .j av  a  2s .  c  o  m

    //        setPreferredSize(new Dimension(600,400));

    try {

        document.addTitle("PDF Pipeline iText Prototype");
        document.addAuthor(authorName);
        document.addSubject("This example tests text, color, image, transparency & table functionality.");
        document.addKeywords("text, color, image, transparency, table");
        document.addCreator("Standalone PDF Renderer using iText");

        Paragraph header = new Paragraph();

        Font pageHeaderStyle = FontFactory.getFont(FontFactory.TIMES_ROMAN, 15,
                Font.BOLDITALIC | Font.UNDERLINE);
        Font featureHeaderStyle = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, new BaseColor(Color.red));

        header.add(new Chunk("PDF Pipeline Prototype v2 using iText\n", pageHeaderStyle));

        header.setSpacingAfter(15f);

        document.add(header);

        Paragraph content = new Paragraph();

        content.add(new Chunk("Publication Count - Author Name - " + authorName, featureHeaderStyle));

        content.setSpacingAfter(15f);

        document.add(content);
        // step4

        PdfPTable publicationCount = createTable(yearToPublicationCount);

        document.add(publicationCount);

        content = new Paragraph();

        content.add(new Chunk("Transparency of Shapes", featureHeaderStyle));

        content.setSpacingAfter(15f);

        document.add(content);

        createTransparencyShapes(document, pdfWriter);

        createImage(document, pdfWriter, featureHeaderStyle);

    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java

License:Open Source License

private void createImage(Document document, PdfWriter writer, Font featureHeaderStyle)
        throws BadElementException, MalformedURLException, IOException, DocumentException {
    Image imageSprite = Image.getInstance(new URL(
            "http://lh3.ggpht.com/_4msVPAgKJv8/SCRYD-pPVKI/AAAAAAAAAYU/zUN963EPoZc/s1024/102_0609.JPG"));
    imageSprite.setAbsolutePosition(400, 500);
    imageSprite.scaleAbsolute(171.0f, 250.0f);
    float imageSpriteY = document.getPageSize().getHeight() * 0.60f;
    float imageSpriteX = document.getPageSize().getWidth() * 0.65f;
    imageSprite.setAlignment(Image.UNDERLYING);

    document.add(imageSprite);//from   ww  w.ja  va  2  s.c  o  m

    PdfContentByte cb = writer.getDirectContent();
    ColumnText ct = new ColumnText(cb);
    Chunk imageHeader = new Chunk("Images", featureHeaderStyle);
    ct.addText(imageHeader);
    ct.setAlignment(Element.ALIGN_LEFT);
    ct.setSimpleColumn(imageSpriteX, imageSpriteY - imageSprite.getScaledHeight(),
            imageSpriteX + imageSprite.getScaledWidth(), imageSpriteY + imageSprite.getScaledHeight() + 20);
    ct.go();

    ct = new ColumnText(cb);
    Chunk imageFooter = new Chunk("Footer to be set for a figure. Similar to 'image cpation'.",
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8));
    ct.addText(imageFooter);
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.setSimpleColumn(imageSpriteX, imageSpriteY - 150, imageSpriteX + imageSprite.getScaledWidth(),
            imageSpriteY);
    ct.go();
}

From source file:EplanPrinter.PDFPrint.java

License:Open Source License

public Phrase composePhrase(String str, BaseFont normalFont, BaseFont boldFont)
        throws DocumentException, IOException {
    ArrayList<Chunk> chunks = new ArrayList();

    // unescape all HTML encode i.e &lt; = <
    str = HtmlDecoder.unescapeHTML(str);

    // replace all <li> with bullet symbol
    str = Pattern.compile("\\<li*?\\>", Pattern.CASE_INSENSITIVE).matcher(str)
            .replaceAll(new Character('\u2022') + " ");

    String words[] = str.split(" ");
    for (int i = 0; i < words.length; i++) {
        String noHtml = words[i];
        BaseFont font = boldFont;/*  w w  w . j  av  a2s.c  om*/
        if (hasHtmlTag(noHtml, REGEX_B)) {
            noHtml = removeHtmlTag(words[i]);
        } else if (hasHtmlTag(noHtml, REGEX_I)) {
            noHtml = removeHtmlTag(words[i]);
        } else if (hasHtmlTag(noHtml, REGEX_EM)) {
            noHtml = removeHtmlTag(words[i]);
        } else if (hasHtmlTag(noHtml, REGEX_STRONG)) {
            noHtml = removeHtmlTag(words[i]);
        } else if (hasHtmlTag(noHtml, REGEX_LI)) {
            noHtml = new Character('\u2022') + " " + removeHtmlTag(words[i]);
            font = normalFont;
        } else if (hasHtmlTag(noHtml, REGEX_DT)) {
            noHtml = new Character('\u2022') + " " + removeHtmlTag(words[i]);
            font = normalFont;
        } else if (hasHtmlTag(noHtml, REGEX_DD)) {
            noHtml = new Character('\u2022') + " " + removeHtmlTag(words[i]);
            font = normalFont;
        } else {
            noHtml = removeHtmlTag(words[i]);
            font = normalFont;
        }

        chunks.add(new Chunk(noHtml + " ", new Font(font, fontSize)));
    }

    Phrase phrase = new Phrase();
    for (Chunk chunk : chunks) {
        phrase.add(chunk);
    }

    return phrase;
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java

License:Open Source License

protected Paragraph createParagraph(String s) {

    Paragraph result = getDefaultParagraph();
    StringBuilder sb = new StringBuilder();
    Font f = CONTENT_NORMAL;//from  w w w.  j  av a2  s  . c  om
    boolean customStyle = false;

    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (!customStyle) {
            if (c == '%') {
                if (i + 1 < s.length()) {
                    i++;
                    c = s.charAt(i);
                    if (c == 'b') {//bold
                        f = CONTENT_BOLD;
                        customStyle = true;
                    } else if (c == 'i') {//italic
                        f = CONTENT_ITALIC;
                        customStyle = true;
                    } else if (c == 'u') {//underlined
                        f = CONTENT_UNDERLINE;
                        customStyle = true;
                    } else if (c == 'e') {//emphasized (bold/italic)
                        f = CONTENT_BOLDITALIC;
                        customStyle = true;
                    } else {
                        sb.append("%" + c);
                    }
                    if (customStyle) {
                        result.add(new Chunk(sb.toString()/*.replace(" ","\u00a0")*/, CONTENT_NORMAL));
                        sb = new StringBuilder();
                    }
                } else {
                    sb.append(c);
                }
            } else {
                sb.append(c);
            }
        } else {
            if (c == '%') {
                result.add(new Chunk(sb.toString()/*.replace(" ","\u00a0")*/, f));
                sb = new StringBuilder();
                customStyle = false;
            } else {
                sb.append(c);
            }
        }
    }
    if (sb.length() > 0 && customStyle) {
        result.add(new Chunk(sb.toString()/*.replace(" ","\u00a0")*/, f));
    } else if (sb.length() > 0 && !customStyle) {
        result.add(new Chunk(sb.toString()/*.replace(" ","\u00a0")*/, CONTENT_NORMAL));
    }
    return result;
}

From source file:femr.ui.controllers.PDFController.java

License:Open Source License

private Phrase getStyledPhrase(String title, String value) {
    Phrase phrase = new Phrase();
    phrase.add(new Chunk(title, getTitleFont()));
    phrase.add(new Chunk(value, getValueFont()));
    return phrase;
}

From source file:fll.scheduler.TournamentSchedule.java

License:Open Source License

/**
 * Output the detailed schedule for a team for the day.
 * /*from  w w w .jav a  2s . c  om*/
 * @throws DocumentException
 */
private void outputTeamSchedule(final SchedParams params, final Document detailedSchedules,
        final TeamScheduleInfo si) throws DocumentException {
    final Paragraph para = new Paragraph();
    para.add(new Chunk(
            String.format("Detailed schedule for Team #%d - %s", si.getTeamNumber(), si.getTeamName()),
            TEAM_TITLE_FONT));
    para.add(Chunk.NEWLINE);

    para.add(new Chunk(String.format("Organization: %s", si.getOrganization()), TEAM_TITLE_FONT));
    para.add(Chunk.NEWLINE);

    para.add(new Chunk("Division: ", TEAM_HEADER_FONT));
    para.add(new Chunk(si.getAwardGroup(), TEAM_VALUE_FONT));
    para.add(Chunk.NEWLINE);

    for (final String subjectiveStation : subjectiveStations) {
        para.add(new Chunk(subjectiveStation + ": ", TEAM_HEADER_FONT));
        final LocalTime start = si.getSubjectiveTimeByName(subjectiveStation).getTime();
        final LocalTime end = start.plus(params.getStationByName(subjectiveStation).getDuration());
        para.add(new Chunk(String.format("%s - %s", formatTime(start), formatTime(end)), TEAM_VALUE_FONT));
        para.add(Chunk.NEWLINE);
    }

    for (int round = 0; round < getNumberOfRounds(); ++round) {
        para.add(new Chunk(String.format(PERF_HEADER_FORMAT, round + 1) + ": ", TEAM_HEADER_FONT));
        final LocalTime start = si.getPerfTime(round);
        final LocalTime end = start.plus(Duration.ofMinutes(params.getPerformanceMinutes()));
        para.add(new Chunk(String.format("%s - %s %s %d", formatTime(start), formatTime(end),
                si.getPerfTableColor(round), si.getPerfTableSide(round)), TEAM_VALUE_FONT));
        para.add(Chunk.NEWLINE);
    }

    para.add(Chunk.NEWLINE);
    para.add(new Chunk(
            "Performance rounds must start on time, and will start without you. Please ensure your team arrives at least 5 minutes ahead of scheduled time, and checks in.",
            TEAM_HEADER_FONT));

    para.add(Chunk.NEWLINE);
    para.add(new Chunk(
            "Note that there may be more judging and a head to head round after this judging, please see the main tournament schedule for these details.",
            TEAM_HEADER_FONT));
    para.add(Chunk.NEWLINE);
    para.add(Chunk.NEWLINE);
    para.add(Chunk.NEWLINE);

    para.setKeepTogether(true);
    detailedSchedules.add(para);
}