View PDF files in Svelte application
GemBox.PdfViewer can be easily integrated into Svelte projects.
First, you need to install GemBox.PdfViewer using NPM or Yarn with one of the following commands:
npm install @gembox/pdfviewer
# or
yarn add @gembox/pdfviewer
After that you can use GemBox.PdfViewer in your Svelte components. Following example is a basic PDF Viewer component:
<script>
import { onMount } from 'svelte';
import { GemBoxPdfViewer } from '@gembox/pdfviewer';
import '@gembox/pdfviewer/dist/es/pdfviewer.css';
GemBoxPdfViewer.setLicense("FREE-LIMITED-KEY");
let viewerElement;
onMount(() => {
GemBoxPdfViewer.create({
container: viewerElement
});
});
</script>
<div bind:this={viewerElement} style="width: 600px; height: 350px;"></div>
You can save this component as PdfViewer.svelte
and use it throughout your Svelte application as needed:
<script>
import PdfViewer from './PdfViewer.svelte';
</script>
<PdfViewer />