html2pdf icon indicating copy to clipboard operation
html2pdf copied to clipboard

How can I prevent the width overflowing?

Open dydsoft opened this issue 5 years ago • 5 comments

I use this tool to print differents reports on my system. Those are with dynamic content obviouslly, so I can't set a fixed width per table column. I tried setting a width as style on the table and didn't helped, tried setting a parent div over the table with fixed witdh and either worked. The problem happens when a column content is too large, the ideal solution is resolving it with linebreak, i dont care the height, but I need the width to fit

This is the report on the system. report

This is the report on pdf. pdf

dydsoft avatar Feb 17 '20 16:02 dydsoft

Hi, I have a same problem. Html2Pdf is very useful library and I using it in my GLPI plugin, but there is no word-break or table width support which makes this overflowing problems. This issue was reported few times but unfortunately rejected. @spipu please consider implement word-breaking again. Regards, Mateusz

mateusznitka avatar Feb 20 '20 15:02 mateusznitka

Hi Mateusnitka. On your code you can implement a some word wrapping function simple like this

function strWrap(&$cadena, $intLong = 50){
	$intLen					= 0;
	$cadIzq					= "";
	$intLen 				= strlen($cadena) - 1;
	$cadIzq					= "";
	$j							= 0;
	for ($i=0; $i<=$intLen; $i++){
		$j							= $j + 1;
		$cadIzq					= $cadIzq . $cadena[$i];
		if(($cadena[$i] == " " or $cadena[$i] == "." or $cadena[$i] == ",") and $j >= $intLong) {
			$cadIzq					= $cadIzq . "<br />";
			$j							= 0;
		}
	}
	$cadena					= $cadIzq;
}

And call on your php like this

			$strContenidoCampo = $ArrHdr002['lsver_value'];
			strWrap($strContenidoCampo, 30);

I hope this can solve your issue.

Urc0m avatar Mar 01 '20 06:03 Urc0m

@Urc0m thanks for reply. I will check your solution soon.

Regards, Mateusz

mateusznitka avatar Mar 03 '20 13:03 mateusznitka

No table width support guys ? Really ? I'm running through the same problems. Don't you have some something lighter than adding some <br/> with php ?

eguyot avatar Apr 07 '21 14:04 eguyot

I can also add empty tabels same issue, overflowing when above 15 cells.

BlutVampir avatar Sep 28 '23 09:09 BlutVampir