| Current Path : /var/www/cesa.co.za/cfg/ |
| Current File : /var/www/cesa.co.za/cfg/pdf_css_config.php |
<?php
/**
* PDF CSS Configuration File
*
* This file defines which CSS files should be loaded for PDF generation
* to ensure the PDF matches the main site's appearance.
*
* Modify this file to add/remove CSS files as needed.
*/
// Main CSS files (loaded first, in order of priority)
$PDF_MAIN_CSS_FILES = [
'/cesanet/style.css', // Main site styles
'/css/shared.css', // Shared component styles
];
// Additional CSS files (loaded after main files)
$PDF_ADDITIONAL_CSS_FILES = [
'/cceadmin/xenon.css', // CCE admin styles
'/cpdadmin/xenon.css', // CPD admin styles
'/echasl23/xenon.css', // ECHASL styles
];
// CSS files to exclude (won't be loaded)
$PDF_EXCLUDED_CSS_FILES = [
'/js/jqueryui-1-13/jquery-ui.min.css', // jQuery UI (often causes issues in PDFs)
];
// PDF-specific CSS overrides (loaded last, with !important)
$PDF_OVERRIDE_CSS = [
'body' => [
'font-family' => 'Verdana, Arial, sans-serif !important',
'font-size' => '16px !important',
'color' => '#494949 !important',
'margin' => '0 !important',
'padding' => '0 !important',
],
'table' => [
'border-collapse' => 'collapse !important',
'width' => '100% !important',
],
'td, th' => [
'border' => '1px solid #CCCCCC !important',
'padding' => '4px !important',
'vertical-align' => 'top !important',
'font-size' => '16px !important',
],
'.eventname' => [
'font-family' => 'Verdana, Arial, sans-serif !important',
'font-size' => '18pt !important',
'font-weight' => 'bold !important',
'display' => 'block !important',
'visibility' => 'visible !important',
'opacity' => '1 !important',
'color' => '#000000 !important',
'background-color' => 'transparent !important',
],
// Ensure eventname class is visible even if it's inside a link or affected by link styles
'a .eventname, .eventname a, a.eventname' => [
'display' => 'block !important',
'visibility' => 'visible !important',
'opacity' => '1 !important',
'color' => '#000000 !important',
'text-decoration' => 'none !important',
'background-color' => 'transparent !important',
],
// Override any link-hiding CSS that might be affecting the calendar
'a' => [
'text-decoration' => 'none !important',
'color' => 'inherit !important',
'font-size' => '16px !important',
],
// Ensure calendar content is visible
'.calendar-content, .calendar-table, .event-row' => [
'display' => 'block !important',
'visibility' => 'visible !important',
'opacity' => '1 !important',
],
'@page' => [
'margin-top' => '1cm !important',
'margin-left' => '0 !important',
'margin-right' => '0 !important',
'margin-bottom' => '1cm !important',
],
'thead' => [
'display' => 'table-header-group !important',
'font-size' => '16px !important',
],
'tfoot' => [
'display' => 'table-row-group !important',
],
'tr' => [
'page-break-inside' => 'avoid !important',
],
'p, div, span' => [
'font-size' => '16px !important',
],
'.boldblue' => [
'color' => '#009DDA !important',
'font-weight' => 'bold !important',
],
// Hide elements that should not appear in PDFs
'.printhide' => [
'display' => 'none !important',
'visibility' => 'hidden !important',
'opacity' => '0 !important',
],
// Hide common button elements in PDFs
'.btn, .button, .register-btn, .more-info-btn' => [
'display' => 'none !important',
'visibility' => 'hidden !important',
],
// Make More Info and Register Now buttons have white text
'.printhide .bluelink' => [
'color' => '#ffffff !important',
'text-decoration' => 'underline !important',
],
];
// Function to get all CSS file paths
function getPDFCSSFiles() {
global $PDF_MAIN_CSS_FILES, $PDF_ADDITIONAL_CSS_FILES;
$allFiles = array_merge($PDF_MAIN_CSS_FILES, $PDF_ADDITIONAL_CSS_FILES);
// Convert to full paths
$fullPaths = [];
foreach ($allFiles as $cssFile) {
$fullPaths[] = $_SERVER['DOCUMENT_ROOT'] . $cssFile;
}
return $fullPaths;
}
// Function to check if a CSS file should be excluded
function isCSSFileExcluded($cssFile) {
global $PDF_EXCLUDED_CSS_FILES;
foreach ($PDF_EXCLUDED_CSS_FILES as $excludedFile) {
if (strpos($cssFile, $excludedFile) !== false) {
return true;
}
}
return false;
}
// Function to get PDF override CSS as string
function getPDFOverrideCSSString() {
global $PDF_OVERRIDE_CSS;
$cssString = "/* PDF-specific overrides */\n";
foreach ($PDF_OVERRIDE_CSS as $selector => $properties) {
$cssString .= $selector . " {\n";
foreach ($properties as $property => $value) {
$cssString .= " " . $property . ": " . $value . ";\n";
}
$cssString .= "}\n\n";
}
return $cssString;
}
/**
* Load and inline CSS files for PDF generation
* This ensures the PDF matches the main site's appearance
*/
function loadCSSForPDF() {
$cssContent = '';
// Get CSS files from configuration
$cssFiles = getPDFCSSFiles();
// Load main CSS files
foreach ($cssFiles as $cssFile) {
if (file_exists($cssFile) && !isCSSFileExcluded($cssFile)) {
$css = file_get_contents($cssFile);
if ($css !== false) {
// Clean up the CSS for PDF compatibility
$css = cleanCSSForPDF($css);
$cssContent .= "/* From: " . basename($cssFile) . " */\n";
$cssContent .= $css . "\n";
}
}
}
// Add PDF-specific overrides from configuration
$cssContent .= getPDFOverrideCSSString();
// Add calendar visibility CSS to ensure .eventname and other content is visible
$cssContent .= getCalendarVisibilityCSS();
return $cssContent;
}
/**
* Clean CSS for PDF compatibility
*/
function cleanCSSForPDF($css) {
// Remove @import statements (they won't work in PDF)
$css = preg_replace('/@import[^;]+;/', '', $css);
// Remove media queries that might interfere with PDF
$css = preg_replace('/@media[^{]*\{[^}]*\}/', '', $css);
// Remove any external font references
$css = preg_replace('/@font-face[^{]*\{[^}]*\}/', '', $css);
// Ensure all colors are hex values for better PDF compatibility
$css = str_replace('rgb(0, 157, 218)', '#009DDA', $css);
// Remove any CSS rules that might hide content in PDFs
// This includes rules that set display: none, visibility: hidden, or opacity: 0
// But we'll be careful not to remove legitimate hiding rules for print/PDF
// Remove rules that completely hide elements (but keep legitimate print hiding)
$css = preg_replace('/([^{}]+)\s*\{\s*display\s*:\s*none[^}]*\}/', '', $css);
// Remove rules that make elements invisible
$css = preg_replace('/([^{}]+)\s*\{\s*visibility\s*:\s*hidden[^}]*\}/', '', $css);
// Remove rules that make elements completely transparent
$css = preg_replace('/([^{}]+)\s*\{\s*opacity\s*:\s*0[^}]*\}/', '', $css);
// Remove any CSS that might interfere with PDF rendering
// But preserve legitimate styling
return $css;
}
/**
* Add specific CSS overrides to ensure calendar content is visible
* This function adds CSS rules that override any problematic hiding rules
*/
function getCalendarVisibilityCSS() {
return '
/* Ensure event names are always visible in PDFs */
.eventname {
font-family: Verdana, Arial, sans-serif !important;
font-size: 18pt !important;
font-weight: bold !important;
display: block !important;
visibility: visible !important;
opacity: 1 !important;
color: #000000 !important;
background-color: transparent !important;
text-decoration: none !important;
}
/* Override any link styles that might hide event names */
a .eventname,
.eventname a,
a.eventname {
display: block !important;
visibility: visible !important;
opacity: 1 !important;
color: #000000 !important;
text-decoration: none !important;
background-color: transparent !important;
}
/* Hide elements with .printhide class in PDFs */
.printhide {
display: none !important;
visibility: hidden !important;
opacity: 0 !important;
}
/* Make More Info and Register Now buttons have white text */
.printhide .bluelink {
color: #ffffff !important;
text-decoration: underline !important;
}
/* Also hide common button classes that should not appear in PDFs */
.btn,
.button,
.register-btn,
.more-info-btn,
input[type="button"],
input[type="submit"] {
display: none !important;
visibility: hidden !important;
}
/* Override any print-specific hiding for event names */
@media print {
.eventname, .eventname * {
display: block !important;
visibility: visible !important;
opacity: 1 !important;
}
.printhide {
display: none !important;
visibility: hidden !important;
opacity: 0 !important;
}
}
';
}
/**
* Debug function to show what CSS is being loaded
* Uncomment the call to this function in the HTML head if you need to debug
*/
function debugCSSLoading() {
$cssContent = loadCSSForPDF();
echo "<!-- DEBUG: CSS Content Length: " . strlen($cssContent) . " characters -->\n";
echo "<!-- DEBUG: CSS Content Preview: " . substr($cssContent, 0, 500) . "... -->\n";
return $cssContent;
}
?>