简体   繁体   中英

Change font family and font size to print

this is my Javascript

<script type="text/javascript">
            function printInfo(ele) {
              var openWindow = window.open();
              openWindow.document.write(ele.previousSibling.innerHTML,'');
              openWindow.document.body.setAttribute('style', 'font-family:Arial !important;');
              openWindow.document.body.setAttribute('style', 'font-size:36px;');
              openWindow.document.close();
              openWindow.focus();
              openWindow.print();
              openWindow.close();
            }
          </script>

It change font family in my document except text in my table. please help. I print using:

open div-document-close div-a onclick printInfo(this)

<table border="0" style="margin-left: 10px;">
  <tr style="margin: 0px;">
     <td>Nama</td>
     <td style="padding:0 10px 0 10px">:</td>
     <td><?php echo "$nmlengkap";?></td>
  </tr>
</table>

Give the table an id so that you can set the styles on the table as well

<script type="text/javascript">
            function printInfo(ele) {
              var openWindow = window.open();
              openWindow.document.write(ele.previousSibling.innerHTML,'');
              tbl = openWindow.document.getElementById("tbl");
              tbl.setAttribute('style', 'font-family:Arial !important;');
              tbl.setAttribute('style', 'font-family:Arial 'font-size:36px;');
              openWindow.document.body.setAttribute('style', 'font-family:Arial !important;');
              openWindow.document.body.setAttribute('style', 'font-size:36px;');
              openWindow.document.close();
              openWindow.focus();
              openWindow.print();
              openWindow.close();
            }
          </script>

And the table:

<table id='tbl' border="0" style="margin-left: 10px;">
  <tr style="margin: 0px;">
     <td>Nama</td>
     <td style="padding:0 10px 0 10px">:</td>
     <td><?php echo "$nmlengkap";?></td>
  </tr>
</table>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM