Customize window.print Function

Hi guys, is there’s a way to customize a page say for example if I am going to print a page correctly with a size of 8.5 x 13 inches using window.print function in javascript.

This is a CSS issue, not a PHP or JS one.
Use the following css:

html{
 width: 8.5in;
 height: 13in;
}

I would suggest making an entire print stylesheet formatting the page correctly, and import it into the page like this:

<link rel='stylesheet' media='print' link='print.css'>

No javascript is required, it will be properly formatted when the page prints.

Properly formatted insofar as anything HTML is properly formatted when sent to a printer. If you have to do anything complicated it is better to use PDF.

The printer section of the CSS standard is horribly neglected by browser manufacturers and in a mostly unusable state in my opinion.