What role does the coordinate system play when rotating text in PDF generation with PHP?

When rotating text in PDF generation with PHP, the coordinate system plays a crucial role in determining the position and angle of the rotated text. To rotate text correctly, you need to adjust the coordinate system before drawing the text on the PDF. This involves translating the origin to the desired position, rotating the coordinate system by the desired angle, and then drawing the text at the adjusted position.

// Create a new PDF document
$pdf = new FPDF();
$pdf->AddPage();

// Set the position and angle for rotating text
$x = 50; // X coordinate
$y = 50; // Y coordinate
$angle = 45; // Rotation angle

// Adjust the coordinate system for rotating text
$pdf->SetXY($x, $y);
$pdf->Rotate($angle, $x, $y);

// Draw the rotated text
$pdf->SetFont('Arial', '', 12);
$pdf->Cell(0, 0, 'Rotated Text', 0, 1, 'C');

// Reset the coordinate system after rotating text
$pdf->Rotate(0);
$pdf->SetXY(0, 0);

// Output the PDF document
$pdf->Output();