Monday, 9 September 2019

How can I replace PDF content of a window?

I'm displaying a PDF inside another window by using base64 encoded data and this is working perfectly using

this.pdfWindow = window.open('', '_blank', 'toolbar=0,location=0,menubar=0');
this.pdfWindow.document.write("<iframe id='pdf_frame' width='100%' height='100%' src='data:application/pdf;base64, " + encodeURI(res)+"'></iframe>")

But I would like to be able to update the content of this window and change the PDF file that is represented there.

I've tried to do another write but this is just appending the other PDF below the current one.

I've tried this as well:

this.pdfWindow.document.getElementById('pdf_frame').innerHTML = newContent;

Nothing happened.

I've also tried removing and re-appending the frame without success:

this.pdfWindow.document.removeChild(this.pdfWindow.document.getElementById('pdf_frame'));
this.pdfWindow.document.write("<iframe id='pdf_frame' width='100%' height='100%' src='data:application/pdf;base64, " + encodeURI(res)+"'></iframe>");

Still nothing happening.

I'm surely missing something but can't find it.

Thanks for futures answers.



from How can I replace PDF content of a window?

No comments:

Post a Comment