Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从Cordova/Phonegap中的index.html生成PDF_Javascript_Android_Cordova_Pdf_Phonegap - Fatal编程技术网

Javascript 如何从Cordova/Phonegap中的index.html生成PDF

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

我正在使用Cordova/Phonegap和PDF生成器插件构建一个应用程序,用于将文件的HTML转换为可在客户端保存的PDF

因为我对Javascript还是相当陌生,所以我一直在使用示例。现在,我可以指定一个特定的网页,并从网页的HTML中生成PDF

但是,我希望对index.html页面而不是外部URL执行此操作。我想要同样的东西,但是我的index.html文件在应用程序中

我严格按照示例操作,并将index.js文件更改为以下内容:

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,但我无法获得正确的语法。任何建议都将不胜感激