How to Use an Authorization Token in Vue PDF Viewer
14 Aug 20263 minutes to read
The PDF Viewer supports adding an authorization token to every AJAX request by configuring the ajaxRequestSettings.ajaxHeaders property. Set the header once and the library includes it in all requests initiated by the viewer.
The following steps are used to include the authorization token in the PDF viewer control.
Step 1: Follow the steps provided in the link to create a simple PDF Viewer sample in Vue.
Step 2: Add the following code snippet to include the authorization token.
<template>
<div>
<ejs-pdfviewer id="pdfViewer" :serviceUrl="serviceUrl" :documentPath="documentPath"
:ajaxRequestSettings="ajaxRequestSettings">
</ejs-pdfviewer>
</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 } from 'vue';
const serviceUrl = "https://document.syncfusion.com/web-services/pdf-viewer/api/pdfviewer";
const documentPath = "PDF_Succinctly.pdf";
// Include Authorization Token.
const ajaxRequestSettings = {
ajaxHeaders: [
{
headerName: 'Authorization',
headerValue: 'Bearer 64565dfgfdsjweiuvbiuyhiueygf'
}
],
withCredentials: false
}
provide('PdfViewer', [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView,
Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields]);
</script><template>
<div>
<ejs-pdfviewer id="pdfViewer" :serviceUrl="serviceUrl" :documentPath="documentPath"
:ajaxRequestSettings="ajaxRequestSettings">
</ejs-pdfviewer>
</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: "PDF_Succinctly.pdf",
// Include Authorization Token.
ajaxRequestSettings: {
ajaxHeaders: [
{
headerName: 'Authorization',
headerValue: 'Bearer 64565dfgfdsjweiuvbiuyhiueygf'
}
],
withCredentials: false
},
};
},
provide: {
PdfViewer: [Toolbar, Magnification, Navigation, LinkAnnotation, BookmarkView, ThumbnailView,
Print, TextSelection, TextSearch, Annotation, FormDesigner, FormFields]
}
}
</script>Find the Sample, how to include authorization token