Re: PDF (invoice or catalog) not showing image(s)
Posted: 02 Dec 2021, 23:25
Phoca PDF has specific hacks in TCPDF, which try to correct the path, so for example, this tries to correct all the image variant paths in TCPDF:
Jan
Code: Select all
// ALL $_SERVER['DOCUMENT_ROOT'] changed to JPATH_ROOT to work correctly in Joomla!
// Xx changed FROM: $_SERVER['DOCUMENT_ROOT'] TO: JPATH_ROOT
// 1x changed FROM: K_PATH_MAIN TO: JPATH_ROOT
///if (($imgsrc[0] === '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
//if (($imgsrc[0] === '/') AND !empty(JPATH_ROOT) AND (JPATH_ROOT != '/')) {
if (strpos($imgsrc, 'http') === 0 || strpos($imgsrc, 'https') === 0) {
// Don't manipulate full url
} else if (!empty(JPATH_ROOT) AND (JPATH_ROOT != '/')) {
// fix image path
///$findroot = strpos($imgsrc, $_SERVER['DOCUMENT_ROOT']);
$findroot = strpos($imgsrc, JPATH_ROOT);
if (($findroot === false) OR ($findroot > 1)) {
///if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
if (substr(JPATH_ROOT, -1) == '/') {
///$imgsrc = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$imgsrc;
$imgsrc = substr(JPATH_ROOT, 0, -1).$imgsrc;
} else {
///$imgsrc = $_SERVER['DOCUMENT_ROOT'].$imgsrc;
$tmpJb = str_replace('/', '\\', JUri::root(true));//JUri::base(true);
$tmpIp = str_replace('/', '\\', $imgsrc);
$tmpIpWJb = str_replace($tmpJb, '', $tmpIp);
// Is the image path full path?
if (JPATH_ROOT != '') {
$ds = '';
$imgsrc = str_replace('\\', '/', $imgsrc);
$firstPos = substr($imgsrc, 0, 1);// start the path with "/"?
if ($firstPos != '/') {
$ds = '/';// If not set the ds (directory separator) between path and image path
}
$imgsrc = JPATH_ROOT.$ds.$tmpIpWJb;
}
}
}
$imgsrc = str_replace('\\', '/', $imgsrc);
$imgsrc = urldecode($imgsrc);
$testscrtype = @parse_url($imgsrc);
if (empty($testscrtype['query'])) {
// convert URL to server path
///$imgsrc = str_replace(K_PATH_URL, K_PATH_MAIN, $imgsrc);
$imgsrc = str_replace(K_PATH_URL, JPATH_ROOT, $imgsrc);
} elseif (preg_match('|^https?://|', $imgsrc) !== 1) {
// convert URL to server path
///$imgsrc = str_replace(K_PATH_MAIN, K_PATH_URL, $imgsrc);
$imgsrc = str_replace(K_PATH_MAIN, JPATH_ROOT, $imgsrc);
}
}
$imgsrc = str_replace('\\', '/', $imgsrc);