Myanmar Font in TC/PDF export in PHP with laravel

You need to download the font ttf file
Zawgyi-One-20051130.ttf

================
Utility.php
=================
<?php namespace App\Core;

use Validator;
use Auth;
use DB;
use App\Http\Requests;
use App\Session;
use PDF;
use TCPDF_FONTS;

class Utility
{
// Use Pdf Export
public static function exportPDF($html,$pdfTitle = 'exportPDF')
{
PDF::SetTitle($pdfTitle);

require_once(base_path() . '/vendor/tecnickcom/tcpdf/include/tcpdf_fonts.php');
// $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$fontname = TCPDF_FONTS::addTTFfont(app_path() .'/Core/Export/Zawgyi-One-20051130.ttf', 'TrueTypeUnicode', '', 32);

// $font1 = PDF::addTTFfont('/home/waiyan/Downloads/Zawgyi-One-20051130.ttf', 'TrueTypeUnicode', '', 8);
PDF::SetFont($fontname, '', 15, '', false);

// set font
//PDF::SetFont('helvetica', '', 12);
PDF::AddPage();
PDF::writeHTML($html, true, false, false, false, '');

PDF::Output($pdfTitle . '.pdf');
exit();

}

}
===========================================
ServicePdfGenerator.php
===========================================
<?php

namespace App\Core\Export;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use App\Core\Config\Config;
use App\Core\Utility;
use PDF;

class ServicePdfGenerator implements IPDFGeneratorInterface
{
public function generate($paramObj)
{

ob_end_clean();
ob_start();

$html = <<<EOD

.table_main {
font-size: 10;
}

.table_border {
border: 1;
}

ကခဂ ကခဂ ကခဂ ကခဂ

EOD;

Utility::exportPDF($html,”mm_font_pdf”);
return true;

}
}
==============================================

Advertisements

dompdf/dompdf v0.7.0 requires ext-gd * -> the requested PHP extension gd is missing from your system

Problem 1
    - dompdf/dompdf v0.7.0 requires ext-gd * -> the requested PHP extension gd is missing from your system.
    - barryvdh/laravel-dompdf v0.7.0 requires dompdf/dompdf ^0.7 -> satisfiable by dompdf/dompdf[v0.7.0].
    - Installation request for barryvdh/laravel-dompdf ^0.7.0 -> satisfiable by barryvdh/laravel-dompdf[v0.7.0].


Solution

If you are working in PHP version 5.* then you have to install

sudo apt-get install php5-gd
And if you are working in PHP version 7.* then you have to install

sudo apt-get install php7.0-gd

Hope it will work..

Cheers

Upgrade to PHP 7.0 on Ubuntu

Ref : https://www.stewright.me/2016/03/upgrade-php-7-0-ubuntu/

Prerequisites and disclaimer

My server is a Ubuntu 14.04 box that uses Apache 2.4 and PHP 5.5.9 prior to upgrade. These instructions are for Apache 2.4 users with a similar configuration, and I recommend you test in isolation before using in a production environment. Proceed at your own risk.

Step 1 – Add a new Apt source

At the time of writing, I’m using the packages maintained by a guy called Ondřej Surý (he’s worth a follow on Twitter) until there’s a Debian package for PHP 7 in the official release channels.

To do this, enter the following command into the box you’re upgrading:

sudo add-apt-repository ppa:ondrej/php

You’ll probably be prompted to enter your password at this point. Go ahead and enter it.

Step 2 – Install updates and the PHP 7.0 package

Next we’re going to update and upgrade packages on our system to ensure everything goes smoothly. You can do this in a single command with:

sudo apt-get update && sudo apt-get upgrade

Once this has finished, we’re ready to install PHP 7.0. Enter the following command into your terminal:

sudo apt-get install php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-mcrypt php7.0-curl

This will install PHP 7.0, along with a number of commonly used PHP packages including the Apache PHP 7 module. I found that everything else pretty much worked without being installed separately. That’s it pretty much. You shouldn’t need to make any configuration changes and everything should just work.

Step 3 – Test to ensure your server is using PHP 7.0

From the command line, type the following command:

php -v

Checking the passing data array ( Debugging at the PHP and Javascript )

PHP Page တစ္ခုေရးတဲ႕ အခါ Database ထဲကေန Select ယူလုိက္တဲ႕ Data ေတြကို ဘယ္လုိပါလာသလဲ သိခ်င္သည္႔ အခါ ….
print_r(array_name);  Or echo var_dump(array_name);

အေနနဲ႕ ထုတ္ယူၿကည္႔ရႈႏုိင္ပါသည္ …..

print_r(array_name);  Or echo var_dump(array_name);  ေရးၿပီးသည္႔ အခါ
exit(); ၿဖင္႔ လက္ရွိေနရာမွ ထြက္လွ်င္ က်န္ရွိေသာ အလုပ္မ်ားဆက္မလုပ္ေတာ႔ ဘဲ လက္ရွိ run ေနသည္႔ကုိ ရပ္တန္႔သြားပါလိမ္႔မည္ ..

eg .

<?php
$con=mysqli_connect(“myexample.com”,”william”,”db123″,”my_db”);
// Check connection
if (mysqli_connect_errno())
{
echo “Failed to connect to MySQL: ” . mysqli_connect_error();
}

$result = mysqli_query($con,”SELECT * FROM Persons”);

echo <table border=’1′>
<
tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>”;

while($row = mysqli_fetch_array($result))
{

 var_dump($row);
echo “<tr>”;
echo “<td>” . $row[‘FirstName’] . “</td>”;
echo “<td>” . $row[‘LastName’] . “</td>”;
echo “</tr>”;
}
echo “</table>”;

mysqli_close($con);
?>

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Javascript  ေရးသည္႔ အခါလည္း  PHP မွသယ္လာေသာ Data မ်ားကို စစ္ၿကည္႔ခ်င္သည္႔ အခါ …..
php မွ server ဆီသို႕သြားၿပီး သယ္ယူလာလည္႔ data မ်ားကို  json format အေနနဲ႔ေၿပာင္းၿပီး  alert(data1.join(“\n”)); အေနနဲ႕ ထုတ္ယူၿကည္႔ရႈႏုိင္ပါသည္

var data1 = <?php echo json_encode(test()); ?>;
 alert(data1.join(‘\n’));

<?php function test()
{
return $arrData;
}
?>