use of com.centurylink.mdw.designer.utils.DocxBuilder in project mdw-designer by CenturyLinkCloud.
the class ExportHelper method exportProcess.
/**
* Export a process
*
* @param filename
* the file name (including path) where the document will be
* generated
* @param format
* can be docx, pdf, rtf, html and bpmn
* @param canvas
* for printing process images
* @param graph
* the process to be printed.
*/
public void exportProcess(String filename, String format, Graph process, DesignerCanvas canvas) throws Exception {
initialize(false);
String oldNodeIdType = process.getNodeIdType();
try {
process.setNodeIdType(nodeIdType);
options.add(SECTION_NUMBER);
if (format.equals(DOCX)) {
DocxBuilder builder = printProcessDocx(process, canvas);
builder.save(new java.io.File(filename));
return;
} else if (format.equals(HTML)) {
StringBuilder sb = printPrologHtml("Process " + process.getName());
printProcessHtml(sb, canvas, 0, process, filename);
printEpilogHtml(sb, filename);
return;
} else if (format.equals(JPG) || format.equals(PNG)) {
byte[] imgBytes = printImage(-1f, canvas, process.getGraphSize(), format.equals(JPG) ? "jpeg" : "png");
try (OutputStream os = new FileOutputStream(new File(filename))) {
os.write(imgBytes);
return;
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
}
} else if (format.equals(BPMN2)) {
new BPMNHelper().exportProcess(process.getProcessVO(), filename);
} else {
// itext processor
Document document = new Document();
try {
DocWriter writer = null;
if (format.equals(RTF)) {
writer = RtfWriter2.getInstance(document, new FileOutputStream(filename));
} else if (format.equals(PDF)) {
writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
}
document.open();
document.setPageSize(PageSize.LETTER);
Rectangle pageSize = document.getPageSize();
Chapter chapter = printOneProcessPdf(writer, canvas, format, 1, process, filename, pageSize);
document.add(chapter);
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
} finally {
// step 5: we close the document
document.close();
}
}
} finally {
process.setNodeIdType(oldNodeIdType);
}
}
use of com.centurylink.mdw.designer.utils.DocxBuilder in project mdw-designer by CenturyLinkCloud.
the class ExportHelper method printProcessDocx.
private DocxBuilder printProcessDocx(Graph process, DesignerCanvas canvas) throws Exception {
DocxBuilder builder = new DocxBuilder();
// title
String title = "Workflow: \"" + process.getName() + "\"";
builder.addParagraph("Heading1", title);
// process image
int zoomSave = process.zoom;
process.zoom = 100;
byte[] imgBytes = printImage(-1f, canvas, process.getGraphSize(), "png");
process.zoom = zoomSave;
builder.addImage(imgBytes);
printProcessBodyDocx(builder, process);
// embedded subprocesses
for (SubGraph subprocess : process.getSubgraphs(nodeIdType)) {
String id = subprocess.getDisplayId(nodeIdType);
String spTitle = "Embedded Subprocess " + id + ": \"" + subprocess.getName() + "\"";
builder.addParagraph("Heading1", spTitle);
printProcessBodyDocx(builder, subprocess);
}
// process variables
if (options.contains(VARIABLES)) {
List<VariableVO> variables = process.getProcessVO().getVariables();
if (variables != null && !variables.isEmpty()) {
builder.addParagraph("Heading2", "Process Variables");
String[] headers = new String[] { "Name", "Type", "Mode", "Description" };
String[][] values = new String[4][variables.size()];
for (int i = 0; i < variables.size(); i++) {
VariableVO var = variables.get(i);
values[0][i] = var.getName();
values[1][i] = var.getVariableType();
values[2][i] = VariableVO.VariableCategories[var.getVariableCategory()];
values[3][i] = var.getVariableReferredAs();
}
builder.addTable(headers, values, 11, 120);
}
}
return builder;
}
use of com.centurylink.mdw.designer.utils.DocxBuilder in project mdw-designer by CenturyLinkCloud.
the class ExportHelper method printHtmlParagraphsPdf.
private void printHtmlParagraphsPdf(Section section, String content, int parentLevel) throws Exception {
if (content == null || content.length() == 0)
return;
String vContent = content;
if (isBase64Encoded(content) || "true".equals(System.getProperty("mdw.designer.force.msword"))) {
byte[] docBytes = decodeBase64(content);
vContent = new DocxBuilder(docBytes).toHtml();
vContent = vContent.replaceAll(" ", " ");
}
JEditorPane documentation = new JEditorPane();
documentation.setContentType("text/html");
documentation.setText(vContent);
javax.swing.text.Document swingdoc = documentation.getDocument();
Element[] elements = swingdoc.getRootElements();
for (Element e : elements) {
Object gen = generateElementHtml(e, 0, normalFont);
addSectionContentPdf(section, gen, parentLevel);
}
}
Aggregations