1

Library it´s:

composer require barryvdh/laravel-dompdf

i´m trying to create pdf in my app with laravel 10.20. I created my blade and all content it´s ok.

enter image description here

I have any rows, columns, etc and all my content when i access to route that i can show my blade, it´s ok.

In my controller i have this code:

$pdf = PDF::loadView('Pdfs.precontract', ['precontrato' => $personalDataPrecontract])
                            ->setPaper('a4', 'landscape')
                            ->setOption('zoom', 1.2)
                            ->setOption('footer-center', '')
                            ->setOption('footer-font-size', 5);
            $pdf->set_base_path("/public/css/");

            $path = public_path('/storage/pruebas');
            $fileName =  'precontrato.pdf' ;
            $pdf->save($path . '/' . $fileName);
            $pdf->download($fileName);               

My problem, it´s when i create my pdf with controller, not load my head styles. In my blade, i haver any includes (head, footer, etc) in my head, i have this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="description" content="">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link type="text/css" media="all" rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}">
    <link rel="stylesheet" href="{{ asset('css/style_pdf_pre.css') }}">
</head>
<body>
    <header>
        <div class="row justify-content-center align-items-center w-100 mt-3">

My bootstrap version it´s in PDFs, v4.6.2 i trayed with 3.3.7, but i have same problem.

When generate my pdf, i can show it so.

enter image description here

I haven´t got rows.. columns...

Anybody can say me that i´m doing wrong? Thanks for readme and sorry for my bad english

1 Answer 1

0

By default barryvdh/laravel-dompdf does not support boostrap yet and it supports CSS 2.1 selector syntaxes. You can find the dompdf supported CSS selector syntaxes here.

But if insist on using bootstrap you may try:

$pdf->setBasePath(public_path());

Then in you HTML use:

<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="all">

But then you're likely to encounter another issue that is col-md-12 will result in a div outside the pdf sheet. And to fix that you need to set the DPI in the following format:

$pdf = new \Dompdf\Options();
$pdf->setDpi(150);
$dompdf = new \Dompdf($pdf);

However, for PDF's with little design that can be pulled through small amount of CSS I prefer to do the design manually. You may take some idea from the this repository that I've created for simple invoices and often use it.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks for your response, but not run your response
@scorpions77 What's happening? Getting any errors?
yes, for example Class "Dompdf" not found
i resolve my problem installing laravel-snappy and configure it in windows and adding in my head blade <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.