I’m using TCPDF class to generate PDF. First I send some data in json format (jquery) then I would like to generate PDF with these data.
Could you tell me if I am right. I should generate pdf, save it on the server and then if ajax call returns success, redirect the user to this pdf. Is a good way?
I have:
$.ajax({
url: '/pdf/fiele_to_generate_pdf.php',
type: 'POST',
contentType: "application/json; charset=utf-8",
data: $.toJSON(jsonObj),
processData: false,
dataType: 'html',
async: false,
success: function(html) {
window.location.href = '/pdf/example.pdf';
}
});
Thanks for any advice.
Edit: So I have sent a request to make the pdf via Ajax to the server, then the pdf file was generated and saved on the server. Then I have used window.location.href to redirect the user to this pdf. Everything works but I would like to avoid saving file on the server. Any ideas?
Ok this script will save the file and also display in the browser
the trick is in using the output method with the ‘F’ or ‘I’:
CODE