1

I have two texts and i want to print them on two different pages, this is what i did so far :

The button print :

<button onclick="javascript : CallPrint('idText1','idText2')" type="button">Print</button>

callPrint JavaScript method :

<script language="javascript" type="text/javascript">
    function CallPrint(firstText,secondText) {
        var firstContent = document.getElementById(firstText);
        var secondContent = document.getElementById(secondText);
        var WinPrint = window.open('', '', 'letf=0,top=0,width=1200,height=750,toolbar=0,scrollbars=0,status=0,dir=ltr');
        WinPrint.document.write(firstContent.innerHTML);
        WinPrint.document.write(secondContent.innerHTML);
        WinPrint.document.close();
        WinPrint.focus();
        WinPrint.print();
        WinPrint.close();
    }
</script>

The problem is, they are printed one after the other. How is it possible to separate them on two different pages (without using br tags). If it is not possible, i wanna know if it is possible to show two print windows instead of one.

2
  • 1
    to separate them on two different pages - CSS page breaks Commented Dec 23, 2016 at 10:54
  • 1
    Have a look at the page-break-after page-break-before page-break-inside css properties and put them inside a @print css rule. There's some combination in there where you can force and element to always start a new page. Commented Dec 23, 2016 at 10:54

2 Answers 2

1

Add an empty paragraph with page-break-after: always style between the 2 texts:

WinPrint.document.write(firstContent.innerHTML);
WinPrint.document.write('<p style="page-break-after:always;"></p>');
WinPrint.document.write(secondContent.innerHTML);

Sign up to request clarification or add additional context in comments.

Comments

0

You have to open two windows in the function in order to seperate the contents in two files.

function CallPrint(firstText,secondText) {
        var firstContent = document.getElementById(firstText);
        var secondContent = document.getElementById(secondText);
        var WinPrint = window.open('', '', 'letf=0,top=0,width=1200,height=750,toolbar=0,scrollbars=0,status=0,dir=ltr');
        WinPrint.document.write(firstContent.innerHTML);
        var WinPrint2 = window.open('', '', 'letf=0,top=0,width=1200,height=750,toolbar=0,scrollbars=0,status=0,dir=ltr');
        WinPrint2.document.write(secondContent.innerHTML);

1 Comment

It did not work i've already tried it, i got an exception : cannot read property 'document' of undefined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.