I have a fetch
request that returns a PDF stream:
// from the php code:
public function getPdfContent() {
return response($pdf, 200)
->header('Content-Type', 'application/pdf');
}
And the fetch
:
fetch(`/get-pdf-content)
.then(response =>
)
Is it possible to set an <embed>
content to show the PDF as if I had put the URL directly as src
?
<embed src="/get-pdf-content">
Because I am creating different PDFs in the backend then I want to dynamically set the <embed>
content based on which button was clicked
2
Maybe you can send the entire <embed>
tag along with the src
from the backend. Then use the dangerouslySetInnerHTML
attribute in any <div>
and give the whole <embed>
tag gotten as response as the attribute’s value.
This would automatically set the <embed>
tag with whatever src
value you assign it at the backend.
example:
<div dangerouslySetInnerHTML={{ __html: "<embed src='...'>" }} />