What are the best practices for handling printing functionality in PHP applications?

When handling printing functionality in PHP applications, it is best practice to separate the presentation logic from the business logic. This can be achieved by creating a separate PHP file for generating the printable content and using CSS for styling the print layout. Additionally, it is recommended to use the PHP `print` or `echo` functions to output the printable content to the browser.

// Separate PHP file for generating printable content
printable.php

<?php
// Business logic to retrieve data
$data = fetchData();

// HTML content for printable page
$html = '<html><head><link rel="stylesheet" type="text/css" href="print.css"></head><body>';
$html .= '<h1>Printable Content</h1>';
$html .= '<p>' . $data . '</p>';
$html .= '</body></html>';

// Output printable content
echo $html;
?>

// CSS file for styling print layout
print.css

@media print {
    body {
        font-size: 12pt;
        line-height: 1.6;
    }
}