codedge/laravel-fpdf

issue of generated pdf file

khayyak opened this issue · 1 comments

$objPdf = new Fpdf;
$objPdf->AddPage();
$objPdf->SetFont('Arial', '', 10);
$objPdf->SetTitle("Title");
$objPdf->SetAuthor('Author');
$objPdf->Cell(50, 25, 'Hello World!');
$objPdf->AliasNbPages();
$objPdf->Output("","i");
ob_get_clean();

this is my code but generated pdf file not display on browser , but when I replace $objPdf->Output("","i"); by $objPdf->Output("","f"); it works good and save file on server . so what is the problem here and thanks

I found a solution , the issue was because of using axios so I need to add this code to have a possibility to download PDF file .
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
link.click();
});