Created
March 12, 2024 12:26
-
-
Save bjoerntx/54b635a8df9f04d6ea776c8d9b3dbc25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useRef, useEffect } from 'react'; | |
import DocumentViewer from '@txtextcontrol/tx-react-document-viewer' | |
function App() { | |
useEffect(() => { | |
window.addEventListener('documentViewerLoaded', handleLoaded); | |
}, []); | |
const handleLoaded = (event) => { | |
var xhr = new XMLHttpRequest(); | |
xhr.open("GET", "https://yourapi.domain.com/api/document", true); | |
xhr.setRequestHeader("Access-Control-Allow-Origin", "*"); | |
xhr.send(); | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState == 4) { | |
event.srcElement['TXDocumentViewer'].loadDocument(btoa(xhr.responseText), "loaded.html"); | |
} | |
} | |
}; | |
return ( | |
<DocumentViewer | |
width="1000px" | |
height="800px" | |
basePath="https://backend.textcontrol.com?access-token=yourtoken"> | |
</DocumentViewer> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment