What are best practices for handling line breaks in PHP variables when converting HTML to PDF?

When converting HTML to PDF in PHP, it is important to handle line breaks properly to ensure the content is formatted correctly in the resulting PDF. One common approach is to use the PHP function `nl2br()` to convert newline characters to HTML line breaks before passing the content to the PDF generation library.

$htmlContent = "This is a sample text with line breaks.\nNew line here.";
$htmlContent = nl2br($htmlContent);

// Pass $htmlContent to the PDF generation library for conversion