TCPDF icon indicating copy to clipboard operation
TCPDF copied to clipboard

Huge SVG files parsing error

Open Simulator88 opened this issue 2 years ago • 2 comments

Hi all,

When handling huge SVG images, I get the error:

xml_parse(): SVG Error: No memory at line 8

It is a known limitation to xml parser, it could not work with files bigger than 10 mb.

This could be solved by reading the SVG images in chunks, like here, but it is still not implemented. I tried to do it in my own way, but no luck, is there somebody who tried to fix this?

My code:

$fopen = fopen($svgdata, "r"); while($fileContents = fread($fopen, 102410245)) { if (!xml_parse($parser, $fileContents, feof($fopen))) { $error_message = sprintf('SVG Error : %s at line %d', xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)); $this->Error($error_message); } }

FIY: $svgdata is now the path to the SVG file.

Thank you.

Simulator88 avatar May 11 '23 19:05 Simulator88

Hi @Simulator88 This has nothing to do with the tcpdf project, you should post this on stackoverflow.com

williamdes avatar May 14 '23 08:05 williamdes

Hi, with php >8.4 you can allow huge xml files for the parser. To do this, you would need to add the following option in ImageSVG after initialising the XML parser (e.g. line 23176)

xml_parser_set_option( $parser, XML_OPTION_PARSE_HUGE, true);

a-herms avatar Apr 01 '25 14:04 a-herms