Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'PrintPlugin' of undefined" cordova print plugin #13

Open
marth1 opened this issue Jan 12, 2016 · 5 comments

Comments

@marth1
Copy link

marth1 commented Jan 12, 2016

setTimeout(function(){
var type = "text/html";
var title = "test.html";
var fileContent = "Phonegap Print Plugin";
window.plugins.PrintPlugin.print(fileContent,function(){console.log('success')},function(){console.log('fail')},"",type,title);
}, 2000);

@mohamed-salah
Copy link
Owner

you sure run it after device ready
and can you tell me which platform android or ios you use and witch version of them

@marth1
Copy link
Author

marth1 commented Jan 13, 2016

var html = document.getElementById('printssss').innerHTML;
var result=html.replace(/"/g, ''');

                        var type = "text/html";
                        var title = "print.html";
                        window.plugins.PrintPlugin.print(result, function() 
                        {
                              cordova.plugin.pDialog.dismiss();
                        }, function() {
                                console.log('fail')
                        }, "", type, title);

some times working fine and some times am getting error like.... "Uncaught TypeError: Cannot read property 'PrintPlugin' of undefined"

@marth1
Copy link
Author

marth1 commented Jan 13, 2016

4.0 and above versions of android devices

@marth1
Copy link
Author

marth1 commented Jan 13, 2016

    var html = document.getElementById('printssss').innerHTML;
                        var result=html.replace(/"/g, '\'');


                    setTimeout(function()
                    {
                        var type = "text/html";
                        var title = "Print.html";
                        var fileContent=result+"<style>.dtls_order .dtls_order_table .table { margin: 0 0 20px 0; padding: 0px; border-bottom: 1px solid #eeeeee; color: #000000;width: 100%;margin: 0 0 20px 0;padding: 0px;font-size:13px; cellpadding:0; cellspacing:0; }.dtls_order .dtls_order_table .table thead { background: #eee; }.printpage_body{ background: #fff; color: #000 !important; position: fixed; top: 0px; left: 0px; width: 100%; height: 100%; z-index: 9; overflow-y: scroll; } .printpage_body .contentWrap{ padding:20px 10px; } .printpage{ width:100%; height:auto; float:left; } .printHeader{  width: 100%; padding: 15px; border-bottom: 1px solid #eee; } .printHeader .rt_acts{ position: absolute;  top: 10px; font-size: 20px; border: 1px solid #d03e43; border-radius: 100%; width: 28px; height: 28px; } .printHeader .rt_acts .ic_cls{  color: #d03e43; padding: 3px 0px; margin-right: -1px; } .printHeader .rest_head{  width:100%; text-align:center; padding: 0 15%; } .printHeader .rest_head .rest_name{ text-align:center;font-size: 16px; color: #d03e43; margin: 0 0 5px 0; padding: 0px; } .printHeader .rest_head .rest_adres{ text-align:center;font-size: 12px; color: #666; margin: 0px; padding: 0px; font-family: 'Roboto', Arial, sans-serif; line-height:18px; } .dtlsoftin{ width:100%; float:left; height:auto; } .dtlsoftin .dtls_row{ width:100%; float:left; margin-bottom: 10px; } .dtlsoftin .dtls_row li{ width:auto; float:left; padding:0 20px 0 0; margin:0px; list-style:none; font-weight:bold; } .dtlsoftin .dtls_row li span{ margin-left:5px; font-weight:normal; } .dtlsoftin .dtls_3{ width:100%; float:left; } .dtlsoftin .custmerAdres{ width:100%; float:left; margin-bottom: 10px; } .dtlsoftin .custmerAdres .rd{ color: #d03e43; } .dtls_order{ width:100%; float:left; height:auto; } .dtls_order .dtls_order_h1{ font-size: 14px; color: #d03e43; margin: 0 0 5px 0; padding: 0px; text-align:center; } .dtls_order .dtls_order_table{ width:100%; float:left; height:auto; margin-top: 10px; } .dtls_order .dtls_order_table .table{ margin:0 0 20px 0; padding:0px; border-bottom: 1px solid #eeeeee; color:#000000; } .dtls_order .dtls_order_table .table thead{ background:#eee; } .dtls_order .dtls_order_table .table tbody{ font-size:13px; } .dtls_order .dtls_order_total_wrap{ width:100%; float:right; height:auto; } .dtls_order .dtls_order_total_wrap table{ color:#000000; } .dtls_order .dtls_order_total_wrap .td_1{ width:35%; } .dtls_order .dtls_order_total_wrap .td_2{ width:65%; } .dtls_order .dtls_order_total{ width:100%; float:right; height:auto; font-size:13px; } .dtls_order .dtls_order_total li{ width:100%; float:left; padding:0 0 5px 0; margin:0px; list-style:none; font-weight:normal; } .dtls_order .dtls_order_total li span{ margin-left:5px; font-weight:bold; float:right; } .dtls_order .dtls_order_total hr{ float: left; width: 100%; margin-top: 10px; margin-bottom: 10px; border: 0; border-top: 1px solid #eeeeee; } .dtls_order .dtls_order_ftr{ width:100%; float:left; margin-top: 10px; }#orderstable{ margin: 0 0 20px 0; padding: 0px; border-bottom: 1px solid #eeeeee; color: #000000;width: 100%;margin: 0 0 20px 0;padding: 0px;font-size:13px; cellpadding:0; cellspacing:0; }#trhead{background: #eee;}.thheads{width:10%;vertical-align: bottom;border-bottom: 1px solid #dddddd;padding: 7px 0px;}#count{width:10%}#descript{width:25%}#itemprice{width:20%}#qaty{width:10%}#percetage{width:15%}#pricess{width:20%;}</style>";

                        window.plugins.PrintPlugin.print(fileContent,function()
                        {
                            console.log('success')
                        },function()
                        {
                            console.log('fail')},"",type,title);
                        }, 

                    2000);

Here is my code am printing div content through printer but some times working fine and some times am getting error like.... "Uncaught TypeError: Cannot read property 'PrintPlugin' of undefined"....please resolve this issue...

@mohamed-salah
Copy link
Owner

mohamed-salah commented May 17, 2016

sorry to be very late
I think your main problem with deviceready event
can you just add your code after deviceready
like that
`
document.addEventListener('deviceready', function(){

var html = document.getElementById('printssss').innerHTML;
var type = "text/html";
var title = "Print.html";
var fileContent = html.replace(/"/g, '\'');
window.plugins.PrintPlugin.print(fileContent,
    function(){
        console.log('success')
    },function(){
        console.log('fail')
    },"",type,title);

}, false);
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants