Skip to content
Advertisement

mPDF: How to use WriteCell function using bold text?

I’ve this snippet, in Laravel, where there is a wrapper. Note I’m using directly mPDF, instead of wrapper function

    $pdf = new MPdf();
    $mpdf = $pdf->getMpdf();
    $mpdf->SetSourceFile(public_path() . DIRECTORY_SEPARATOR  . 'pdf' . DIRECTORY_SEPARATOR   . 'my_template.pdf');
    $template = $mpdf->ImportPage(1);
    $mpdf->UseTemplate($template);
    $mpdf->WriteCell(130,140, $text_to_write );

My need is simply to write my text in bold. I don’t ever need to change font file.

How ?!

Advertisement

Answer

I resolved accessing underlying FPDF functions.

Recap: Laravel-mpdf is a wrapper for mPDF. mPDF ‘wraps’ and enhance one of a few pdf handling libraries.

It’s stated here: https://mpdf.github.io/ : “It is based on FPDF and HTML2FPDF with a number of enhancements”

Having this info, I simply tried to use FPDF functions and they worked. FPDF docs: http://www.fpdf.org/en/doc

Snippet

    $pdf = new MPdf();
    $mpdf = $pdf->getMpdf();
    $mpdf->SetSourceFile('name_and_path_of_template_file.pdf');
    $template = $mpdf->ImportPage(1);
    $mpdf->UseTemplate($template);
    $mpdf->SetFont('Arial','B', 11);

    $mpdf->WriteText(11,82, $what_to_write_in_bold );

    $mpdf->SetFont('Arial','', 10);

    $mpdf->WriteText(164, 243.46, $what_to_write_in_noraml);

    $mpdf->Output();
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement