use of com.lowagie.text.Phrase 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.Phrase in project mdw-designer by CenturyLinkCloud.
the class ExportHelper method printAttributesPdf.
private void printAttributesPdf(Section section, List<AttributeVO> attrs, int parentLevel) {
Paragraph sTitle = new Paragraph("Activity Attributes", subSectionFont);
Section subsection = section.addSection(sTitle, parentLevel == 0 ? 0 : (parentLevel + 1));
com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f);
for (AttributeVO attr : attrs) {
if (excludeAttribute(attr.getAttributeName(), attr.getAttributeValue()))
continue;
Phrase phrase = new Phrase();
phrase.add(new Chunk(attr.getAttributeName(), fixedWidthFont));
String v = attr.getAttributeValue();
if (v == null)
v = "";
phrase.add(new Chunk(": " + v, normalFont));
list.add(new ListItem(phrase));
}
subsection.add(list);
}
use of com.lowagie.text.Phrase in project vcell by virtualcell.
the class ITextWriter method writeGeom.
// Section used can be a chapter or a section of one, based on the document type.
protected void writeGeom(Section container, Geometry geom, GeometryContext geomCont) throws Exception {
try {
Section geomSection = container.addSection("Geometry: " + geom.getName(), container.numberDepth() + 1);
if (geom.getDimension() == 0) {
Paragraph p = new Paragraph(new Phrase("Non spatial geometry."));
p.setAlignment(Paragraph.ALIGN_CENTER);
geomSection.add(p);
return;
}
ByteArrayOutputStream bos = generateGeometryImage(geom);
com.lowagie.text.Image geomImage = com.lowagie.text.Image.getInstance(java.awt.Toolkit.getDefaultToolkit().createImage(bos.toByteArray()), null);
geomImage.setAlignment(Table.ALIGN_LEFT);
geomSection.add(geomImage);
// addImage(geomSection, bos);
Table geomTable = getTable(2, 50, 1, 2, 2);
geomTable.setAlignment(Table.ALIGN_LEFT);
Extent extent = geom.getExtent();
String extentStr = "(" + extent.getX() + ", " + extent.getY() + ", " + extent.getZ() + ")";
Origin origin = geom.getOrigin();
String originStr = "(" + origin.getX() + ", " + origin.getY() + ", " + origin.getZ() + ")";
geomTable.addCell(createCell("Size", getFont()));
geomTable.addCell(createCell(extentStr, getFont()));
geomTable.addCell(createCell("Origin", getFont()));
geomTable.addCell(createCell(originStr, getFont()));
geomSection.add(geomTable);
} catch (Exception e) {
System.err.println("Unable to add geometry image to report.");
e.printStackTrace();
}
}
use of com.lowagie.text.Phrase in project vcell by virtualcell.
the class PDFWriter method writeHeaderFooter.
protected void writeHeaderFooter(String headerStr) throws DocumentException {
/*Paragraph headerParagraph = new Paragraph(headerStr);
headerParagraph.add(" (produced by ");
com.lowagie.text.Anchor vcLink = new com.lowagie.text.Anchor("The Virtual Cell");
vcLink.setReference("http://www.nrcam.uchc.edu");
headerParagraph.add(vcLink);
headerParagraph.add(")");
*/
if (headerStr.trim().length() > 0) {
HeaderFooter headerFooter = new HeaderFooter(new Phrase(headerStr), false);
headerFooter.setBorder(Rectangle.BOTTOM);
document.setHeader(headerFooter);
}
HeaderFooter headerFooter = new HeaderFooter(new Phrase("Page "), true);
headerFooter.setBorder(Rectangle.TOP);
document.setFooter(headerFooter);
}
use of com.lowagie.text.Phrase in project drools by kiegroup.
the class EndPage method onEndPage.
public void onEndPage(PdfWriter writer, Document document) {
try {
// TODO this image never existed
Image image = Image.getInstance(DroolsDocsBuilder.class.getResource("guvnor-webapp.png"));
image.setAlignment(Image.RIGHT);
image.scaleAbsolute(100, 30);
Rectangle page = document.getPageSize();
PdfPTable head = new PdfPTable(2);
PdfPCell cell1 = new PdfPCell(image);
cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
cell1.setBorder(0);
head.addCell(cell1);
PdfPCell cell2 = new PdfPCell(new Phrase(currentDate, DroolsDocsComponentFactory.HEADER_FOOTER_TEXT));
cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
cell2.setBorder(0);
head.addCell(cell2);
head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());
} catch (Exception e) {
throw new ExceptionConverter(e);
}
}
Aggregations