HOME

Friday, February 24, 2012

Set Printer defalut Font, font size, linespacing and letter spacing in JavaScript and ASP.NET


 function getPrint() {
   
        pp = window.open(); //Adding HTML opening tag with <HEAD> … </HEAD> portion
        pp.document.writeln('<HTML><HEAD><title>Issue Voucher</title>');
        pp.document.writeln('<base target="_self"></HEAD>'); //Adding Body Tag
        pp.document.writeln('<body bottomMargin="0"');
        pp.document.writeln('leftMargin="0" topMargin="0" rightMargin="0" >');
        pp.document.writeln('<form>'); //Creating two buttons Print and Close within a HTML table
        pp.document.writeln('<p id="par">');
     
        pp.document.writeln(document.getElementById('<%=DivPrint.ClientID %>').outerHTML);
//Ending Tag of
 </form>, </body> and </HTML>
     
        //Adding form Tag

        pp.document.writeln('</p>');

        for (i = 0; i < pp.document.all.length; i++) {
            pp.document.all[i].style.fontFamily = "Lucida Console,Script";
            pp.document.all[i].style.fontSize = 10;
            pp.document.all[i].style.lineHeight = 1.5;
            pp.document.all[i].style.fontStyle = "normal";
            pp.document.all[i].style.letterSpacing = "5px";
        }

        pp.document.writeln('</form></body></HTML>');

        pp.document.close();
        pp.focus();
        pp.print();
     
    }


where DivPrint is replace with your Print area

No comments:

Post a Comment