use of com.centurylink.mdw.common.utilities.bpmn.BPMNHelper 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);
}
}
Aggregations