The issue involves Arabic text appearing reversed in the PDF output. The font "DejaVuSans" is being used, but the Arabic text is still not displaying correctly.
Despite attempts to address the problem through font selection and encoding adjustments, the Arabic text remains reversed in the generated PDF.
Further investigation and troubleshooting are required to determine the cause of this issue and find a suitable solution for proper Arabic text rendering.
Generate-pdf.php
<?php
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
use Dompdf\Options;
if (isset($_POST['generate-pdf'])) {
$options = new Options();
$options->set('isHtml5ParserEnabled', true);
$options->set('isPhpEnabled', true);
$options->set('fontDir', __DIR__ . '/fonts'); // Path to your fonts directory
$options->set('fontCache', __DIR__ . '/font-cache'); // Path to your font cache directory
$options->set('defaultFont', 'NotoSansArabic-Regular');
// Use the correct font name
$dompdf = new Dompdf($options);
$template = file_get_contents('pdf-template.html');
$template = str_replace('<head>', '<head><style>.arabic { direction: rtl; font-family: DejaVuSans; }</style>', $template);
// Map form fields to placeholders in the template
$template = str_replace('', $_POST['date'], $template);
$template = str_replace('', $_POST['company_name'], $template);
$template = str_replace('', $_POST['owner_name'], $template);
$template = str_replace('', $_POST['activity_type'], $template);
$template = str_replace('', $_POST['behalf_of'], $template);
// Convert the image to base64
$logo_base64 = base64_encode(file_get_contents('alent.PNG'));
$template = str_replace('', $logo_base64, $template);
$html = $template;
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream('output.pdf', array('Attachment' => 0));
}
?>
<!DOCTYPE html>
<html><html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<title>PDF Template</title>
<style>
/* Add your CSS styles here */
.header {
display: flex;
align-items: center;
}
@font-face {
font-family: 'Noto Sans Arabic';
src: url('fonts/NotoSansArabic-Regular.woff') format('woff'),
url('fonts/NotoSansArabic-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
body {
font-family: 'Noto Sans Arabic', sans-serif;
}
}
//Other css
</style>
</head>
<body lang="ar" dir="rtl">
<div class="input-box">
<h3> اسم المالك / Name of owner:</h3>
<p></p>
</div>
// Other Displays
These are the two main files related to the process. can you please check out ?
Can you please provide a solution regarding, I have literally tried every solution out there on the internet.
source https://stackoverflow.com/questions/76988270/dejavusans-dompdf-for-arabic-loading-reversed
No comments:
Post a Comment