Javascript 如何从Cordova/Phonegap中的index.html生成PDF
我正在使用Cordova/Phonegap和PDF生成器插件构建一个应用程序,用于将文件的HTML转换为可在客户端保存的PDF 因为我对Javascript还是相当陌生,所以我一直在使用示例。现在,我可以指定一个特定的网页,并从网页的HTML中生成PDF 但是,我希望对index.html页面而不是外部URL执行此操作。我想要同样的东西,但是我的index.html文件在应用程序中 我严格按照示例操作,并将index.js文件更改为以下内容:Javascript 如何从Cordova/Phonegap中的index.html生成PDF,javascript,android,cordova,pdf,phonegap,Javascript,Android,Cordova,Pdf,Phonegap,我正在使用Cordova/Phonegap和PDF生成器插件构建一个应用程序,用于将文件的HTML转换为可在客户端保存的PDF 因为我对Javascript还是相当陌生,所以我一直在使用示例。现在,我可以指定一个特定的网页,并从网页的HTML中生成PDF 但是,我希望对index.html页面而不是外部URL执行此操作。我想要同样的东西,但是我的index.html文件在应用程序中 我严格按照示例操作,并将index.js文件更改为以下内容: var app = { // Applica
var app = {
// Application Constructor
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
// deviceready Event Handler
//
// Bind any cordova events here. Common events are:
// 'pause', 'resume', etc.
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
// Our code start here
var opts = {
type: "share", //Open a context menu and ask the user what to do next (print, mail, etc..).
fileName: 'v8-tutorial.pdf' //it will use this filename as a place-holder
}
// http://cesarvr.github.io/2015/11/20/javascript-v8.html
pdf.fromURL('https://www.sheldonbrown.com/web_sample1.html', opts)
.then((status) => console.log('success->', status))
.catch((error) => console.log(error));
// End here
console.log('Received Event: ' + id);
}
};
app.initialize();
每当我在Android仿真器中用应用程序的其余部分测试上述代码时,我都能够从Javascript中的特定URL生成pdf,但我需要它来处理给定的文件——在本例中是my index.html
我相信我所需要做的就是更改行pdf.fromURL('https://www.sheldonbrown.com/web_sample1.html,opts)
从文件而不是URL生成pdf,但我无法获得正确的语法。任何建议都将不胜感激