Answer the question
In order to leave comments, you need to log in
How to open pdf on button?
there is a pdf.php file that opens a pdf generated from html code.
I want that when the button is clicked, data is sent to this file and pdf is opened depending on the data received.
Tried to write jquery:
$('#button').on('click', function () {
var params = {...};
$.post('pdf.php', params);
});
<?php
ob_start();
include 'pdfInvoice.php';
$html = ob_get_contents();
ob_end_clean();
include("mpdf60/mpdf.php");
$mpdf = new mPDF('utf-8', 'A4', '12', '', 10, 10, 7, 7, 10, 10);
$stylesheet = file_get_contents('css/invoice.css'); //подключаем css
$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML($html, 2); //формируем pdf
$mpdf->Output('invoice.pdf', 'I');
Answer the question
In order to leave comments, you need to log in
Ajax will not download.
button/ajax replace with regular <a href="pdf.php?...">Скачать pdf</a>
Update: ... or with
<form action="pdf.php?..."><input type="submit" value="Скачать pdf"></form>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question