'javascript print Contents fitting to one page

with this function, I can print div content succesfully but I want to fitting one horizantal page . How can I do that?

function printDiv(divId) {
    var printContents = document.getElementById(divId).innerHTML;
     var originalContents = document.body.innerHTML;
     document.body.innerHTML = printContents;
     window.print();
     document.body.innerHTML = originalContents;
    
  return true;
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source