What are the best practices for defining HTTP headers and echoing PDF content in PHP?

When serving a PDF file in PHP, it is important to define the appropriate HTTP headers to ensure proper rendering in the browser. This includes setting the Content-Type header to 'application/pdf' and Content-Disposition header to 'inline' or 'attachment' depending on whether you want the browser to display the PDF inline or prompt the user to download it. Additionally, echoing the PDF content with appropriate output buffering can prevent any unwanted output before or after the PDF data.

<?php
// Define HTTP headers
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="example.pdf"');

// Output buffering to prevent any unwanted output
ob_start();

// Echo PDF content
echo file_get_contents('path/to/example.pdf');

// Flush output buffer
ob_end_flush();