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

Setting up Laravel with Nginx and phpmyadmin on Ubuntu 14.04

1) Install the Backend Components
1.1) sudo apt-get update
1.2) sudo apt-get upgrade
1.3) sudo apt-get install nginx php5-fpm php5-cli php5-mcrypt git
--------------------------------------------------------------------------------------------------------------------------
2) Modify the PHP Configuration
2.1) sudo nano /etc/php5/fpm/php.ini
2.2) cgi.fix_pathinfo=0 
2.3) sudo php5enmod mcrypt
2.4) sudo service php5-fpm restart
--------------------------------------------------------------------------------------------------------------------------
3) Configure Nginx and the Web Root
3.1) sudo mkdir -p /var/www/laravel
3.2) sudo nano /etc/nginx/sites-available/default


=======================================================
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    #root /var/www/laravel/public;
    index index.php index.html index.htm;

    server_name server_domain_or_IP;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

=======================================================
3.3) sudo service nginx restart
3.4) if you want to setup virtual block
3.4.1) sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com
3.4.2) sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

sample for "/etc/nginx/site-availables/example.com
=======================================================
server {
    listen 8080 default_server;
    listen [::]:8080 default_server;

    #root /var/www/laravel_example_com/public;
    index index.php index.html index.htm;

    server_name server_domain_or_IP;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}



======================================================== 

3.4.3) sudo nano /etc/nginx/nginx.conf 
3.4.4) server_names_hash_bucket_size 64; 
3.4.5) sudo service nginx restart 
-------------------------------------------------------------------------------------------------------------------------- 
4) Create Swap File (Optional) 
4.1) sudo fallocate -l 1G /swapfile 2) sudo mkswap /swapfile 3) sudo swapon /swapfile 

--------------------------------------------------------------------------------------------------------------------------
5) Install Composer and Laravel 5.1) cd ~ 
5.2) curl -sS https://getcomposer.org/installer | php 
5.3) sudo mv composer.phar /usr/local/bin/composer 
5.4) sudo composer create-project laravel/laravel /var/www/laravel 
5.5) sudo composer create-project laravel/laravel /var/www/laravel 4.2 
5.6) sudo chown -R :www-data /var/www/laravel 
5.7) sudo chmod -R 775 /var/www/laravel/app/storage 
5.8) http://server_domain_or_IP

--------------------------------------------------------------------------------------------------------------------------
4) Install phpmyadmin
4.1) sudo apt-get install phpmyadmin
4.2) che5.ck where is the site
cd /usr/share/nginx/html

4.3) sudo ln  -s /usr/share/phpmyadmin/ /usr/share/nginx/html
it will create a new link name “phpmyadmin” under /user/share/nginx/html
if you want to create custom phpmyadmin link, you can create by the following command
sudo ln  -s /usr/share/phpmyadmin_mycustom_name/ /usr/share/nginx/html
it will create a new link name “phpmyadmin_mycustom_name” under /user/share/nginx/html
And we can call it from browser by “http://ip_address/phpmyadmin; or “http://ip_address/phpmyadmin_mycustom_name;

4.3 ) sudo systemctl restart nginx

—————————————————————————————————————————————-

5) if there is “root /var/www/html” at /etc/nginx/sites-available/default, comment out it
eg ” # root /var/www/html ” and change server_name to
server_name localhost / ip_address;

—————————————————————————————————————————————

6) if “cgi.fix_pathinfo = 0” at /etc/php/7.0/fpm/php.ini, pls change back to original “cgi.fix_pathinfo = 1”
sudo systemctl restart nginx   OR sudo service nginx restart

 

7) If you used the new port for the virtual host, you have to allow that ports to access from globally ( outside )sudo ufw allow 8000/tcp

 

8) To Create a New User and Grant Permissions in MySQL

================================

Before we create and grant the permissions to the new user, we need to open the ( MySql port 3306 from firewall ).
To check firewall is active or inactive at unbuntu by the following command

ufw status

if reply ufw inactive, we need to open the ufw (firewall) by the following command

ufw enable

And then you can check which port are allow in our web server by the following command

ufw status
and it will reply all status.
If mysql is not allow, we need to allow it by the following command

ufw allow 3306/tcp

if port 3306 is not okay to access from the remote / other local pc, we need to change the mysql default por to ‘3360’ or as you wish.

to change the MySql port to ‘3360’,
go to the /etc/mysql
and edit the my.cnf

go to ‘[mysqld]’ part
chnage the default “bind_address” to “server_ip_address”
change the default “port” to “3360”

And then, restart the mysql service by the follwoing command
sudo service mysql restart

After it all, we need to check one thing
which ports are opening at our Web Server by the following

nmap localhost/ipaddress

========================================

login to mysql with root password
mysql -uroot -p
and then,

8.1) Let’s start by making a new user within the MySQL shell:

CREATE USER ‘newuser’@’localhost’ IDENTIFIED BY ‘password’;

8.2) provide the user with access to the information they will need

GRANT ALL PRIVILEGES ON * . * TO ‘newuser’@’localhost’;

8.3) Let’s start by making a new user within the MySQL shell:

CREATE USER ‘newuser’@’ip_address’ IDENTIFIED BY ‘password’;

8.4) provide the user with access to the information they will need

GRANT ALL PRIVILEGES ON * . * TO ‘newuser’@’ip_address’;

8.5) Reload all privileges

FLUSH PRIVILEGES;

 

Cheers

 

Laravel Composer Update Issues at Ubuntu

Apache error “Could not reliably determine the server’s fully qualified domain name”

Open a terminal
Open the /etc/apache2/httpd.conf file:
sudo editor /etc/apache2/httpd.conf
By default, it would be blank. Simply add the following line:
ServerName localhost
Save the file and exit
Restart the server
sudo service apache2 restart
=====================================
mbstring is missing while composer updating

– laravel/framework v5.2.9 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.

for general php versions
sudo apt-get install php-mbstring

for php 5.*
sudo apt-get install libapache2-mod-php5

for php 7.*
sudo apt-get install php-mbstring php7.0-mbstring php-gettext libapache2-mod-php7.0

Then, restart apache2:
sudo service apache2 restart ( Ubuntu 14.04 )
sudo systemctl restart apache2 ( Ubuntu 16.04 )

Still missing?

sudo phpenmod mcrypt
sudo phpenmod mbstring

Then, restart apache2
sudo service apache2 restart ( Ubuntu 14.04 )
sudo systemctl restart apache2 ( Ubuntu 16.04 )

===================================

If you got problem, while composer updating
“doctrine-dbal missing”

composer require Doctrine/dbal
or
apt-get install php-doctrine-dbal
=====================================

If you got problem
” phpunit/phpunit 4.8.9 requires ext-dom * -> the requested PHP extension dom is missing from your system.”

for general php versions
sudo apt-get install php-xml

if your php version is 5.*
sudo apt-get install php5.6-xml

if your php version is 7.*
sudo apt-get install php7.0-xml

Sending email with WebMail in laravel 5.2

1) 
===================================================================================
.env
===================================================================================
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:xVpNKIpjAe7LoKTrVd7pKOdJrsaiLmSy8tLYMjerJMS0=
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test_db
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=cpanel1.cloud.com
MAIL_PORT=587
MAIL_USERNAME=test@mywebmaildomain.com
MAIL_PASSWORD=testPassword
MAIL_ENCRYPTION=tls

===================================================================================
config/mail.php
===================================================================================

<?php return [ 'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'cpanel1.cloud.com'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => 'test@mywebmaildomain.com', 'name' => 'Bacekend System'],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'sendmail' => '/usr/sbin/sendmail -bs',
];
===================================================================================

PHP Fatal error: Class’Elibyy\TCPDF\ServiceProvider” in laravel

----------------------------------------------------------------
laravel framework version 5.2 
added at composer.json
 "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*",
        "laravelcollective/html": "~5.2",
        "uxweb/sweet-alert": "~1.1",
        "maatwebsite/excel": "~2.1.0",
        "intervention/image": "dev-master",
        "elibyy/tcpdf-laravel": "5.2.*"
    },
------------------------------------------------------------------
1) comment out 2 lines from config/app.php
1.1) at  'providers' => [ 
need to comment out 
//Elibyy\TCPDF\ServiceProvider::class,

1.2) at  'aliases' => [
need to comment out 
//'PDF'       => Elibyy\TCPDF\Facades\TCPDF::class,

------------------------------------------------------------------
2) composer update --no-scripts
3) un-comment previous 2 lines from config/app.php
4) run again "composer update --no-scripts"

Cheers