L
L
leni_m2017-06-16 14:02:44
PHP
leni_m, 2017-06-16 14:02:44

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);
    });

And the data goes away (status 200), but the pdf does not open, although if you open pdf.php in the browser, the pdf file opens.
Here is the content of pdf.php:
<?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');

And in the pdfInvoice.php file there is a table in html

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-06-16
@leni_m

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 question

Ask a Question

731 491 924 answers to any question