import {
Viewer,
DocumentGate,
useDocument,
useDocuments,
useDocumentsState,
} from '@embedpdf/react/runtime';
import type { OpenInput } from '@embedpdf/react/runtime';
import { Stage, stagePlugin, useStage, useStageState } from '@embedpdf/react/stage';
import { RenderLayer, renderPlugin } from '@embedpdf/react/render';
import { localEngine } from '@embedpdf/engine';
import './tabs.css';
const engine = localEngine();
const plugins = [stagePlugin(), renderPlugin()];
const welcome = async (): Promise => {
const response = await fetch('https://www.embedpdf.com/pdfs/welcome.pdf');
return { kind: 'bytes', bytes: new Uint8Array(await response.arrayBuffer()) };
};
const article = async (): Promise => {
const response = await fetch('https://www.embedpdf.com/pdfs/article.pdf');
return { kind: 'bytes', bytes: new Uint8Array(await response.arrayBuffer()) };
};
const sketch = async (): Promise => {
const response = await fetch('https://www.embedpdf.com/pdfs/sketch.pdf');
return { kind: 'bytes', bytes: new Uint8Array(await response.arrayBuffer()) };
};
function Tabs() {
const documents = useDocuments();
const { documents: open, activeId } = useDocumentsState();
return (
{open.map((document) => (
documents.setActive(document.id)}
>
{document.name}
documents.close(document.id)}
>
×
))}
documents.open(sketch, { name: 'Floor plan' })}
>
+
);
}
// The active tab: rename it, move it to the front, and zoom it. Each tab keeps its own zoom.
function TabTools() {
const documents = useDocuments();
const { id, name } = useDocument();
const stage = useStage();
const zoomLevel = useStageState((state) => state.zoomLevel);
return (
documents.rename(id, event.target.value)}
/>
documents.move(id, 0)}>
Move to front
stage.zoomOut()}
>
−
stage.zoomIn()}>
+
{Math.round(zoomLevel * 100)}%
);
}
export default function App() {
return (
Opening…
}>
{() => }
);
}