PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
To get started, you'll need:
npx create-react-app compdfkit-appcd compdfkit-appnpm i @compdfkit_pdf_sdk/webviewer --savenode_modules/@compdfkit_pdf_sdk/webviewer/dist.cp -a ./node_modules/@compdfkit_pdf_sdk/webviewer/dist/. ./public/webviewerAdd the PDF document you want to display to the public/webviewer/example directory. You can use our demo document as an example.
When using the Web SDK, you need to use the path parameter to tell it where the copied static resources are located, if not, they will be relative to the current path.
Add the following code to your src/webviewer.js file:
import { useEffect, useRef } from 'react';
import ComPDFKitViewer from '@compdfkit_pdf_sdk/webviewer';
export default function WebViewer() {
const containerRef = useRef(null);
useEffect(() => {
let docViewer = null;
ComPDFKitViewer.init({
path: '/',
pdfUrl: './example/developer_guide_web.pdf',
license: '<Input your license here>'
}, containerRef.current).then((instance) => {
docViewer = instance.docViewer;
docViewer.addEvent('documentloaded', async () => {
console.log('ComPDFKit Web Demo loaded');
})
})
}, []);
return <div ref={containerRef} style={{ width: "100%", height: "100vh", overflow: "hidden" }} />
}src/App.js file with the following. This includes the newly created component in your app:import WebViewer from './webviewer.js';
function App() {
return (
<div className="App">
<WebViewer />
</div>
);
}
export default App;npm start