wrapper(); $pdf->setPaper($page->dompdfPaper(), $page->orientation); $pdf->loadHTML($this->withPageMargins(view($template)->render(), $page)); return new DompdfResponse($pdf); } /** * dompdf exposes no margin API — the page box comes from an `@page` rule, so * CSS is the only lever (see PdfPageSetup::marginCss). * * Injected at the top of
rather than the bottom so a template that * declares its own `@page` still wins, later rules of equal specificity * taking precedence. Prepending is the fallback for markup with no , * which dompdf tolerates. */ private function withPageMargins(string $html, PdfPageSetup $page): string { $style = ''; $injected = preg_replace('/(]*>)/i', '$1'.$style, $html, 1, $count); return $count ? $injected : $style.$html; } protected function wrapper(): PDF { return App::make('dompdf.wrapper'); } }