Displaying generated PDF (not local or external)

Maybe I’m missing something, but PDFs are not images so I don’t see how converting it base64 and trying to display it as an image would work?

If you wanted to do that I’d image these are the steps

  1. Convert the PDF to a PIL object: https://github.com/Belval/pdf2image
  2. Export the PIL object to a PNG: https://stackoverflow.com/a/19651233/2958068
  3. Display in base64 like this: PNG image not showing

However this may not look good and you won’t get PDF features like text selection and copying. The only way I know to display a real PDF on a web-page without relying on external technologies like Adobe Acrobat is to use pdf.js.

It should be possible to take a React version of pdf.js and create a Dash component out of it:

  1. https://www.npmjs.com/package/react-pdf-js
  2. https://dash.plot.ly/react-for-python-developers
  3. https://dash.plot.ly/plugins

But I don’t think it’s a small undertaking.

1 Like