How can PHP scripts be optimized to ensure that the desired output is achieved when printing information on paper?

To optimize PHP scripts for printing information on paper, it is important to format the output in a way that is suitable for print. This includes adjusting font sizes, margins, and page breaks to ensure that the content fits well on paper. Additionally, using CSS styles specifically for print media can help customize the appearance of the printed output.

<?php
echo '<style type="text/css">
@media print {
  body {
    font-size: 12pt;
    margin: 0;
    padding: 0;
  }
  .print-only {
    display: block;
  }
}
</style>';

echo '<div class="print-only">';
echo 'This content will only be visible when printed.';
echo '</div>';
?>