withPageMargins(view($template)->render(), $page); $html = $this->withDocumentTitle($html, $metadata['Title'] ?? null); $pdf = $this->wrapper(); $pdf->setPaper($page->dompdfPaper(), $page->orientation); $pdf->loadHTML($html); if ($metadata !== []) { $pdf->addInfo($metadata); } 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; } /** * dompdf reads the document Title from the