TCPDF: clip text for cell width

I am creating a PDF report using the TCPDF Cell method. Text printed by the Cell method spills the width specified in the method. I want to print only that part of the text that matches the specified width, but should not go beyond or wrap on the next line. I do not need a font stretching strategy.

I searched a lot, but could not find a solution. Is there any other way / way to handle this? (I used setfillcolor (255) to achieve a visual effect, but the text is still invisible, detected when trying to select.)

here is my piece of code.

$pdf->SetFillColor(255); // only visual effect $pdf->Cell(36, 0, "A very big text in the first column, getting printed in 3.6cm width", 0, 0, 'L', true); $pdf->Cell(20, 0, "Data 1", 0, 0, 'L', true); $pdf->Cell(20, 0, "Data 2", 0, 0, 'L', true); 

Thank you very much.

+4
source share
1 answer

I found the answer here from Nicola Asuni, who is the main author of TCPDF. The following code provided by fenstra user works for me:

 // Start clipping. $pdf->StartTransform(); // Draw clipping rectangle to match html cell. $pdf->Rect($x, $y, $w, $h, 'CNZ'); // Output html. $pdf->writeHTMLCell($w, $h, $x, $y, $html); // Stop clipping. $pdf->StopTransform(); 

As far as I can tell, the cropping rectangle will not consider the registration on the displayed text, so you will apply the correct math to the width and height of the Rect if you need to simulate the behavior of MultiCell in this particular case.

+5
source

Source: https://habr.com/ru/post/1381636/


All Articles