dompdf local language(gujarati) text not display properly - php

I am using DOMPDF version 2
i want to print Gujarati text in my pdf and gujarati font is displayed but it changed some text like "ટેસ્ટ ડેટા ચેક" is changed in pdf. not all character is changed but some merraged and special character is changed. I had tried multiple different gujarati fonts but same thing is happen in all.
<?php
use Dompdf\Dompdf;
require 'vendor/autoload.php';
$html = '
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
#font-face {
font-family: "notoSerifGujarati";
src:url(fonts/NotoSerifGujarati-VariableFont_wght.ttf)
}
.m {
font-family: "notoSerifGujarati";
}
</style>
</head>
<body>
<p class="m">
ટેસ્ટ ડેટા ચેક
</p>
</body>
</html>';
$tmp = sys_get_temp_dir();
$dompdf = new Dompdf([
'logOutputFile' => '',
// authorize DomPdf to download fonts and other Internet assets
'isRemoteEnabled' => true,
// all directories must exist and not end with /
'fontDir' => $tmp,
'fontCache' => $tmp,
'tempDir' => $tmp,
'chroot' => $tmp,
]);
$dompdf->loadHtml($html); //load an html
$dompdf->render();
$dompdf->stream('hello.pdf', [
'compress' => true,
'Attachment' => false,
]);
how text displayed in pdf

Related

Google Unicode Fonts not rendered properly in mpdf for PHP

I'm trying to use Baloo2 Google Font in mpdf to render Hindi Language.
I'm using the Latest Version.
The PDF is being Rendered but the complex scripts are not being rendered properly.
I'm trying to render the following,
चातुर्यकला त्रिवेदी But it is rendered asचातुर् यकला त् रविदी
Although when inspected in browser, the rendering is proper in inspect source code. but not displayed properly in the PDF.
The Code in my file is
$html = ' आवेदक का नाम : चातुर्यकला त्रिवेदी';
$filename = 'demofile' . time() . '.pdf';
$mpdf = new \Mpdf\Mpdf([
'mode' => 'utf-8',
'default_font' => 'baloo',
]);
$mpdf->debug = true;
$mpdf->WriteHTML("p, td {font-family: baloo; color: transparent; white-space: pre; cursor: text; transform-origin: 0% 0%;}", 1);
$mpdf->WriteHTML($html);
$mpdf->Output($filename, 'D');
I've also copied the fonts in the ttfonts directory and also made changes to the fontVariables.php files as follows
'fontdata' => [
"baloo" => [
'R' => "BalooRegular.ttf",
'useOTL' => 0xFF,
'useKashida' => 75,
]...
];
When done in this format, an error is thrown
GPOS Lookup Type 5, Format 3 not supported (ttfontsuni.php)
Pls. let me know what I'm doing wrong...

Tamil fonts do not appear in the TCPDF php library

I am trying to create a pdf in the Tamil language, but I am experiencing font rendering issues. When I use the Baamini font, it works, but there is no English font in Baamini, so I tried other fonts such as latha.ttf, notosans.ttf, azaghi.ttf, and others, but these fonts do not work in tcpdf or fpdf. Please assist us in resolving this, and thank you in advance!
<?php
header('Content-type: text/html; charset=UTF-8') ;//chrome
require_once('tcpdf_include.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->setFontSubsetting(true);
$pdf->SetFont('freeserif', '', 12);
$pdf->AddPage();
$utf8text = '<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> </head> <body> <p>தினமும் உங்களை இந்த தோட்டத்து வழியாக செல்லும்போது என்னை கவனிப்பீர்களா என்று திரும்பி திரும்பி பார்த்து செல்வேன். ஆனால் நீங்களோ வெறி பிடித்தது போல் மண்ணை கொத்தி கொண்டிருப்பீர்கள்.</p></body></html>';
$pdf->writeHTML($utf8text, true, 0, true, true);
$pdf->Output('example_067.pdf', 'I');
?>
My Output is

I am trying to generate PDF/A-3 using mpdf (PHP library) but when I try to validate the output using an online validator ,the result is not a PDF/A-3

<?php
require_once __DIR__ . '/autoload.php';
$mpdf = new \Mpdf\Mpdf([
'PDFA' => true,
'PDFAauto' => true,
//'PDFAversion'=> 'A-3',
]);
$mpdf->SetAssociatedFiles([[
'name' => 'public_filename.xml',
'mime' => 'text/xml',
'description' => 'some description',
'AFRelationship' => 'Alternative',
'path' => __DIR__ . '/TaxInvoice.xml'
]]);
$rdf = '<rdf:Description rdf:about="" xmlns:zf="urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#">'."\n";
$rdf .= ' <zf:DocumentType>INVOICE</zf:DocumentType>'."\n";
$rdf .= ' <zf:DocumentFileName>ZUGFeRD-invoice.xml</zf:DocumentFileName>'."\n";
$rdf .= ' <zf:Version>1.0</zf:Version>'."\n";
$rdf .= ' <zf:ConformanceLevel>BASIC</zf:ConformanceLevel>'."\n";
$rdf .= '</rdf:Description>'."\n";
$mpdf->SetAdditionalXmpRdf($rdf);
$html = '
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
';
$mpdf->WriteHTML($html);
$mpdf->Output("mupdf.pdf","D");
erros from the validator
-ISO 19005-1:2005
Properties specified in XMP form shall use either the predefined schemas defined in XMP Specification, or extension schemas that comply with XMP Specification
-ISO 19005-1:2005
A file's name dictionary, as defined in PDF Reference 3.6.3, shall not contain the EmbeddedFiles key
-ISO 19005-1:2005
A file specification dictionary, as defined in PDF 3.10.2, shall not contain the EF key

Wkhtmltopdf conversion

My html to pdf conversion using wkhtmlpdf working fine without the <style> tag
but when I include the style tag it's not working that means not generating the pdf some one help me to solve this issue or let me know how to include my style.css in this format.
The way I handle this is as follows--
<?php
// create some HTML content
$html = '<!DOCTYPE html><html><head>
<style>
body {
margin: 0;
padding: 0;
}
...
</style></head><body>
<!-- Your body content -->
</body></html>';
$options = array(
"no-outline",
"binary" => "/usr/local/bin/wkhtmltopdf",
"margin-top" => ".25in",
"margin-right" => ".25in",
"margin-bottom" => ".55in",
"margin-left" => ".25in",
"zoom" => 1
);
$footer = '<!DOCTYPE html><html><head></head><body>...</body></html>';
$page_options = array('footer-html' => $footer);
$pdf->addPage($html, $page_options);
$pdf->saveAs('MY_PDF_NAME.pdf');
Hope this helps!
Best,
-Rush

pdf document - setting the window title (html header)

I'm using this to output a pdf document :
$response = new \Symfony\Component\HttpFoundation\Response(file_get_contents($thefile), 200, [
'Content-Description' => 'File transfer',
'Content-Disposition' => 'filename="' . $filename . '"',
'Content-Transfer-Encoding' => 'binary',
'Content-Type' => 'application/pdf',
]);
unlink($thefile);
$response->send();
In the generated page, the header title is the link to the page.
How can I customize the title ?
You have to include the title inside the pdf.
I just have to generate the pdf from a script as src of an iframe !
This way the head title is kept !
<head>
<title>THE TITLE</title>
</head>
<body>
<iframe src="process.php"></iframe>
</body>
</html>
Or I could ajax the php script, and return the result in a container element (eg div)

Categories