how to display base64 encoded pdf in react js

Create a data URL: The Base64 string must be wrapped in a data URL format. Documentation to the package https://www.npmjs.com/package/base64topdf, try this Import react-read-pdf into . rev2023.3.1.43269. The B64 data is accurate, as it loads in an iframe as such: However, if I insert the data into a react-pdf document as such, I get an error: The Document is rendered with an error message Failed to load PDF file., and the console logs the following error: InvalidPDFException{name: "InvalidPDFException", message: "Invalid PDF structure"}, I also get a lot of warnings like the following: Warning: Ignoring invalid character "109" in hex string. This is actually the reason, I want to use pdf.js. Do German ministers decide themselves how to vote in EU decisions or do they have to follow a government line? Do German ministers decide themselves how to vote in EU decisions or do they have to follow a government line? How to send base64 String from created PDF file to client? Learn more about Teams Thank you for details! How do I remove a property from a JavaScript object? Defines the height of the page. They key part for me was remembering to stripslashes if you addslashes earlier. this.setState ( { fileData: file, fileName: file.name }) } reactjs base64 Share Follow edited Jun 19, 2018 at 8:51 asked Apr 12, 2018 at 11:24 user8998234 Add a comment 1 Answer Sorted by: 2 Asking for help, clarification, or responding to other answers. If neither. By the way, in addition to , you can use or