4

I'm using mPDF server side to create a pdf file. It works okay if I output the file to the server, however, I would like to return a string back to the client and build a pdf file from it which I can then use like any normal file from a file input.

server side, the (simplified) code is

$output_dest = 'S';
$content = $mpdf->Output($post_data->fileName, $output_dest);
//$mpdf->Output($post_data->fileName, 'F'); //just to check that the output should be correct                   
$response->setContent($content);

and client side i've tried using Blobs to create a file

var fileObj = new Blob([offerString], {type : 'application/pdf'});

but there are 2 problems. First, the blob, when sent to the server, doesn't have the required name. Secondly, the pdf file created (using window.saveAs to save the blob) is blank. It has the correct number of pages and author information, but it's completely blank.

If I use mPDF's file output, the resulting file is correct, so the problem must lie somewhere within the string->blob process.

Edit: The solution is to create the Blob not straight from the string but from an arrayBuffer. I've created the arrayBuffer using the solution suggested in another answer here

Community
  • 1
  • 1
Bogdan
  • 1,869
  • 6
  • 24
  • 53

0 Answers0