mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 09:09:01 +00:00
Document and Knowledge Base article PDFs with the letterhead look: logo and company details on the first page, the name with the client, folder and last update, a running header on later pages, a footer with the company, Confidential or Knowledge Base, the date and page numbers, tables with lines, shaded code, checklist boxes, symbols the old font could not draw, and headings as bookmarks; WebP pictures now show in document PDFs and the client documentation PDF; 26.12.3 changelog entries
This commit is contained in:
@@ -1021,25 +1021,42 @@ function clientExportPdfFacts(array $facts, $label_width = 26) {
|
||||
* page.
|
||||
*/
|
||||
function clientExportPdfDocumentHtml($html, $document_id) {
|
||||
$html = documentHtmlPurify($html);
|
||||
return clientExportPdfImages(documentHtmlPurify($html), $document_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* The images of purified HTML made fit for TCPDF, as above - its own from
|
||||
* uploads/<$folder>/<id>/ (documents, or kb for an article) inlined, a WebP
|
||||
* one as a PNG, any other dropped. Also for a document's or an article's own
|
||||
* PDF (functions/document_pdf.php).
|
||||
*/
|
||||
function clientExportPdfImages($html, $id, $folder = 'documents') {
|
||||
if (stripos($html, '<img') === false) {
|
||||
return $html;
|
||||
}
|
||||
$base = realpath(__DIR__ . '/../uploads/documents/' . intval($document_id));
|
||||
return preg_replace_callback('/<img\b[^>]*>/i', function ($match) use ($base) {
|
||||
$folder = $folder === 'kb' ? 'kb' : 'documents';
|
||||
$base = realpath(__DIR__ . "/../uploads/$folder/" . intval($id));
|
||||
return preg_replace_callback('/<img\b[^>]*>/i', function ($match) use ($base, $folder) {
|
||||
$tag = $match[0];
|
||||
$src = preg_match('/\bsrc\s*=\s*"([^"]*)"/i', $tag, $m) ? html_entity_decode($m[1], ENT_QUOTES, 'UTF-8') : '';
|
||||
$alt = preg_match('/\balt\s*=\s*"([^"]*)"/i', $tag, $m) ? $m[1] : '';
|
||||
$data = null;
|
||||
if (preg_match('#^data:image/(png|jpe?g|gif);base64,(.+)$#is', $src, $m)) {
|
||||
$data = base64_decode($m[2], true) ?: null;
|
||||
} elseif ($base && preg_match('#^/?uploads/documents/\d+/([^/?\#]+)$#', $src, $m)) {
|
||||
} elseif ($base && preg_match('#^/?uploads/' . $folder . '/\d+/([^/?\#]+)$#', $src, $m)) {
|
||||
$path = realpath($base . '/' . rawurldecode($m[1]));
|
||||
if ($path && strpos($path, $base . DIRECTORY_SEPARATOR) === 0 && is_file($path)) {
|
||||
$data = file_get_contents($path);
|
||||
}
|
||||
}
|
||||
$info = $data ? @getimagesizefromstring($data) : false;
|
||||
// A WebP one as a PNG, which TCPDF can draw
|
||||
if ($info && $info[2] === IMAGETYPE_WEBP && function_exists('imagewebp') && ($image = @imagecreatefromstring($data))) {
|
||||
ob_start();
|
||||
imagepng($image);
|
||||
$data = ob_get_clean();
|
||||
$info = @getimagesizefromstring($data);
|
||||
}
|
||||
if (!$info || !in_array($info[2], [IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF], true)) {
|
||||
return $alt !== '' ? '<i>[' . $alt . ']</i>' : '<i>[image]</i>';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user