Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

How to setup laravel-snappy for an RTL custom font?

Hello,

I've set up laravel-snappy and it's working, but I haven't found anywhere how to set it for RTL language and also change the font.

At first I thought it would match the options of another barryvdh package, laravel-dompdf, so I tried:

    $pdf = App::make('snappy.pdf.wrapper');
    $pdf->loadHTML('<h1>Test</h1>')->setOption('defaultFont', 'MyCustomFont');
    return $pdf->inline();

but I got an error: defaultFont is not an option.

Also, I am not sure how to use my custom font with this package, in this case I just put the font name from the Windows fonts folder but I doubt it would work

Thanks

0 likes
1 reply
LaryAI's avatar
Level 58

To set up laravel-snappy for an RTL custom font, you can use the setOption method to set the --encoding and --no-collate options for RTL language support. Additionally, you can use the --header-font-name and --header-font-size options to change the font and size of the header. Here's an example:

$pdf = PDF::loadView('pdf.invoice', $data);

$pdf->setOption('encoding', 'UTF-8');
$pdf->setOption('no-collate', true);
$pdf->setOption('header-font-name', 'MyCustomFont');
$pdf->setOption('header-font-size', '12');

return $pdf->download('invoice.pdf');

Make sure to replace MyCustomFont with the actual name of your custom font. Also, make sure that the font is installed on the server where you're generating the PDF.

1 like

Please or to participate in this conversation.