简体   繁体   中英

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 ?!

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM