Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Here is a function that prints my ASPX page on a click which works absolutely perfect .
XML
function PrintPanel() {
       debugger;
       var panel = document.getElementById("<%=Upnl1.ClientID %>");
       var printWindow = window.open(panel, '', 'height=600,width=900');
       printWindow.document.write('<html><head><title>DIV Contents</title>');

       printWindow.document.write('</head><body >');
       printWindow.document.write(panel.innerHTML);
       printWindow.document.write('</body></html>');
       printWindow.document.close();
       setTimeout(function () {
           printWindow.print();
       }, 1000);
       return false;
   }


But I want to simple thing which is where I am stuck. I want it to print in Landscape by default. Always Printer picks the Potrait. But I want to do this Landscape instead of user picking it , I prefer it to default to Landscape for this function alone.

Can someone help me with this please?
Posted
Comments
Afzaal Ahmad Zeeshan 18-Sep-15 16:47pm    
Increase the width and decrease the height. Create the document in that format, once that has been done (also make sure you are using pixels and not percentage values). User would have to print the document in landscape otherwise the data would be lost (unless his printer is smart enough to change the layout itself). :-)
sudevsu 21-Sep-15 9:22am    
This has helped me. Thank you

You can't select the default orientation from your javascript code. Code running inside the browser runs inside a restricted sandbox. The browser itself and all system resources are off-limits to your code.
 
Share this answer
 
Comments
sudevsu 21-Sep-15 9:22am    
Thank you
That's impossible :-)
what you could do, is "gently" force the user to print the output in landscape, by indeed adjusting the dimensions of your output-form. Nevertheless : a savvy user would still be able to circumvent this.
 
Share this answer
 
Comments
sudevsu 21-Sep-15 9:22am    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900