4/16/2017

How to use Mangal Font with `mPDF PHP` Library


Similar Questions

  • How to use Hindi with mPDF
  • How to use Custom Font with mPDF
  • How to use UTF-8 Font with mPDF
  • How to use UTF-8 Data with mPDF

Simple Project Structure

app
    assets
        css
        js
        img
    bin
    bower_components
    vendor
        mpdf
            mpdf

Steps

  1. First Copy and Paste Custom Font to ./vendor/mpdf/mpdf/ttfonts Directory
    So Full path to font will be ./vendor/mpdf/mpdf/ttfonts/MANGAL.TTF

  2. Update Fonts Config File of mPDF Library ./vendor/mpdf/mpdf/config_fonts.php

$this->fontdata = array(
    "mangal" => array(
        'R' => "MANGAL.TTF",
        'useOTL' => 0xFF,
    ),

    ....

);

  1. Update HTML-DOM/CSS property for font-family
    So find and replace font-family:{old_font} to font-family:mangal

  2. You can create basic CSS Rules for it

body {
    font-family: mangal;
}

// OR

.hindi {
    font-family: mangal;
}

First Install mPDF library using Composer

php /home/ssp/composer.phar require mpdf/mpdf

First Demo Normal Case

<?php 
// Using mPDF Library
$mpdf = new mPDF(''); 

// Normal Case
$test_case1 = '
<head>
<title>Document in Hindi</title>
</head>
<body>
<p>यह एक डेमो टेस्ट है |</p>
</body></html>';

// Set some flags for mPDF
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;

// Read and Parse HTML Content
$mpdf->WriteHTML($test_case1);
// Display PDF to Browser
$mpdf->Output();
exit;

Using Custom Style for any HTML Element

<?php 
$test_case2 = '
<head>
<title>Document in Hindi</title>
</head>
<body style="font-family: mangal; font-size: 20px;">
<p>यह एक डेमो टेस्ट है |</p>
</body></html>';

$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;

$mpdf->WriteHTML($test_case2);
$mpdf->Output();
exit;

Using Custom Stylesheet (CSS)

<?php 
$test_case3 = '
<head>
<title>Document in Hindi</title>
<style>
body {
    font-family: mangal;
    font-size: 15px;
    color: red;
}
</style>
</head>
<body style="font-family: mangal; font-size: 20px;">
<p>यह एक डेमो टेस्ट है |</p>
</body></html>';

$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;

$mpdf->WriteHTML($test_case3);
$mpdf->Output();
exit;

Download Fonts for Hindi India

  1. http://indiatyping.com/index.php/download/hindi-fonts
  2. http://indiatyping.com/index.php/download/mangal-font

How to Shrink RAW Disk Image to Actual Used Disk Space

Related Questions

  1. How to save disk space for raw disk images
  2. How to shrink raw disk image to actual space used
  3. How to compress raw disk image to actual space used

Note: This method is only for Linux Users

Step 1 (Clone or Download bash Script)

https://github.com/Drewsif/PiShrink Make your pi images smaller!
ssp@ssp-pc:~/Downloads$
=> git clone https://github.com/Drewsif/PiShrink.git
Cloning into 'PiShrink'...
remote: Counting objects: 72, done.
remote: Total 72 (delta 0), reused 0 (delta 0), pack-reused 72
Unpacking objects: 100% (72/72), done.
Checking connectivity... done.

Lets Check Syntax of Command pishrink.sh

ssp@ssp-pc:~/Downloads$
=> cd PiShrink/
ssp@ssp-pc:~/Downloads/PiShrink$
=> ls
LICENSE  pishrink.sh  README.md
ssp@ssp-pc:~/Downloads/PiShrink$
=> ./pishrink.sh 
Usage: ./pishrink.sh [-s] imagefile.img [newimagefile.img]

You need sudo permission to Use this Script

ssp@ssp-pc:~/Downloads/PiShrink$
=> ./pishrink.sh -s /media/ssp/Linux_DATA/raspberry-pi.img /media/ssp/Linux_DATA/raspberry-pi.min.img 
ERROR: You need to be running as root.

ssp@ssp-pc:~/Downloads/PiShrink$
=> sudo ./pishrink.sh -s /media/ssp/Linux_DATA/raspberry-pi.img /media/ssp/Linux_DATA/raspberry-pi.min.img 
Copying /media/ssp/Linux_DATA/raspberry-pi.img to /media/ssp/Linux_DATA/raspberry-pi.min.img...
Skipping autoexpanding process...
e2fsck 1.42.9 (4-Feb-2014)
/dev/loop0: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/loop0: 152923/480496 files (0.1% non-contiguous), 1059531/1924096 blocks
resize2fs 1.42.9 (4-Feb-2014)
resize2fs 1.42.9 (4-Feb-2014)
Resizing the filesystem on /dev/loop0 to 1066992 (4k) blocks.
Begin pass 2 (max = 98529)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 59)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 13514)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/loop0 is now 1066992 blocks long.

Shrunk /media/ssp/Linux_DATA/raspberry-pi.min.img from 7.5G to 4.2G

Result

As you can see that Actual Size of Disk Image was about 8 GB and now it is about 4 GB, So this script is really useful When you want to save disk space and now you can easily restore raw disk image fatster (in short time). After that You can expand file system to use all available disk space.