use of com.lowagie.text.Paragraph in project activityinfo by bedatadriven.
the class ThemeHelper method legendText.
public static Paragraph legendText(String text) {
Paragraph para = new Paragraph();
para.setFont(bodyFont());
return para;
}
use of com.lowagie.text.Paragraph 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;
}
use of com.lowagie.text.Paragraph in project janrufmonitor by tbrandt77.
the class PDFFilter method doExport.
public boolean doExport() {
Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
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.journal.Journal", "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.journal.Journal", "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);
}
ICall c = null;
String cellContent = null;
for (int i = 0, j = this.m_callList.size(); i < j; i++) {
c = this.m_callList.get(i);
for (int k = 0, m = renderer.size(); k < m; k++) {
t = (ITableCellRenderer) renderer.get(k);
t.updateData(c);
cellContent = t.renderAsText();
if (cellContent != null && cellContent.length() > 0) {
table.addCell(cellContent);
} else {
cellContent = t.renderAsImageID();
if (cellContent != null && cellContent.length() > 0) {
try {
if (cellContent.startsWith("db://")) {
InputStream in = ImageHandler.getInstance().getImageStream(c.getCaller());
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);
}
} catch (IOException e) {
this.m_logger.severe(e.getMessage());
table.addCell(" ");
}
} else
table.addCell(" ");
}
}
}
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 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;
}
use of com.lowagie.text.Paragraph in project mdw-designer by CenturyLinkCloud.
the class ExportHelper method printOneProcessPdf.
private Chapter printOneProcessPdf(DocWriter writer, DesignerCanvas canvas, String type, int chapterNumber, Graph process, String filename, Rectangle page_size) throws Exception {
Paragraph cTitle = new Paragraph("Workflow Process: \"" + process.getName() + "\"", chapterFont);
Chapter chapter = new Chapter(cTitle, chapterNumber);
// print image
printGraphPdf(writer, canvas, process, page_size, type, filename, chapter, chapterNumber);
// print documentation text
printGraphPdf(process, chapter);
for (Node node : process.getNodes(nodeIdType)) {
printNodePdf(node, chapter);
}
for (SubGraph subgraph : process.getSubgraphs(nodeIdType)) {
printGraphPdf(subgraph, chapter);
for (Node node : subgraph.getNodes(nodeIdType)) {
printNodePdf(node, chapter);
}
}
if (options.contains(VARIABLES)) {
printVariablesPdf(chapter, process.getProcessVO().getVariables(), options.contains(SECTION_NUMBER) ? 1 : 0);
}
return chapter;
}
Aggregations