Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
122
rated 0 times [  126] [ 4]  / answers: 1 / hits: 42215  / 11 Years ago, thu, september 26, 2013, 12:00:00

I have a ticket booking system in Joomla.



When user clicks on ticket link a ticket is shown on the site.



I am using a barcode.php file to generate the barcode image for ticket number.



Now there are 2 scenarios I used to print ticket.




  1. When I print that ticket using window.print() or Ctrl+P, 2 pages get printed
    even though my ticket content is only single page.


  2. When I use following javascript code to print specific part of the page, barcode image is not generated.



    function print_specific_div_content(){
    var content = <html>;
    content += document.getElementById(divToPrint).innerHTML ;
    content += </body>;
    content += </html>;

    var printWin = window.open('','','left=0,top=0,width=552,height=477,toolbar=0,scrollbars=0,status =0');
    printWin.document.write(content);
    printWin.document.close();
    printWin.focus();
    printWin.print();
    printWin.close();
    }



My requirements are:



Ticket should be printed only on single page.



Any help or suggestion will be appreciated.



Thanks.



EDIT 1 :



I modified my function as follow, but unfortunately it shows new window but no print dialog. :(



function print_specific_div_content(){
var win = window.open('','','left=0,top=0,width=552,height=477,toolbar=0,scrollbars=0,status =0');
var handler = function() {
win.print();
win.close();
};
if(win.addEventListener)
win.addEventListener('load', handler, false);
else if(win.attachEvent)
win.attachEvent('onload', handler, false);

var content = <html>;
content += document.getElementById(divToPrint).innerHTML ;
content += </body>;
content += </html>;
win.document.write(content);
win.document.close();
}

More From » php

 Answers
6

When printing just the content, you need to wait for the document to load before printing so that the images will be loaded:



function print_specific_div_content(){
var win = window.open('','','left=0,top=0,width=552,height=477,toolbar=0,scrollbars=0,status =0');

var content = <html>;
content += <body onload=window.print(); window.close();>;
content += document.getElementById(divToPrint).innerHTML ;
content += </body>;
content += </html>;
win.document.write(content);
win.document.close();
}

[#75405] Wednesday, September 25, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
averyc

Total Points: 102
Total Questions: 113
Total Answers: 89

Location: Taiwan
Member since Mon, Sep 6, 2021
3 Years ago
;