Load documents in Vue Pdfviewer component
18 Nov 201812 minutes to read
The PDF Viewer library allows you to switch or load PDF documents dynamically after the initial load operation. To achieve this, load the PDF document as a base64 string or file name into the PDF Viewer control using the Load() method dynamically.
The following steps are used to load the PDF document dynamically.
Step 1: Follow the steps provided in the link to create a simple PDF Viewer sample.
Step 2: Use the following code snippet to load the PDF document using a base64 string.
<template>
<div id="app">
<button v-on:click="load">LoadDocument</button>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath">
</ejs-pdfviewer>
</div>
</template>
<script setup>
import {
PdfViewerComponent as EjsPdfviewer, Toolbar, Magnification, Navigation,
LinkAnnotation, BookmarkView, Annotation, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner
} from '@syncfusion/ej2-vue-pdfviewer';
import { provide, ref } from 'vue';
const pdfviewer = ref(null);
const documentPath = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf";
provide('PdfViewer', [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, Annotation,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner])
// Load the PDF document from a Base64 string
const load = function (event) {
var viewer = pdfviewer.value.ej2Instances;
viewer.load('data:application/pdf;base64', +AddBase64String, null);
}
</script>
<template>
<div id="app">
<button v-on:click="load">LoadDocument</button>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath">
</ejs-pdfviewer>
</div>
</template>
<script>
import {
PdfViewerComponent, Toolbar, Magnification, Navigation,
LinkAnnotation, BookmarkView, Annotation, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner
} from '@syncfusion/ej2-vue-pdfviewer';
export default {
name: "App",
components: {
"ejs-pdfviewer": PdfViewerComponent
},
data() {
return {
documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf",
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, Annotation,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner]
},
methods: {
// Load the PDF document from a Base64 string
load: function (event) {
var viewer = this.$refs.pdfviewer.ej2Instances;
viewer.load('data:application/pdf;base64', +AddBase64String, null);
}
}
}
</script>
<template>
<div>
<button v-on:click="load_1">LoadDocumentFromBase64</button>
<div>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :serviceUrl="serviceUrl" :documentPath="documentPath">
</ejs-pdfviewer>
</div>
</div>
</template>
<script setup>
import {
PdfViewerComponent as EjsPdfviewer, Toolbar, Magnification, Navigation, LinkAnnotation,
BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
Annotation, FormDesigner, FormFields
} from '@syncfusion/ej2-vue-pdfviewer';
import { provide, ref } from 'vue';
const pdfviewer = ref(null);
const serviceUrl = "https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer";
const documentPath = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf";
provide('PdfViewer', [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView,
Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields])
// Load the PDF document from a Base64 string
const load_1 = function (event) {
var viewer = pdfviewer.value.ej2Instances;
viewer.load('data:application/pdf;base64,' + AddBase64String, null);
}
</script>
<template>
<div>
<button v-on:click="load_1">LoadDocumentFromBase64</button>
<div>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :serviceUrl="serviceUrl" :documentPath="documentPath">
</ejs-pdfviewer>
</div>
</div>
</template>
<script>
import {
PdfViewerComponent, Toolbar, Magnification, Navigation, LinkAnnotation,
BookmarkView, ThumbnailView, Print, TextSelection, TextSearch,
Annotation, FormDesigner, FormFields
} from '@syncfusion/ej2-vue-pdfviewer';
export default {
name: "App",
components: {
"ejs-pdfviewer": PdfViewerComponent
},
data() {
return {
serviceUrl: "https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer",
documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView,
Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields]
},
methods: {
// Load the PDF document from a Base64 string
load_1: function (event) {
var viewer = this.$refs.pdfviewer.ej2Instances;
viewer.load('data:application/pdf;base64,' + AddBase64String, null);
}
}
}
</script>
Step 3: Use the following code snippet to load the PDF document using the document name.
<template>
<div id="app">
<button v-on:click="load_2">LoadDocument</button>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath">
</ejs-pdfviewer>
</div>
</template>
<script setup>
import {
PdfViewerComponent as EjsPdfviewer, Toolbar, Magnification, Navigation,
LinkAnnotation, BookmarkView, Annotation, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner
} from '@syncfusion/ej2-vue-pdfviewer';
import { provide, ref } from 'vue';
const pdfviewer = ref(null);
const documentPath = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf";
provide('PdfViewer', [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, Annotation,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner])
const load_2 = function (event) {
// Load the PDF document using the file name
let viewer = pdfviewer.value.ej2Instances;
viewer.load('https://cdn.syncfusion.com/content/pdf/hive-succinctly.pdf', null);
}
</script>
<template>
<div id="app">
<button v-on:click="load_2">LoadDocument</button>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath">
</ejs-pdfviewer>
</div>
</template>
<script>
import {
PdfViewerComponent, Toolbar, Magnification, Navigation,
LinkAnnotation, BookmarkView, Annotation, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner
} from '@syncfusion/ej2-vue-pdfviewer';
export default {
name: "App",
components: {
"ejs-pdfviewer": PdfViewerComponent
},
data() {
return {
documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf",
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, Annotation,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner]
},
methods: {
load_2: function (event) {
// Load the PDF document using the file name
let viewer = this.$refs.pdfviewer.ej2Instances;
viewer.load('https://cdn.syncfusion.com/content/pdf/hive-succinctly.pdf', null);
}
}
}
</script>
<template>
<div id="app">
<button v-on:click="load_2">LoadDocument</button>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath" :serviceUrl="serviceUrl">
</ejs-pdfviewer>
</div>
</template>
<script setup>
import {
PdfViewerComponent as EjsPdfviewer, Toolbar, Magnification, Navigation,
LinkAnnotation, BookmarkView, Annotation, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner
} from '@syncfusion/ej2-vue-pdfviewer';
import { provide, ref } from 'vue';
const pdfviewer = ref(null);
const serviceUrl = "https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer";
const documentPath = "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf";
provide('PdfViewer', [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, Annotation,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner])
const load_2 = function (event) {
// Load the PDF document using the file name
let viewer = pdfviewer.value.ej2Instances;
viewer.load('https://cdn.syncfusion.com/content/pdf/hive-succinctly.pdf', null);
}
</script>
<template>
<div id="app">
<button v-on:click="load_2">LoadDocument</button>
<ejs-pdfviewer id="pdfViewer" ref="pdfviewer" :documentPath="documentPath" :serviceUrl="serviceUrl">
</ejs-pdfviewer>
</div>
</template>
<script>
import {
PdfViewerComponent, Toolbar, Magnification, Navigation,
LinkAnnotation, BookmarkView, Annotation, ThumbnailView,
Print, TextSelection, TextSearch, FormFields, FormDesigner
} from '@syncfusion/ej2-vue-pdfviewer';
export default {
name: "App",
components: {
"ejs-pdfviewer": PdfViewerComponent
},
data() {
return {
serviceUrl: "https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer",
documentPath: "https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, Annotation,
ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner]
},
methods: {
load_2: function (event) {
// Load the PDF document using the file name
let viewer = this.$refs.pdfviewer.ej2Instances;
viewer.load('https://cdn.syncfusion.com/content/pdf/hive-succinctly.pdf', null);
}
}
}
</script>
Find the sample, how to load PDF documents dynamically