use of com.lowagie.text.DocWriter in project activityinfo by bedatadriven.
the class ItextReportRenderer method render.
@Override
public void render(ReportElement element, OutputStream os) throws IOException {
try {
Document document = new Document();
DocWriter writer = createWriter(document, os);
document.open();
renderFooter(document);
if (element instanceof Report) {
renderReport(writer, document, element);
} else {
renderElement(writer, document, element);
}
document.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.lowagie.text.DocWriter 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.lowagie.text.DocWriter in project mdw-designer by CenturyLinkCloud.
the class ExportHelper method exportProcesses.
/**
* Export multiple processes
*
* @param filename
* the file name (including path) where the document will be
* generated
* @param type
* can be pdf, rtf and html
* @param flowchart
* the designer page (for using its canvas and report errors)
* @param graphs
* the list of processes to be printed.
* @param options
* options for printing, from the print dialog.
*/
public void exportProcesses(String filename, String type, FlowchartPage flowchart, List<Graph> graphs) throws Exception {
initialize(false);
options.add(SECTION_NUMBER);
// step 1: creation of a document-object
Document document = new Document();
try {
// step 2: create PDF or RTF writer
DocWriter writer;
if (type.equals(RTF)) {
writer = RtfWriter2.getInstance(document, new FileOutputStream(filename));
} else if (type.equals(PDF)) {
writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
} else {
StringBuilder sb = printPrologHtml("Processes");
Graph process;
for (int i = 0; i < graphs.size(); i++) {
process = graphs.get(i);
flowchart.setProcess(process);
this.printProcessHtml(sb, flowchart.canvas, i + 1, process, filename);
}
printEpilogHtml(sb, filename);
return;
}
// step 3: we open the document
document.open();
// step 4: we add contents to the document
document.setPageSize(PageSize.LETTER);
Graph process;
Chapter chapter;
Rectangle pageSize = document.getPageSize();
for (int i = 0; i < graphs.size(); i++) {
process = graphs.get(i);
process.setNodeIdType(nodeIdType);
flowchart.setProcess(process);
chapter = printOneProcessPdf(writer, flowchart.canvas, type, i + 1, process, filename, pageSize);
document.add(chapter);
}
} finally {
// step 5: we close the document
document.close();
}
}
use of com.lowagie.text.DocWriter in project mdw-designer by CenturyLinkCloud.
the class ExportHelper method printImagePdf.
public void printImagePdf(String filename, DesignerCanvas canvas, Dimension graphsize) {
try {
DefaultFontMapper mapper = new DefaultFontMapper();
FontFactory.registerDirectories();
mapper.insertDirectory("c:\\winnt\\fonts");
// we create a template and a Graphics2D object that corresponds
// with it
// 1 inch
int margin = 72;
float scale = 0.5f;
Rectangle pageSize;
pageSize = PageSize.LETTER.rotate();
Document document = new Document(pageSize);
DocWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
document.open();
document.setPageSize(pageSize);
int imageW = (int) pageSize.getWidth() - margin;
int imageH = (int) pageSize.getHeight() - margin;
boolean edsave = canvas.editable;
canvas.editable = false;
Color bgsave = canvas.getBackground();
canvas.setBackground(Color.white);
int horizontalPages = (int) (graphsize.width * scale) / imageW + 1;
int verticalPages = (int) (graphsize.height * scale) / imageH + 1;
for (int i = 0; i < horizontalPages; i++) {
for (int j = 0; j < verticalPages; j++) {
Image img;
PdfContentByte cb = ((PdfWriter) writer).getDirectContent();
PdfTemplate tp = cb.createTemplate(imageW, imageH);
Graphics2D g2 = tp.createGraphics(imageW, imageH, mapper);
tp.setWidth(imageW);
tp.setHeight(imageH);
g2.scale(scale, scale);
g2.translate(-i * imageW / scale, -j * imageH / scale);
canvas.paintComponent(g2);
g2.dispose();
img = new ImgTemplate(tp);
document.add(img);
}
}
canvas.setBackground(bgsave);
canvas.editable = edsave;
document.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations