Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

372
Views
send svg to dompdf using fetch with javascript then download result

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!