use of com.lowagie.text.Chunk in project charts by vaadin.
the class PdfExportDemo method createHeaderCell.
private PdfPCell createHeaderCell(String caption) throws BadElementException {
Chunk chunk = new Chunk(caption, captionFont);
Paragraph p = new Paragraph(chunk);
p.add(Chunk.NEWLINE);
p.add(Chunk.NEWLINE);
PdfPCell cell = new PdfPCell(p);
cell.setBorder(0);
cell.setBorderWidthBottom(1);
cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
return cell;
}
use of com.lowagie.text.Chunk 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.Chunk 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;
}
}
use of com.lowagie.text.Chunk 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.Chunk in project ofbiz-framework by apache.
the class PdfSurveyServices method buildPdfFromSurveyResponse.
/**
*/
public static Map<String, Object> buildPdfFromSurveyResponse(DispatchContext dctx, Map<String, ? extends Object> rcontext) {
Map<String, Object> context = UtilMisc.makeMapWritable(rcontext);
Delegator delegator = dctx.getDelegator();
Map<String, Object> results = ServiceUtil.returnSuccess();
String surveyResponseId = (String) context.get("surveyResponseId");
String contentId = (String) context.get("contentId");
String surveyId = null;
Document document = new Document();
try {
if (UtilValidate.isNotEmpty(surveyResponseId)) {
GenericValue surveyResponse = EntityQuery.use(delegator).from("SurveyResponse").where("surveyResponseId", surveyResponseId).queryOne();
if (surveyResponse != null) {
surveyId = surveyResponse.getString("surveyId");
}
}
if (UtilValidate.isNotEmpty(surveyId) && UtilValidate.isEmpty(contentId)) {
GenericValue survey = EntityQuery.use(delegator).from("Survey").where("surveyId", surveyId).queryOne();
if (survey != null) {
String acroFormContentId = survey.getString("acroFormContentId");
if (UtilValidate.isNotEmpty(acroFormContentId)) {
context.put("contentId", acroFormContentId);
}
}
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter.getInstance(document, baos);
List<GenericValue> responses = EntityQuery.use(delegator).from("SurveyResponseAnswer").where("surveyResponseId", surveyResponseId).queryList();
for (GenericValue surveyResponseAnswer : responses) {
String value = null;
String surveyQuestionId = (String) surveyResponseAnswer.get("surveyQuestionId");
GenericValue surveyQuestion = EntityQuery.use(delegator).from("SurveyQuestion").where("surveyQuestionId", surveyQuestionId).queryOne();
String questionType = surveyQuestion.getString("surveyQuestionTypeId");
// DEJ20060227 this isn't used, if needed in the future should get from SurveyQuestionAppl.externalFieldRef String fieldName = surveyQuestion.getString("description");
if ("OPTION".equals(questionType)) {
value = surveyResponseAnswer.getString("surveyOptionSeqId");
} else if ("BOOLEAN".equals(questionType)) {
value = surveyResponseAnswer.getString("booleanResponse");
} else if ("NUMBER_LONG".equals(questionType) || "NUMBER_CURRENCY".equals(questionType) || "NUMBER_FLOAT".equals(questionType)) {
Double num = surveyResponseAnswer.getDouble("numericResponse");
if (num != null) {
value = num.toString();
}
} else if ("SEPERATOR_LINE".equals(questionType) || "SEPERATOR_TEXT".equals(questionType)) {
// not really a question; ingore completely
} else {
value = surveyResponseAnswer.getString("textResponse");
}
Chunk chunk = new Chunk(surveyQuestion.getString("question") + ": " + value);
Paragraph p = new Paragraph(chunk);
document.add(p);
}
ByteBuffer outByteBuffer = ByteBuffer.wrap(baos.toByteArray());
results.put("outByteBuffer", outByteBuffer);
} catch (GenericEntityException | DocumentException e) {
Debug.logError(e, module);
results = ServiceUtil.returnError(e.getMessage());
}
return results;
}
Aggregations