I'd like to generate and open PDF when user clicks on a button. Here is my code so far:
index.php:
</html>
<head>
<script>
$('.cmd_butt').click(function() {
$.ajax({
url: 'create_pdf.php',
data: {id: $(this).attr('order_id'), name: $(this).attr('name')},
type: 'post'
});
}
</script>
</head>
<body>
<button class="cmd_butt" order_id="250" name="pdf_but">Download PDF</button>
</body>
</html>
create_pdf.php:
<?php
//header('Content-type: application/pdf')
header("Content-type: application-download");
//header("Content-Length: $size");
header("Content-Disposition: attachment; filename=MyPDF.pdf");
header("Content-Transfer-Encoding: binary");
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
// create new PDF document
// some code
// some code
//$pdf->Output('test.pdf', 'I');
//$pdf->Output('test.pdf', 'FD');
$pdf->Output();
?>
How can I open a new window with generated PDF? Or notify user with "save as" dialog to download this PDF? I've tried different Output() combinations but none of them worked.