记`tecnickcom/TCPDF`暗坑
TCPDF is a comprehensive PHP library for generating PDF documents without requiring external extensions. This page provides a high-level overview of the library's architecture, purpose, and main components. For detailed information about specific components, please refer to their respective documentation pages.
1. ImageSVG处理内存不足
所在文件:vendor/tecnickcom/tcpdf/tcpdf.php
PHP >= 8.4
// creates a new XML parser to be used by the other XML functions
$parser = xml_parser_create('UTF-8');
//在这之后加上
xml_parser_set_option( $parser, XML_OPTION_PARSE_HUGE, true);
PHP < 8.4
将
if (!xml_parse($parser, $svgdata)) {
$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);
}
修改成:
$chunkSize = 256;
for($pointer = 0; $pointer < strlen($svgdata) && empty($parseErrors); $pointer += $chunkSize) {
$xmlString = substr($svgdata, $pointer, $chunkSize);
if(!xml_parse($parser, $xmlString, false)) {
$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);
};
}
2. 最终生成的PDF有隐藏水印
所在文件:vendor/tecnickcom/tcpdf/tcpdf.php
protected $tcpdflink = false;
$this->tcpdflink = false;