Jump to content

Display problem in mpdf php with database

Go to solution Solved by mac_gyver,

Recommended Posts

I am trying to print multiple barcode labels at once using mpdf. 

There are 2 problems i am facing. 

1st one : 1 blank page is getting adding at the beginning.

2nd : i want to display data like this 


instead ,it displays 


In TCPDF , i did not get any of these problems, but i have to use some indian language which properly displays only in Mpdf.

Here is my Mpdf Code

require_once __DIR__ . '/bootstrap.php';
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];

$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];

$mpdf = new \Mpdf\Mpdf([
	'fontDir' => array_merge($fontDirs, [__DIR__]),
	'fontdata' => $fontData + 
			'freeserif' => [
				'R' => 'assets/FreeSerif.ttf',
			'inkfree' => [
				'R' => 'assets/Inkfree.ttf',
    'margin_left' => 1,
	'margin_right' => 1,
	'margin_top' => 1,
	'margin_bottom' => 1,
	'margin_header' => 1,
	'margin_footer' => 1,
    'showBarcodeNumbers' => TRUE

$sec1 = $con->prepare("SELECT bc.bc_id, bc.book_id, bc.depts, bc.dept_ids, bc.bcode_unq, bk.bk_name, bk.price, bk.currency, l.lang_name, ed.ed_dept, ed.short_code, eds.sub_dept, eds.short_code AS edssortcode FROM books_copy bc INNER JOIN books bk ON bc.book_id=bk.book_id INNER JOIN languages l ON bk.lang=l.lang_id INNER JOIN edu_dept ed ON bk.edu_dept=ed.ed_id INNER JOIN edu_subdept eds ON bk.edu_subdept=eds.eds_id WHERE bc.bc_id BETWEEN 53 AND 55");
        foreach($sec1 as $r1)
            $agam = $r1['bc_id'];
        $bname = $r1['bk_name'];
        $price = $r1['price'];
        $lang = $r1['lang_name'];
        $edept = $r1['ed_dept'];
        $esubdept = $r1['sub_dept'];
        $escode = $r1['short_code'];
        $esscode = $r1['edssortcode'];    
        $bcode = $r1['bcode_unq']; 
        $dept_code = substr($r1['depts'],0,3);
        $deptids = $r1['dept_ids'];
        $dept = $escode.' '.$esscode; 
        $deptsubdept = $edept.' '.$esubdept;
        $bvert = substr($esscode,0,3);

$content = '';
$content .= '<html>
body {
font-family: freeserif;
	font-size: 12px;
border-right:1px solid #000;
.vertical {
border-collapse: collapse;
  text-align: right;
  writing-mode: vertical-lr;
  text-orientation: upright;
$content .= '<table border="0">
<table border="0" cellpadding="2" align="left" class="line">
<tr><td colspan="3" style="font-size:12px;"><strong>'.$_SESSION['library'].'</strong></td></tr>
<tr><td>Agam : '.$agam.' </td><td colspan="2" align="right">रु. '.$price.'</td></tr>
<tr><td colspan="3">Vibhag : '.$deptsubdept.'</td></tr>
<tr><td colspan="3">Book : '.$bname.'</td></tr>

<td valign="top" align="right">
<table><tr><td style="font-size:12px;" class="vertical">'.$bvert.'



<div style="position:fixed; top: 33mm;">
<barcode code="'.$agam.'" type="C39" class="barcode" />
<div style="text-align:center;">'.$agam.'</div>
 $mpdf->WriteHTML('<pagebreak sheet-size="75mm 50mm" />');      


i am attaching the pdf file generated thru mpdf as well as tcpdf.



I can post db tables structure if it helps.



Link to comment
Share on other sites

as far as i can tell, mpdf doesn't support writing-mode or text-orientation - https://mpdf.github.io/css-stylesheets/supported-css.html

the only reason you have a case where the letters are vertical is because there's only horizontal space in the layout for a single letter at that point. i recommend that you just add a <br> tag between each letter using code.

  • Great Answer 1
Link to comment
Share on other sites

  • Solution

here's a note about AddPage(), which does the same as the <pagebreak> tag -


Note: Unlike FPDF AddPage() does not need to be called at the beginning of the document if you are writing HTML code to the document. WriteHTML() will automatically add the first page to a new document.

apparently WriteHtml() adds the first page at the beginning of a new document, so the specific <pagebreak> adds a second one.

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.