Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open PDF in a new tab using dompdf

Tags:

dompdf

Im trying to generate pdf using dompdf, how can I open the pdf in a new tab in a browser? Like, I Click A link for the PDF and it should open in a new tab, not save it automatically. I want to give the user a choice to save the file after seeing it first. how do i do that?

whenever i use $pdf->output at the end of the file, it does not change a thing, the file is still downloaded automatically. please help. thanks.

like image 502
freeloader Avatar asked Jun 20 '12 05:06

freeloader


People also ask

How do you insert a page break in Dompdf?

Using page-break-inside: auto; basically says to dompdf "do what you would normally do when breaking pages." To force a page break before/after your table you would use page-break-before: always; / page-break-after: always; . To ask dompdf to avoid breaking inside an element you would use page-break-inside: avoid; .

How do I change the page size of a PDF in Dompdf?

By default it's going to render on 'US Letter', you can change this by using: $dompdf->set_paper(DEFAULT_PDF_PAPER_SIZE, 'portrait'); You can use 'letter', 'legal', 'A4', etc.. With dompdf 0.6 you can also use the CSS @page rule to set your page size/orientation.

How do I use Dompdf in Wordpress?

// EXAMPLE TAKEN FROM https://github.com/dompdf/dompdf // reference the Dompdf namespace use Dompdf\Dompdf; // instantiate and use the dompdf class $dompdf = new Dompdf(); $dompdf->loadHtml('hello world'); // (Optional) Setup the paper size and orientation $dompdf->setPaper('A4', 'landscape'); // Render the HTML as PDF ...


1 Answers

Whether a PDF is downloaded or viewed in the browser depends on a couple of factors. One is your browser settings, but we have no control there. The second is how dompdf present the PDF to the browser. You can tell dompdf to offer the PDF for direct viewing using $dompdf->stream('my.pdf',array('Attachment'=>0));.

As far as opening in a new tab. That depends on how you are generating the PDF. But the simplest way it to provide a link with a target attribute.

like image 160
BrianS Avatar answered Sep 19 '22 19:09

BrianS