I have a website that re-directs to a php page. That PHP page generates some svg, then uses Dompdf to allow the user to download the svg as a pdf. The php looks like this:
$dompdf = new Dompdf();
$style = 'style="max-width:100%; max-height:100%;"';
$html = '<img '. $style . ' src="data:image/svg+xml;base64,'.base64_encode($svg).'" style/></div>';
$dompdf->setPaper('letter', 'landscape');
$dompdf->loadHtml($html);
$dompdf->render();
$dompdf->stream();
But now I have a new situation in which I am creating this svg using javascript. I wrote some javascript which looks like this:
var svg = document.querySelector('svg')
const formData3 = new FormData();
formData3.append('svg_data', svg);
fetch('./inc/php/dompdf/printPdf.php', {
method: "POST",
body: formData3
})
So in the file printPdf.php, I just get the svg from $_POST['svg_data']. My question is, how can I return the stream object to javascript and send the pdf to user to download?