if (isset($_POST['convert_to_pdf'])) {
require_once('../TCPDF-main/main/tcpdf.php');
$pdf = new TCPDF('landscape', PDF_UNIT, 'LEGAL', true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetTitle('HTML to PDF');
$pdf->SetHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->SetFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetMargins(1, 10, 1); // Adjust margins as needed
$pdf->setCellPaddings(1, 5, 1, 5); // Adjust cell paddings as needed
// Disable header and footer
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
// Enable automatic page breaking
$pdf->SetAutoPageBreak(true, 10);
// Set default font
$pdf->SetFont('helvetica', '', 10);
// Add a new page to the PDF
$pdf->AddPage();
// HTML content for the table
$html =
'<table cellpadding="2" cellspacing="0" border="1">
<thead>
<tr style="font-size: 10px; font-weight: 600; background-color: #fefefe;">
<th width="55" height="61">Enrollment No.</th>
<th width="55" height="70" ">Candidate\'s Name</th>
<th width="55" height="30" style="text-align: center;">Sex</th>
<th width="55" height="40" style="text-align: center;">Caste</th>
<th width="55" height="45" style="text-align: center;">Religion</th>
<th width="55" height="46" style="text-align: center;">Subject</th>
<th width="55" height="42" style="text-align: center;">Th.Marks</th>
</tr>
</thead>
<tbody>
</tbody>
</table>';
// Write HTML content to the PDF
$pdf->writeHTML($html, true, false, true, false, '');
// Generate unique filename for the PDF
$fileName = "sample_" . time() . ".pdf";
// Output the PDF as a download
$pdf->Output($fileName, 'D');
exit;
}
The provided PHP code generates a table using TCPDF library, but the table headers () appear horizontally aligned. The objective is to align these headers text vertically, as depicted in a provided sample image. Despite attempts to utilize CSS rotation properties within TCPDF, the desired vertical alignment remains elusive. I donot have nay idea.