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:
npm init vite@latest compdfkit-app --template sveltecd compdfkit-appnpm installnpm 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 a component wrapper for the ComPDFKit library and save it as src/lib/WebViewer.svelte:
<script>
import { onMount } from 'svelte';
import WebViewer from '@compdfkit_pdf_sdk/webviewer';
let container;
let docViewer;
onMount(() => {
WebViewer.init({
path: '/',
pdfUrl: './example/developer_guide_web.pdf',
license: '<Input your license here>'
}, container).then((instance) => {
docViewer = instance.docViewer
docViewer.addEvent('documentloaded', async () => {
console.log('document loaded')
})
})
});
</script>
<body>
<div bind:this={container} style="height: 100vh; width: 100%; overflow: hidden;" />
</body>src/App.svelte file with the newly created component:<script>
import WebViewer from './lib/WebViewer.svelte';
</script>
<main>
<WebViewer />
</main>src/app.css file:body { margin: 0; }
#app { margin: 0; }npm run dev