请参阅:java : pdfbox 读取 PDF文件内书签
请注意:书的目录.txt 编码:UTF-8,推荐用Notepad++ 转换编码。
npm installelementtree ;
npm install xml2js ;
node.js 用 elementtree读目录.txt文件,用 xml2js 转换为json数据,ejs 生成 jstree模板所需的文件。
编写 txt_etree_json.js 如下
// 读目录.txt文件,用xml2js 转换为json数据,生成jstree所需的文件
let fs = require('fs');
let process = require('process');
let path = require('path');
let readline = require('readline');
let et = require('elementtree');
let XML = et.XML;
let ElementTree = et.ElementTree;
// element = et.Element;
let subElement = et.SubElement;
let xml2js = require('xml2js');
let ejs = require('ejs');
if (process.argv.length 0 && line.slice(0,1) !=' '){
// 创建主题的子节点(1级节点)
node1 = subElement(root, "children");
node1.set('id', String(ln));
node1.set('text', txt);
p_node = node1; // 寄存父节点
}
else if (line.startsWith(indent1) && line.slice(2,3) !=' '){
// 创建node1的子节点(2级节点)
if (node1) node2 = subElement(node1, "children");
else node2 = subElement(root, "children");
node2.set('id', String(ln));
node2.set('text', txt);
p_node = node2;
}
else if (line.startsWith(indent2) && line.slice(4,5) !=' '){
// 创建node2的子节点(3级节点)
if (node2) node3 服务器托管网= subElement(node2, "children");
else if(node1) node3 = subElement(node1, "children");
else node3 = subElement(root, "children");
node3.set('id', String(ln));
node3.set('text', txt);
p_node = node3;
}
else if (line.startsWith(indent3) && line.slice(6,7) !=' '){
// 创建node3的子节点(4级节点)
if (node3) node4 = subElement(node3, "children");
else if (node2) node4 = subElement(node2, "children");
else if (node1) node4 = subElement(node1, "children");
else node4 = subElement(root, "children");
node4.set('id', String(ln));
node4.set('text', txt);
p_node = node4;
}
else if (line.startsWith(indent4) && line.slice(8,9) !=' '){
// 创建node4的子节点(5级节点)
if (node4) node5 = subElement(node4, "children");
else if (p_node) node5 = subElement(p_node, "children");
else node5 = subElement(root, "children");
node5.set('id', String(ln));
node5.set('text', txt);
}
else {
console.log(txt);
}
ln++;
});
// 官网 www.npmjs.com/package/xml2js 查找 Options
// Parser 用于解析xml为json对象
let parser = new xml2js.Parser({explicitArray:false, mergeAttrs:true});
var etree, xml, json_str;
let filename ="jstree_template.htm";
rline.on('close', function(){
etree = new ElementTree(root);
xml = etree.write({'xml_declaration': false});
parser.parseString(xml, function(err,res){
if (err) throw err;
//console.dir(res);
json_str = '['+ JSON.stringify(res['node'], null,2) +']';
})服务器托管网;
// 官网 ejs.bootcss.com/#docs
//ejs.renderFile(filename, data, options, function(err, str){
ejs.renderFile(filename, {title:title, mydir:json_str}, {}, function(err, str){
// str => 输出渲染后的 HTML 字符串
fWrite.write(str);
});
console.log("line number: "+ln);
});
https://gitee.com/ 搜索 jstree 下载
https://gitee.com/mirrors/jstree?_from=gitee_search
git clone https://gitee.com/mirrors/jstree.git
编写jstree_template.htm 如下
var mydir = ;
$("#treeview1").jstree({
'core' : {
"multiple" : false,
'data' : mydir,
'dblclick_toggle': true
},
"plugins" : ["search"]
});
//输入框输入时自动搜索
var tout = false;
$('#search_a').keyup(function(){
if (tout) clearTimeout(tout);
tout = setTimeout(function(){
$('#treeview1').jstree(true).search($('#search_a').val());
}, 250);
});
运行node txt_etree_json.js your_pdf_dir.txt
生成your_pdf_dir.htm
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
1.登录paypal开发者中心, 2. 选择Apps & Credentials点击Create App创建应用,创建后点击编辑按钮,如图: 3.进入应用详情,勾选Log in with PayPal点击Advanced Settings添加retur…