To view a base64 encoded PDF in React, you can use the following code:
Copy codeimport React from "react";
const ViewPdf = ({ base64 }) => {
return (
<iframe
src={`data:application/pdf;base64,${base64}`}
style={{ width: "100%", height: "100%" }}
/>
);
};
export default ViewPdf;
This component uses an iframe
element with a src
attribute that is set to the base64 encoded PDF. The src
attribute is set using a data
URI, which allows you to embed the PDF directly in the HTML without needing to link to an external file.
To use the component, you can pass the base64 encoded PDF as a prop to the component like this:
Copy code<ViewPdf base64={base64EncodedPdf} />
This will render the PDF in the component, allowing the user to view it in the browser.
I hope this helps! Let me know if you have any other questions or if there’s anything else I can do to assist.
Last modified: March 3, 2023