Is converting data to PDF format instead of Excel a viable solution for handling data manipulation in PHP?

Converting data to PDF format instead of Excel can be a viable solution for handling data manipulation in PHP if the primary goal is to create a non-editable document for sharing or printing purposes. PDF files are more secure and maintain the original formatting of the data. To convert data to PDF in PHP, you can use libraries like TCPDF or FPDF.

// Example using TCPDF library to convert data to PDF
require_once('tcpdf/tcpdf.php');

$pdf = new TCPDF();
$pdf->SetMargins(10, 10, 10);
$pdf->AddPage();

$data = array(
    array('Name', 'Age', 'City'),
    array('John Doe', 30, 'New York'),
    array('Jane Smith', 25, 'Los Angeles'),
);

$html = '<table border="1">';
foreach ($data as $row) {
    $html .= '<tr><td>' . implode('</td><td>', $row) . '</td></tr>';
}
$html .= '</table>';

$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output('data.pdf', 'D');