Define the functions to translate the tree data.
function translateTreeData(children, depth){
depth = depth || 0;
if (!children || !children.length){return []}
var rows = [];
$.map(children, function(item){
var node = {text:item.text,depth:depth};
rows.push(node);
rows = rows.concat(translateTreeData(item.children, depth+1));
});
return rows;
}
function toArray(rows){
var body = [];
for(var i=0; i<rows.length; i++){
var row = rows[i];
var text = row.text;
for(var j=0; j<row.depth; j++){
text = '-' + text;
}
var item = [text];
body.push(item);
}
return body;
}
Use the pdfmake to export pdf.
var roots = $('#tt').tree('getRoots');
var rows = translateTreeData(roots);
var body = toArray(rows);
var docDefinition = {
content: [{
table: {
headerRows: 0,
widths: ['*'],
body: body
}
}]
};
pdfMake.createPdf(docDefinition).open();