My web-app sends data via ajax to the server to download either a screen display in HTML or a PDF display generated using TCPDF for printing and saving. My php code is :
$pdf->Output($file_name, 'I');
My JS code is:
$.post(server, data, function(result, status, xhr) {
if (!show_pdf) {
// display html
} else {
var blob = new Blob([xhr.responseText], { type: 'application/pdf' });
var fileURL = URL.createObjectURL(blob);
var newWin = window.open(fileURL);
newWin.focus();
}
The result starts like this...
%PDF-1.7 %���� 9 0 obj << /Type /Page /Parent 1 0 R /LastModified (D:20220129175433+11'00') /Resources 2 0 R /MediaBox [0.000000 0.000000 595.276000 841.890000] /CropBox [0.000000 0.000000 595.276000 841.890000] /BleedBox [0.000000 0.000000 595.276000 841.890000] /TrimBox [0.000000 0.000000 595.276000 841.890000] /ArtBox [0.000000 0.000000 595.276000 841.890000] /Contents 10 0 R /Rotate 0 /Group << /Type /Group /S /Transparency /CS /DeviceRGB >> /Annots [ 5 0 R ] /PZ 1 >> endobj 10 0 obj <</Filter /FlateDecode /Length 38835>> stream x���KקYq��S�M�+����U��Ȁ����FJ����*!k�4vs
... and is about 160k long.
The display result is always blank. What am I doing wrong?