Search in sources :

Example 1 with Font

use of com.lowagie.text.Font in project Openfire by igniterealtime.

the class ConversationUtils method buildPDFContent.

private ByteArrayOutputStream buildPDFContent(Conversation conversation, Map<String, Font> colorMap) {
    Font roomEvent = FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.ITALIC, new Color(0xFF, 0x00, 0xFF));
    try {
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new PDFEventListener());
        document.open();
        Paragraph p = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.title", MonitoringConstants.NAME), FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD));
        document.add(p);
        document.add(Chunk.NEWLINE);
        ConversationInfo coninfo = new ConversationUtils().getConversationInfo(conversation.getConversationID(), false);
        String participantsDetail;
        if (coninfo.getAllParticipants() == null) {
            participantsDetail = coninfo.getParticipant1() + ", " + coninfo.getParticipant2();
        } else {
            participantsDetail = String.valueOf(coninfo.getAllParticipants().length);
        }
        Paragraph chapterTitle = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.participants", MonitoringConstants.NAME) + " " + participantsDetail, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
        document.add(chapterTitle);
        Paragraph startDate = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.startdate", MonitoringConstants.NAME) + " " + coninfo.getDate(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
        document.add(startDate);
        Paragraph duration = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.duration", MonitoringConstants.NAME) + " " + coninfo.getDuration(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
        document.add(duration);
        Paragraph messageCount = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.messagecount", MonitoringConstants.NAME) + " " + conversation.getMessageCount(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
        document.add(messageCount);
        document.add(Chunk.NEWLINE);
        Paragraph messageParagraph;
        for (ArchivedMessage message : conversation.getMessages()) {
            String time = JiveGlobals.formatTime(message.getSentDate());
            String from = message.getFromJID().getNode();
            if (conversation.getRoom() != null) {
                from = message.getToJID().getResource();
            }
            String body = message.getBody();
            String prefix;
            if (!message.isRoomEvent()) {
                prefix = "[" + time + "] " + from + ":  ";
                Font font = colorMap.get(message.getFromJID().toString());
                if (font == null) {
                    font = colorMap.get(message.getFromJID().toBareJID());
                }
                if (font == null) {
                    font = FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD, Color.BLACK);
                }
                messageParagraph = new Paragraph(new Chunk(prefix, font));
            } else {
                prefix = "[" + time + "] ";
                messageParagraph = new Paragraph(new Chunk(prefix, roomEvent));
            }
            messageParagraph.add(body);
            messageParagraph.add(" ");
            document.add(messageParagraph);
        }
        document.close();
        return baos;
    } catch (DocumentException e) {
        Log.error("error creating PDF document: " + e.getMessage(), e);
        return null;
    }
}
Also used : PdfWriter(com.lowagie.text.pdf.PdfWriter) Color(java.awt.Color) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(com.lowagie.text.Document) Chunk(com.lowagie.text.Chunk) Font(com.lowagie.text.Font) Paragraph(com.lowagie.text.Paragraph) DocumentException(com.lowagie.text.DocumentException)

Example 2 with Font

use of com.lowagie.text.Font in project activityinfo by bedatadriven.

the class ThemeHelper method elementTitle.

public static Paragraph elementTitle(String title) {
    Paragraph para = new Paragraph(title);
    para.setFont(new Font(Font.TIMES_ROMAN, HEADER2_FONT_SIZE, Font.BOLD, BLUE2));
    para.setSpacingBefore(BODY_FONT_SIZE);
    return para;
}
Also used : Font(com.lowagie.text.Font) Paragraph(com.lowagie.text.Paragraph)

Example 3 with Font

use of com.lowagie.text.Font in project activityinfo by bedatadriven.

the class ThemeHelper method filterDescription.

public static Paragraph filterDescription(String text) {
    Paragraph para = new Paragraph(text);
    para.setFont(new Font(Font.HELVETICA, HEADER3_FONT_SIZE, Font.NORMAL, Color.BLACK));
    return para;
}
Also used : Font(com.lowagie.text.Font) Paragraph(com.lowagie.text.Paragraph)

Example 4 with Font

use of com.lowagie.text.Font in project mdw-designer by CenturyLinkCloud.

the class ExportHelper method generateElementHtml.

private Object generateElementHtml(Element element, int depth, Font font) {
    String tag = element.getName();
    Object myself;
    Object av;
    Font vFont = font;
    if (element instanceof HTMLDocument.RunElement) {
        HTMLDocument.RunElement re = (HTMLDocument.RunElement) element;
        int start = re.getStartOffset();
        int end = re.getEndOffset();
        try {
            String content = re.getDocument().getText(start, end - start);
            HtmlAttr htmlattr = printAttributesHtml(re);
            av = re.getAttribute(CSS.Attribute.FONT_SIZE);
            String fontsize = av == null ? null : av.toString();
            av = re.getAttribute(CSS.Attribute.FONT_FAMILY);
            String fontfamily = av == null ? null : av.toString();
            av = re.getAttribute(CSS.Attribute.COLOR);
            String fontcolor = av == null ? null : av.toString();
            if (fontcolor != null || fontsize != null || fontfamily != null) {
                if (fontfamily == null)
                    fontfamily = font.getFamilyname();
                if (fontsize != null && fontsize.endsWith("pt"))
                    fontsize = fontsize.substring(0, fontsize.indexOf("pt"));
                float size = fontsize == null ? font.getSize() : (Float.parseFloat(fontsize) + 8);
                int style = font.getStyle();
                Color color;
                if (fontcolor != null) {
                    color = Color.decode(fontcolor);
                } else
                    color = font.getColor();
                vFont = FontFactory.getFont(fontfamily, size, style, color);
            } else if (htmlattr.bold || htmlattr.italic) {
                String family = font.getFamilyname();
                float size = font.getSize();
                Color color = font.getColor();
                if (htmlattr.bold && htmlattr.italic)
                    vFont = FontFactory.getFont(family, size, Font.BOLDITALIC, color);
                else if (htmlattr.italic)
                    vFont = FontFactory.getFont(family, size, Font.ITALIC, color);
                else if (htmlattr.bold)
                    vFont = FontFactory.getFont(family, size, Font.BOLD);
            }
            myself = new Chunk(content, vFont);
        } catch (BadLocationException e) {
            e.printStackTrace();
            myself = null;
        }
    } else if (element instanceof HTMLDocument.BlockElement) {
        HTMLDocument.BlockElement be = (HTMLDocument.BlockElement) element;
        HtmlAttr htmlattr = printAttributesHtml(be);
        av = be.getAttribute(javax.swing.text.html.HTML.Attribute.ALIGN);
        String align = av == null ? null : av.toString();
        if (htmlattr.bold || htmlattr.italic) {
            String family = font.getFamilyname();
            float size = font.getSize();
            Color color = font.getColor();
            if (htmlattr.bold && htmlattr.italic)
                vFont = FontFactory.getFont(family, size, Font.BOLDITALIC, color);
            else if (htmlattr.italic)
                vFont = FontFactory.getFont(family, size, Font.ITALIC, color);
            else if (htmlattr.bold)
                vFont = FontFactory.getFont(family, size, Font.BOLD, Color.blue);
        }
        if ("html".equalsIgnoreCase(tag)) {
            myself = generateElementChildrenHtml(element, depth + 1, vFont);
        } else if ("head".equalsIgnoreCase(tag)) {
            myself = null;
        } else if ("body".equalsIgnoreCase(tag)) {
            myself = generateElementChildrenHtml(element, depth + 1, vFont);
        } else if ("p".equalsIgnoreCase(tag) || "p-implied".equalsIgnoreCase(tag)) {
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            Paragraph paragraph = new Paragraph();
            paragraph.setFirstLineIndent(0F);
            for (Object child : children) {
                if (!(child instanceof Chunk))
                    paragraph.add(child);
            }
            if (align != null)
                paragraph.setAlignment(align);
            myself = paragraph;
        } else if ("h1".equalsIgnoreCase(tag) || "h2".equalsIgnoreCase(tag) || "h3".equalsIgnoreCase(tag)) {
            List<Object> children = generateElementChildrenHtml(element, depth + 1, subSectionFont);
            Paragraph title = new Paragraph();
            for (Object child : children) {
                title.add(child);
            }
            myself = new TempSectionPdf(title);
        } else if ("ul".equalsIgnoreCase(tag)) {
            com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f);
            list.setIndentationLeft(25.0f);
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            for (Object child : children) {
                list.add(child);
            }
            myself = list;
        } else if ("ol".equalsIgnoreCase(tag)) {
            com.lowagie.text.List list = new com.lowagie.text.List(true, false, 20.0f);
            list.setIndentationLeft(25.0f);
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            for (Object child : children) {
                list.add(child);
            }
            myself = list;
        } else if ("li".equalsIgnoreCase(tag)) {
            ListItem li = new ListItem();
            li.setSpacingAfter(0.0f);
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            for (Object child : children) {
                li.add(child);
            }
            myself = li;
        } else if ("table".equalsIgnoreCase(tag)) {
            List<Object> rows = generateElementChildrenHtml(element, depth + 1, normalFont);
            try {
                int ncols = 0;
                for (Object row : rows) {
                    if (row instanceof List<?>) {
                        int n = ((List<?>) row).size();
                        if (n > ncols)
                            ncols = n;
                    }
                }
                Table table = new Table(2);
                table.setBorderWidth(1);
                table.setBorderColor(new Color(0, 128, 128));
                table.setPadding(1.0f);
                table.setSpacing(0.5f);
                Cell c = new Cell("header");
                c.setHeader(true);
                c.setColspan(ncols);
                table.addCell(c);
                table.endHeaders();
                for (Object row : rows) {
                    if (row instanceof List<?>) {
                        for (Object cell : (List<?>) row) {
                            if (cell instanceof Cell)
                                table.addCell((Cell) cell);
                        }
                    }
                }
                myself = table;
            } catch (BadElementException e) {
                e.printStackTrace();
                myself = null;
            }
        } else if ("tr".equalsIgnoreCase(tag)) {
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            myself = children;
        } else if ("td".equalsIgnoreCase(tag)) {
            Cell cell = new Cell();
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            for (Object child : children) {
                cell.add(child);
            }
            myself = cell;
        } else if ("div".equalsIgnoreCase(tag)) {
            List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont);
            Paragraph paragraph = new Paragraph();
            paragraph.setFirstLineIndent(0F);
            for (Object child : children) {
                paragraph.add(child);
            }
            if (align != null)
                paragraph.setAlignment(align);
            myself = paragraph;
        } else {
            System.err.println("Unknown element " + element.getName());
            myself = null;
        }
    } else {
        // could be BidiElement - not sure what it is
        myself = null;
    }
    return myself;
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) Font(com.lowagie.text.Font) List(java.util.List) ArrayList(java.util.ArrayList) Cell(com.lowagie.text.Cell) DocxTable(com.centurylink.mdw.designer.utils.DocxBuilder.DocxTable) Table(com.lowagie.text.Table) BadElementException(com.lowagie.text.BadElementException) Color(java.awt.Color) Chunk(com.lowagie.text.Chunk) Paragraph(com.lowagie.text.Paragraph) ListItem(com.lowagie.text.ListItem) BadLocationException(javax.swing.text.BadLocationException)

Example 5 with Font

use of com.lowagie.text.Font in project OpenClinica by OpenClinica.

the class DownloadDiscrepancyNote method createCell.

private Cell createCell(String propertyName, String propertyValue) throws BadElementException {
    StringBuilder content = new StringBuilder(propertyName + ": ");
    content.append(propertyValue);
    Paragraph para = new Paragraph(content.toString(), new Font(Font.HELVETICA, 14, Font.BOLD, new Color(0, 0, 0)));
    return new Cell(para);
}
Also used : Color(java.awt.Color) Cell(com.lowagie.text.Cell) Font(com.lowagie.text.Font) Paragraph(com.lowagie.text.Paragraph)

Aggregations

Font (com.lowagie.text.Font)18 Paragraph (com.lowagie.text.Paragraph)14 Color (java.awt.Color)9 Cell (com.lowagie.text.Cell)6 DocumentException (com.lowagie.text.DocumentException)6 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)4 ExpressionException (cbit.vcell.parser.ExpressionException)3 Chunk (com.lowagie.text.Chunk)3 Document (com.lowagie.text.Document)3 BaseFont (com.lowagie.text.pdf.BaseFont)3 HeaderFooter (com.lowagie.text.HeaderFooter)2 Phrase (com.lowagie.text.Phrase)2 Table (com.lowagie.text.Table)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 Feature (cbit.vcell.model.Feature)1 Membrane (cbit.vcell.model.Membrane)1 StructureTopology (cbit.vcell.model.Model.StructureTopology)1 DocxTable (com.centurylink.mdw.designer.utils.DocxBuilder.DocxTable)1 BadElementException (com.lowagie.text.BadElementException)1 ListItem (com.lowagie.text.ListItem)1