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) 

Source Link

Document

Creates a tab Chunk.

Usage

From source file:org.tellervo.desktop.util.labels.PDFLabelMaker.java

License:Open Source License

public void addLabelsForSamples(List<TridasSample> samples) {

    // Loop through samples in list
    for (TridasSample s : samples) {
        Barcode128 barcode = new LabBarcode(LabBarcode.Type.SAMPLE,
                UUID.fromString(s.getIdentifier().getValue().toString()));

        // if it's tiny, hide the label
        if (margins.getLabelHeight() * .80f < barcode.getBarHeight()) {
            barcode.setBarHeight(margins.getLabelHeight() * .45f);
            barcode.setX(1.8f);// w  w w. j av a  2s .co  m
            barcode.setN(10f);
            barcode.setSize(10f);
            barcode.setBaseline(10f);
            barcode.setBarHeight(50f);
            barcode.setFont(null);
        } else {
            barcode.setBarHeight(margins.getLabelHeight() * .45f);
            barcode.setX(0.6f);
            barcode.setSize(4.0f);

        }

        PdfPCell lbcell = new PdfPCell();

        lbcell.setVerticalAlignment(Element.ALIGN_TOP);
        lbcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        Phrase p = new Phrase();

        String labelText;
        TridasGenericField labcodeField = GenericFieldUtils.findField(s, "tellervo.internal.labcodeText");

        if (labcodeField == null) {
            log.warn("labcode missing from sample.  Can't print!");
            continue;
        }
        labelText = (labcodeField != null) ? labcodeField.getValue() : s.getTitle();

        p.add(new Chunk(labelText, labelfont));
        //p.add(new Chunk("bbb", labelfont));
        //p.add(new Chunk(s.getIdentifier().getValue().toString(), uuidfont));

        //barcode.setFont(null);
        Image img = barcode.createImageWithBarcode(contentb, Color.black, Color.gray);

        PdfPCell labcell = new PdfPCell();

        if (App.getLabName() != null) {
            labcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            labcell.setVerticalAlignment(Element.ALIGN_TOP);
            Phrase labPhrase = new Phrase(App.getLabName().toUpperCase(), tinyfont);
            labcell.addElement(labPhrase);
        }
        addCell(labcell);

        PdfPCell bccell = new PdfPCell();
        bccell.setHorizontalAlignment(Element.ALIGN_MIDDLE);

        bccell.addElement(img);
        bccell.addElement(p);
        addCell(bccell);

        lbcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        lbcell.addElement(p);
        addCell(lbcell);

        //addCell(new PdfPCell());

        /**   PdfPTable tbl = new PdfPTable(2);
                   
           tbl.addCell(bccell);
           tbl.addCell(lbcell);*/

    }

}

From source file:org.tn5250jlpr.SCS2PDF.java

License:Open Source License

private void writeChar(String s) {

    if (!document.isOpen())
        document.open();//w  w  w  .ja v  a 2 s  .c om

    try {
        document.add(new Phrase(new Chunk(s, font)));
    } catch (com.lowagie.text.DocumentException de) {
        System.out.println(de);
    }
}

From source file:org.tpspencer.tal.mvc.document.DocumentWriterImpl.java

License:Apache License

/**
 * Helper to format the text replacing _something_ with
 * italics (the underscores are omitted).
 */// w  w w . java2 s  .  c o m
private Phrase formatText(String text) {
    Phrase p = new Phrase();
    StringBuilder buf = new StringBuilder();
    char[] chars = text.toCharArray();
    boolean inItals = false;
    for (int i = 0; i < chars.length; i++) {
        if (chars[i] == '_') {
            // TODO: Could check that there is another _

            Font f = inItals ? quoteFont : paraFont;
            p.add(new Chunk(buf.toString(), f));
            buf.setLength(0);
            inItals = !inItals;
        }
        /*else if( chars[i] == '*' ) {
           // TODO: Do same for bold
        }*/
        else {
            buf.append(chars[i]);
        }
    }
    if (buf.length() > 0) {
        Font f = inItals ? quoteFont : paraFont;
        p.add(new Chunk(buf.toString(), f));
    }

    return p;
}

From source file:org.unitime.timetable.export.PDFPrinter.java

License:Open Source License

@Override
public void printHeader(String... fields) {
    iTable = new PdfPTable(fields.length - iHiddenColumns.size());
    iMaxWidth = new float[fields.length];
    iTable.setHeaderRows(1);/*from w  w w.  ja  v  a2  s  .  c o  m*/
    iTable.setWidthPercentage(100);

    for (int idx = 0; idx < fields.length; idx++) {
        if (iHiddenColumns.contains(idx))
            continue;
        String f = fields[idx];

        PdfPCell cell = new PdfPCell();
        cell.setBorder(Rectangle.BOTTOM);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);

        Font font = PdfFont.getFont(true);
        cell.addElement(new Chunk(f, font));
        iTable.addCell(cell);

        float width = 0;
        if (f.indexOf('\n') >= 0) {
            for (StringTokenizer s = new StringTokenizer(f, "\n"); s.hasMoreTokens();)
                width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
        } else
            width = Math.max(width, font.getBaseFont().getWidthPoint(f, font.getSize()));
        iMaxWidth[idx] = width;
    }
}

From source file:org.unitime.timetable.webutil.pdf.PdfEventTableBuilder.java

License:Open Source License

public void addText(PdfPCell cell, String text, boolean bold, boolean italic, int orientation, Color color,
        boolean newLine) {
    if (text == null)
        return;/*ww  w .  j a v  a  2  s . co  m*/
    if (cell.getPhrase() == null) {
        Chunk ch = new Chunk(text, PdfFont.getSmallFont(bold, italic, color));
        cell.setPhrase(new Paragraph(ch));
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(orientation);
    } else {
        cell.getPhrase()
                .add(new Chunk((newLine ? "\n" : "") + text, PdfFont.getSmallFont(bold, italic, color)));
    }
}

From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java

License:Open Source License

public void addText(PdfPCell cell, String text, boolean bold, boolean italic, int orientation, Color color,
        boolean newLine) {
    if (text == null)
        return;/*from  w w w.  j a v a  2 s  .c  o  m*/
    if (cell.getPhrase() == null) {
        Chunk ch = new Chunk(text, PdfFont.getFont(bold, italic, color));
        cell.setPhrase(new Paragraph(ch));
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(orientation);
    } else {
        cell.getPhrase().add(new Chunk((newLine ? "\n" : "") + text, PdfFont.getFont(bold, italic, color)));
    }
}

From source file:org.unitime.timetable.webutil.PdfWebTable.java

License:Open Source License

private float addText(PdfPCell cell, String text, boolean bold, boolean italic, boolean underline, Color color,
        Color bgColor) {// w  ww  .ja va  2 s  .c  o m
    Font font = PdfFont.getFont(bold, italic, underline, color);
    Chunk chunk = new Chunk(text, font);
    if (bgColor != null)
        chunk.setBackground(bgColor);
    if (cell.getPhrase() == null) {
        cell.setPhrase(new Paragraph(chunk));
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    } else {
        cell.getPhrase().add(chunk);
    }
    float width = 0;
    if (text.indexOf('\n') >= 0) {
        for (StringTokenizer s = new StringTokenizer(text, "\n"); s.hasMoreTokens();)
            width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
    } else
        width = Math.max(width, font.getBaseFont().getWidthPoint(text, font.getSize()));
    return width;
}

From source file:org.unitime.timetable.webutil.timegrid.PdfExamGridTable.java

License:Open Source License

public void addText(PdfPCell cell, String text, boolean bold) {
    if (text == null)
        return;// w  ww  .j  a v  a  2  s  .  c om
    if (text.indexOf("<span") >= 0)
        text = text.replaceAll("</span>", "").replaceAll("<span .*>", "");
    text = text.replaceAll("<br>", "\n");
    text = text.replaceAll("<BR>", "\n");
    if (cell.getPhrase() == null) {
        cell.setPhrase(new Paragraph(text, PdfFont.getFont(bold)));
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    } else {
        cell.getPhrase().add(new Chunk("\n" + text, PdfFont.getFont(bold)));
    }
}

From source file:org.unitime.timetable.webutil.timegrid.PdfTimetableGridTable.java

License:Open Source License

public void addText(PdfPCell cell, String text, boolean bold) {
    if (text == null)
        return;/*from  ww  w. j av  a 2 s  .c  o m*/
    if (text.indexOf("<span") >= 0)
        text = text.replaceAll("</span>", "").replaceAll("<span .*>", "");
    if (cell.getPhrase() == null) {
        cell.setPhrase(new Paragraph(text, PdfFont.getSmallFont(bold)));
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    } else {
        cell.getPhrase().add(new Chunk("\n" + text, PdfFont.getSmallFont(bold)));
    }
}

From source file:oscar.oscarLab.ca.all.pageUtil.LabPDFCreator.java

License:Open Source License

private void createInfoTable() throws DocumentException {

    //Create patient info table
    PdfPCell cell = new PdfPCell();
    cell.setBorder(0);/*  w  ww  .jav  a2s .  c  o m*/
    float[] pInfoWidths = { 2f, 4f, 3f, 2f };
    PdfPTable pInfoTable = new PdfPTable(pInfoWidths);
    cell.setPhrase(new Phrase("Patient Name: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getPatientName(), font));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Home Phone: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getHomePhone(), font));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Date of Birth: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getDOB(), font));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Work Phone: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getWorkPhone(), font));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Age: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getAge(), font));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Sex: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getSex(), font));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Health #: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getHealthNum(), font));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Patient Location: ", boldFont));
    pInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getPatientLocation(), font));
    pInfoTable.addCell(cell);

    //Create results info table
    PdfPTable rInfoTable = new PdfPTable(2);
    cell.setPhrase(new Phrase("Date of Service: ", boldFont));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getServiceDate(), font));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Date Received: ", boldFont));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(dateLabReceived, font));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Report Status: ", boldFont));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase((handler.getOrderStatus().equals("F") ? "Final"
            : (handler.getOrderStatus().equals("C") ? "Corrected" : "Partial")), font));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Client Ref. #: ", boldFont));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getClientRef(), font));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase("Accession #: ", boldFont));
    rInfoTable.addCell(cell);
    cell.setPhrase(new Phrase(handler.getAccessionNum(), font));
    rInfoTable.addCell(cell);

    //Create client table
    float[] clientWidths = { 2f, 3f };
    Phrase clientPhrase = new Phrase();
    PdfPTable clientTable = new PdfPTable(clientWidths);
    clientPhrase.add(new Chunk("Requesting Client:  ", boldFont));
    clientPhrase.add(new Chunk(handler.getDocName(), font));
    cell.setPhrase(clientPhrase);
    clientTable.addCell(cell);

    clientPhrase = new Phrase();
    clientPhrase.add(new Chunk("cc: Client:  ", boldFont));
    clientPhrase.add(new Chunk(handler.getCCDocs(), font));
    cell.setPhrase(clientPhrase);
    clientTable.addCell(cell);

    //Create header info table
    float[] tableWidths = { 2f, 1f };
    PdfPTable table = new PdfPTable(tableWidths);
    if (multiID.length > 1) {
        cell = new PdfPCell(new Phrase("Version: " + versionNum + " of " + multiID.length, boldFont));
        cell.setBackgroundColor(new Color(210, 212, 255));
        cell.setPadding(3);
        cell.setColspan(2);
        table.addCell(cell);
    }
    cell = new PdfPCell(new Phrase("Detail Results: Patient Info", boldFont));
    cell.setBackgroundColor(new Color(210, 212, 255));
    cell.setPadding(3);
    table.addCell(cell);
    cell.setPhrase(new Phrase("Results Info", boldFont));
    table.addCell(cell);

    // add the created tables to the document
    table = addTableToTable(table, pInfoTable, 1);
    table = addTableToTable(table, rInfoTable, 1);
    table = addTableToTable(table, clientTable, 2);

    table.setWidthPercentage(100);

    document.add(table);
}