Load documents in Vue PDF Viewer control
Load or switch PDF documents dynamically after the initial load. Use the load method to load a PDF by Base64 string or file name.
The following steps show how to load a PDF dynamically.
Step 1: Follow the steps provided in the link to create a simple PDF Viewer sample.
Step 2: Use the following code to load a PDF 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 to load a PDF by 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