Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

377
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda