sementara

This commit is contained in:
Daeng Deni Mardaeni
2026-01-30 14:44:14 +07:00
parent f402c0831a
commit aceff4f006
29 changed files with 2144 additions and 93 deletions

83
Helpers/PdfHelper.php Normal file
View File

@@ -0,0 +1,83 @@
<?php
namespace Modules\Lpj\Helpers;
class PdfHelper
{
/**
* Format text for PDF output to handle special characters
*
* @param string $text
* @return string
*/
public static function formatText($text)
{
if (empty($text)) {
return '';
}
// Common problematic characters and their safe replacements
$replacements = [
'<' => '&lt;',
'>' => '&gt;',
'&' => '&amp;',
'"' => '&quot;',
"'" => '&#39;',
'≤' => '&le;',
'≥' => '&ge;',
'≠' => '!=',
'≈' => '~',
'×' => 'x',
'÷' => '/',
'' => '-',
'—' => '-',
'' => '"',
'' => '"',
'' => "'",
'' => "'",
];
// First pass: replace with HTML entities
$safeText = str_replace(array_keys($replacements), array_values($replacements), $text);
// Ensure UTF-8 encoding
if (!mb_check_encoding($safeText, 'UTF-8')) {
$safeText = mb_convert_encoding($safeText, 'UTF-8', 'auto');
}
// Remove any remaining non-ASCII characters that could cause issues
$safeText = preg_replace('/[^\x20-\x7E\xA0-\xFF]/', '', $safeText);
return $safeText;
}
/**
* Format mathematical symbols to text representation
*
* @param string $text
* @return string
*/
public static function formatMathSymbols($text)
{
if (empty($text)) {
return '';
}
$mathReplacements = [
'<' => 'kurang dari',
'>' => 'lebih dari',
'<=' => 'kurang dari sama dengan',
'>=' => 'lebih dari sama dengan',
'!=' => 'tidak sama dengan',
'==' => 'sama dengan',
'≤' => 'kurang dari sama dengan',
'≥' => 'lebih dari sama dengan',
'≠' => 'tidak sama dengan',
'≈' => 'kira-kira',
'≡' => 'identik dengan',
'≅' => 'hampir sama dengan',
];
return str_replace(array_keys($mathReplacements), array_values($mathReplacements), $text);
}
}