Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created March 28, 2024 19:58
Show Gist options
  • Save bjoerntx/e4e0b97638eb9d7d2d7cebb951ec14f1 to your computer and use it in GitHub Desktop.
Save bjoerntx/e4e0b97638eb9d7d2d7cebb951ec14f1 to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDOM from 'react-dom/client';
import DocumentViewer from '@txtextcontrol/tx-react-document-viewer';
declare var TXDocumentViewer: any;
const App: React.FC = () => {
const load = (contentValue: string) => {
if (TXDocumentViewer) {
// encode the content to base64
contentValue = btoa(contentValue);
// load the document into the viewer
TXDocumentViewer.loadDocument(contentValue, "loaded.html");
}
};
return <>
<select onChange={e => load(e.currentTarget.value)}>
<option>Select a Document</option>
<option value="Document <strong>#1</strong>">Document 1</option>
<option value="Document <strong>#2</strong>">Document 2</option>
<option value="Document <strong>#3</strong>">Document 3</option>
</select>
<br />
<br />
<DocumentViewer
width="800px"
height="500px"
basePath ="https://backend.textcontrol.com?access-token=O5KVBVClFm7Pus1qESin"
isSelectionActivated={true}>
</DocumentViewer>
</>;
};
const root = ReactDOM.createRoot(document.getElementById('root')!);
root.render(<App />);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment