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 nuxt-app compdfkit-appThis will ask you some questions. Choose the default options by pressing Enter. Once you answer all the questions, it’ll install the dependencies and create a new Nuxt.js project. 
Change your directory to compdfkit-app:
cd compdfkit-appnpm i @compdfkit_pdf_sdk/webviewer --savenode_modules/@compdfkit_pdf_sdk/webviewer/dist.cp -a ./node_modules/@compdfkit_pdf_sdk/webviewer/dist/. ./static/webviewerAdd the PDF document you want to display to the static/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.
components/WebViewer.vue —— Create a new component called WebViewer.vue under /components.
<template>
<div id='webviewer' ref='viewer'></div>
</template>
<script>
import { ref, onMounted } from 'vue'
import WebViewer from '@compdfkit_pdf_sdk/webviewer'
export default {
name: 'WebViewer',
setup() {
const viewer = ref(null)
let docViewer = null
onMounted(() => {
WebViewer.init({
path: '/',
pdfUrl: './example/developer_guide_web.pdf',
license: '<Input your license here>'
}, viewer.value).then((instance) => {
docViewer = instance.docViewer
docViewer.addEvent('documentloaded', async () => {
console.log('document loaded')
})
})
})
return {
viewer,
docViewer
}
}
}
</script>
<style>
#webviewer {
height: 100vh;
overflow: hidden;
}
</style>When WebViewer is initialized, it returns an instance of WebViewer that can be used to call a number of useful APIs for document creation, manipulation, annotation, collaboration, and more.
Learn more about WebViewer’s comprehensive functionality by diving into the documentation.
Lastly, the style section helps us apply custom CSS like width and height on the viewer’s div element, which WebViewer gets mounted on.
pages/index.vue —— Here we can drop in our newly created WebViewer component.<template>
<WebViewer />
</template>
<script>
import WebViewer from '../components/WebViewer.vue'
export default {
name: 'app',
components: {
WebViewer
}
}
</script>
<style>
html,
body {
margin: 0;
}
</style>npm run dev