use of com.lowagie.text.Paragraph in project activityinfo by bedatadriven.
the class ThemeHelper method bodyCell.
/**
* Renders a Cell for
*
* @param label
* @param header
* @param depth
* @param leaf
* @param horizantalAlignment
* @return
* @throws BadElementException
*/
public static Cell bodyCell(String label, boolean header, int depth, boolean leaf, int horizantalAlignment) throws BadElementException {
Cell cell = new Cell();
cell.setHorizontalAlignment(horizantalAlignment);
if (label != null) {
Paragraph para = new Paragraph(label);
Font font = bodyFont();
if (depth == 0 && !leaf) {
font.setColor(Color.WHITE);
}
para.setFont(font);
para.setIndentationLeft(LEFT_INDENT + (header ? HEADER3_FONT_SIZE * depth : 0));
cell.addElement(para);
}
cell.setBorderWidthLeft(0f);
cell.setBorderWidthRight(0);
cell.setBorderWidthTop(0);
if (!leaf && depth == 0) {
// #95B3D7
cell.setBackgroundColor(BLUE4);
cell.setBorderWidthBottom(THIN_BORDER_WIDTH);
// #DBE5F1
cell.setBorderColorBottom(BLUE5);
} else if (!leaf && depth == 1) {
cell.setBackgroundColor(BLUE5);
cell.setBorderWidthBottom(THIN_BORDER_WIDTH);
cell.setBorderColorBottom(BLUE2);
} else {
cell.setBorderWidthBottom(THIN_BORDER_WIDTH);
cell.setBorderColorBottom(BLUE5);
cell.setBorderWidthTop(THIN_BORDER_WIDTH);
cell.setBorderColorTop(BLUE5);
}
return cell;
}
use of com.lowagie.text.Paragraph in project janrufmonitor by tbrandt77.
the class PDFCallerListFilter method doExport.
public boolean doExport() {
Document document = new Document(PageSize.A4.rotate());
document.addCreationDate();
document.addCreator("jAnrufmonitor");
try {
PdfWriter.getInstance(document, new FileOutputStream(this.m_filename));
document.open();
// get renderers
List renderer = new ArrayList();
String renderer_config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.editor.Editor", "renderer");
if (renderer_config != null && renderer_config.length() > 0) {
StringTokenizer s = new StringTokenizer(renderer_config, ",");
while (s.hasMoreTokens()) {
renderer.add(RendererRegistry.getInstance().getRenderer(s.nextToken()));
}
}
// get column width
float totalWidth = 0;
String[] cWidth = new String[renderer.size()];
for (int i = 0, j = renderer.size(); i < j; i++) {
cWidth[i] = getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.editor.Editor", "col_size_" + ((ITableCellRenderer) renderer.get(i)).getID());
if (cWidth[i] != null && cWidth[i].length() > 0) {
totalWidth += Float.parseFloat(cWidth[i]);
}
if (cWidth[i] != null && cWidth[i].length() == 0) {
cWidth[i] = "0";
}
}
float[] widths = new float[renderer.size()];
for (int i = 0, j = renderer.size(); i < j; i++) {
widths[i] = Float.parseFloat(cWidth[i]) / totalWidth;
}
PdfPTable table = new PdfPTable(widths);
table.setHeaderRows(1);
table.setWidthPercentage(100f);
ITableCellRenderer t = null;
PdfPCell cell = null;
for (int i = 0, j = renderer.size(); i < j; i++) {
t = (ITableCellRenderer) renderer.get(i);
if (t == null) {
this.m_logger.severe("No renderer found for ID: " + (String) renderer.get(i));
this.m_logger.severe("Export to PDF format canceled...");
return false;
}
cell = new PdfPCell(new Paragraph(t.getHeader()));
cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
table.addCell(cell);
}
ICaller c = null;
String cellContent = null;
Color iterateColor1 = new Color(0xDD, 0xDD, 0xDD);
Color iterateColor2 = new Color(0xFF, 0xFF, 0xFF);
cell = null;
int type_col = -1, num_col = -1;
for (int i = 0, j = this.m_callerList.size(); i < j; i++) {
c = this.m_callerList.get(i);
for (int k = 0, m = renderer.size(); k < m; k++) {
t = (ITableCellRenderer) renderer.get(k);
t.updateData(c);
// find number and typ column for multiline callers
if (t.getID().equalsIgnoreCase("NumberType"))
type_col = k;
if (t.getID().equalsIgnoreCase("Number"))
num_col = k;
cellContent = t.renderAsText();
if (cellContent != null && cellContent.length() > 0) {
cell = new PdfPCell(new Phrase(cellContent));
cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
table.addCell(cell);
} else {
cellContent = t.renderAsImageID();
if (cellContent != null && cellContent.length() > 0) {
if (cellContent.startsWith("db://")) {
InputStream in = ImageHandler.getInstance().getImageStream(c);
if (in != null) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Stream.copy(in, out, true);
in.close();
out.close();
Image pdfImage = Image.getInstance(out.toByteArray());
// pdfImage.scaleAbsolute(90.0f, 45.0f);
table.addCell(pdfImage);
} else {
table.addCell(" ");
}
} else if (new File(cellContent).exists()) {
Image pdfImage = Image.getInstance(cellContent);
table.addCell(pdfImage);
} else {
Image pdfImage = Image.getInstance(SWTImageManager.getInstance(PIMRuntime.getInstance()).getImagePath(cellContent));
table.addCell(pdfImage);
}
// ((Image pdfImage = Image.getInstance(cellContent);
// cell = new PdfPCell(pdfImage);
// cell.setBackgroundColor((i%2==0 ? iterateColor1 : iterateColor2));
// table.addCell(pdfImage);
} else {
cell = new PdfPCell(new Phrase(" "));
cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
table.addCell(cell);
}
}
// last column reached check for multiline caller
if (k == m - 1 && (type_col > -1 || num_col > -1) && (c instanceof IMultiPhoneCaller) && (((IMultiPhoneCaller) c).getPhonenumbers().size() > 1)) {
List phones = ((IMultiPhoneCaller) c).getPhonenumbers();
IPhonenumber pn = null;
for (int y = 1, z = phones.size(); y < z; y++) {
pn = (IPhonenumber) phones.get(y);
for (int w = 0, x = renderer.size(); w < x; w++) {
t = (ITableCellRenderer) renderer.get(w);
if (t.getID().equalsIgnoreCase("NumberType") || t.getID().equalsIgnoreCase("Number")) {
if (t.getID().equalsIgnoreCase("NumberType")) {
final IPhonenumber lpn = pn;
final IAttributeMap lam = c.getAttributes();
t.updateData(new ITreeItemCallerData() {
public IAttributeMap getAttributes() {
return lam;
}
public IPhonenumber getPhone() {
return lpn;
}
});
} else
t.updateData(pn);
cellContent = t.renderAsText();
if (cellContent != null && cellContent.length() > 0) {
cell = new PdfPCell(new Phrase(cellContent));
cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
table.addCell(cell);
} else {
cell = new PdfPCell(new Phrase(" "));
cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
table.addCell(cell);
}
} else {
cell = new PdfPCell(new Phrase(" "));
cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
table.addCell(cell);
}
}
}
}
}
}
document.add(table);
} catch (DocumentException de) {
this.m_logger.severe(de.getMessage());
return false;
} catch (IOException ioe) {
this.m_logger.severe(ioe.getMessage());
return false;
} finally {
document.close();
}
return true;
}
use of com.lowagie.text.Paragraph in project janrufmonitor by tbrandt77.
the class PDFCreator method createPdf.
public void createPdf() {
Document document = new Document(PageSize.A4);
document.addCreationDate();
document.addCreator("jAnrufmonitor");
try {
PdfWriter.getInstance(document, new FileOutputStream(this.m_file));
document.open();
document.add(new Paragraph(this.getI18nManager().getString(getNamespce(), "pdftitle", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 16f, Font.BOLD | Font.UNDERLINE)));
document.add(new Paragraph(" "));
String msg = "";
ITableCellRenderer tcr = RendererRegistry.getInstance().getRenderer("name");
if (tcr != null) {
tcr.updateData(m_cc.getCaller());
msg += tcr.renderAsText();
}
tcr = RendererRegistry.getInstance().getRenderer("number");
if (tcr != null) {
tcr.updateData(m_cc.getCaller());
msg += "\n" + tcr.renderAsText() + "\n";
}
document.add(new Paragraph(msg));
document.add(new Paragraph(" "));
List comments = m_cc.getComments();
Collections.sort(comments, new CommentComparator());
IComment c = null;
PdfPTable table = new PdfPTable(1);
table.setWidthPercentage(100f);
PdfPCell cp = null;
Paragraph pp = null;
Color iterateColor1 = new Color(0xDD, 0xDD, 0xDD);
Color iterateColor2 = new Color(0xFF, 0xFF, 0xFF);
for (int i = 0; i < comments.size(); i++) {
cp = new PdfPCell();
cp.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
pp = new Paragraph();
Paragraph p = new Paragraph();
c = (IComment) comments.get(i);
IAttribute att = c.getAttributes().get(IComment.COMMENT_ATTRIBUTE_SUBJECT);
if (att != null && att.getValue().length() > 0) {
p.add(new Chunk(this.getI18nManager().getString(getNamespce(), "pdfsubject", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 14f, Font.BOLD)));
p.add(new Chunk(att.getValue(), FontFactory.getFont(FontFactory.HELVETICA, 14f, Font.BOLD)));
pp.add(p);
p = new Paragraph();
}
p.add(new Chunk(this.getI18nManager().getString(getNamespce(), "pdfdate", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD)));
p.add(new Chunk(getFormatter().parse(IJAMConst.GLOBAL_VARIABLE_CALLTIME, c.getDate())));
pp.add(p);
p = new Paragraph();
p.add(new Chunk(this.getI18nManager().getString(getNamespce(), "pdfstatus", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD)));
p.add(new Chunk(c.getAttributes().get(IComment.COMMENT_ATTRIBUTE_STATUS).getValue()));
pp.add(p);
att = c.getAttributes().get(IComment.COMMENT_ATTRIBUTE_FOLLOWUP);
if (att != null && att.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_YES)) {
p = new Paragraph();
Chunk cu = new Chunk(this.getI18nManager().getString(getNamespce(), "pdffollowup", "label", getLanguage()), FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD));
cu.setBackground(new Color(0xFF, 0xFF, 0x00));
p.add(cu);
pp.add(p);
}
pp.add(new Paragraph(" "));
p = new Paragraph(c.getText());
pp.add(p);
cp.addElement(pp);
table.addCell(cp);
}
document.add(table);
} catch (DocumentException de) {
this.m_logger.severe(de.getMessage());
} catch (IOException ioe) {
this.m_logger.severe(ioe.getMessage());
} finally {
document.close();
}
}
use of com.lowagie.text.Paragraph in project mdw-designer by CenturyLinkCloud.
the class ExportHelper method printBoldParagraphsPdf.
private void printBoldParagraphsPdf(Section section, String content) {
if (content == null || content.length() == 0)
return;
String[] details = content.split("\n");
String tmp = null;
for (int j = 0; j < details.length; j++) {
if (details[j].length() == 0) {
if (tmp != null)
section.add(new Paragraph(tmp + "\n", boldFont));
tmp = null;
} else if (tmp == null) {
tmp = details[j];
} else {
tmp += " " + details[j];
}
}
if (tmp != null) {
section.add(new Paragraph(tmp + "\n", boldFont));
}
}
use of com.lowagie.text.Paragraph in project mdw-designer by CenturyLinkCloud.
the class ExportHelper method printElementHtml.
private void printElementHtml(Element element, Object parent, int depth, Font font, int parentLevel) {
String tag = element.getName();
Object av;
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);
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();
float size = fontsize == null ? font.getSize() : (Float.parseFloat(fontsize) + 9);
int style = font.getStyle();
Color color;
if (fontcolor != null) {
color = Color.decode(fontcolor);
} else
color = font.getColor();
font = FontFactory.getFont(fontfamily, size, style, color);
}
if (parent instanceof Paragraph) {
((Paragraph) parent).add(new Chunk(content, font));
} else {
System.err.println("chunk with parent " + (parent == null ? "null" : parent.getClass().getName()) + ": " + content);
}
} catch (BadLocationException e) {
e.printStackTrace();
}
} else if (element instanceof HTMLDocument.BlockElement) {
HTMLDocument.BlockElement be = (HTMLDocument.BlockElement) element;
printAttributesHtml(be);
av = be.getAttribute(javax.swing.text.html.HTML.Attribute.ALIGN);
String align = av == null ? null : av.toString();
if ("html".equalsIgnoreCase(tag)) {
printElementChildrenHtml(element, parent, depth + 1, font, parentLevel);
} else if ("head".equalsIgnoreCase(tag)) {
// do nothing
} else if ("body".equalsIgnoreCase(tag)) {
printElementChildrenHtml(element, parent, depth + 1, font, parentLevel);
} else if ("p".equalsIgnoreCase(tag)) {
if (parent instanceof Section) {
Paragraph paragraph = new Paragraph();
if (align != null) {
paragraph.setAlignment(align);
}
printElementChildrenHtml(element, paragraph, depth + 1, normalFont, parentLevel);
((Section) parent).add(paragraph);
} else {
System.err.println("p with parent " + (parent == null ? "null" : parent.getClass().getName()));
}
} else if ("h1".equalsIgnoreCase(tag) || "h2".equalsIgnoreCase(tag) || "h3".equalsIgnoreCase(tag)) {
if (parent instanceof Section) {
Paragraph title = new Paragraph();
printElementChildrenHtml(element, title, depth + 1, subSectionFont, parentLevel);
((Section) parent).addSection(title, parentLevel == 0 ? 0 : (parentLevel + 1));
} else {
System.err.println("list with parent " + (parent == null ? "null" : parent.getClass().getName()));
}
} else if ("ul".equalsIgnoreCase(tag)) {
if (parent instanceof Section) {
com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f);
printElementChildrenHtml(element, list, depth + 1, normalFont, parentLevel);
((Section) parent).add(list);
} else {
System.err.println("list with parent " + (parent == null ? "null" : parent.getClass().getName()));
}
} else if ("ol".equalsIgnoreCase(tag)) {
if (parent instanceof Section) {
com.lowagie.text.List list = new com.lowagie.text.List(true, false, 20.0f);
printElementChildrenHtml(element, list, depth + 1, normalFont, parentLevel);
((Section) parent).add(list);
} else {
System.err.println("list with parent " + (parent == null ? "null" : parent.getClass().getName()));
}
} else if ("li".equalsIgnoreCase(tag)) {
ListItem li = new ListItem();
li.setSpacingAfter(0.0f);
printElementChildrenHtml(element, li, depth + 1, normalFont, parentLevel);
((com.lowagie.text.List) parent).add(li);
} else if ("p-implied".equalsIgnoreCase(tag)) {
if (parent instanceof ListItem) {
Paragraph paragraph = new Paragraph();
printElementChildrenHtml(element, paragraph, depth + 1, normalFont, parentLevel);
((ListItem) parent).add(paragraph);
} else if (parent instanceof Cell) {
Paragraph paragraph = new Paragraph();
printElementChildrenHtml(element, paragraph, depth + 1, normalFont, parentLevel);
((Cell) parent).add(paragraph);
}
} else if ("table".equalsIgnoreCase(tag)) {
try {
Table table = new Table(3);
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(3);
table.addCell(c);
table.endHeaders();
printElementChildrenHtml(element, table, depth + 1, normalFont, parentLevel);
((Section) parent).add(table);
} catch (BadElementException e) {
e.printStackTrace();
}
} else if ("tr".equalsIgnoreCase(tag)) {
printElementChildrenHtml(element, parent, depth + 1, normalFont, parentLevel);
} else if ("td".equalsIgnoreCase(tag)) {
Cell cell = new Cell();
printElementChildrenHtml(element, cell, depth + 1, normalFont, parentLevel);
((Table) parent).addCell(cell);
} else {
System.err.println("Unknown element " + element.getName());
printElementChildrenHtml(element, parent, depth + 1, normalFont, parentLevel);
}
} else {
// could be BidiElement - not sure what it is
return;
}
}
Aggregations