Unplanned
Last Updated: 22 May 2020 11:37 by ADMIN
Marcel
Created on: 18 May 2020 05:40
Category: PDFViewer
Type: Feature Request
0
native header/token file request in PDFViewer

Hi,

currently i found an workaround for the request but a native support would by cool. Token in url is no alternative

 

Workaround:

axios({
	url: `${config.apiUrl}/Page/pdf/` + id,
	method: 'GET',
	responseType: 'blob',
	headers : {
		"Authorization": authHeader().Authorization
	}
}).then((response) =>{
	var fileReader = new FileReader();
	fileReader.readAsDataURL(response.data);
	fileReader.onload = function(e){
		var pdfViewer = $("#documentViewer").data("kendoPDFViewer");
		if(!pdfViewer){
			pdfViewer = $("#documentViewer").kendoPDFViewer({
				pdfjsProcessing: {
					file: {
						data: e.target.result.split(",")[1]
					}
				},
				width: "100%",
			}).data("kendoPDFViewer");
		}else{
			console.log("fromFile function");
			// pdfViewer.fromFile(`${config.apiUrl}/Page/pdf/` + id);
			pdfViewer.zoomScale = pdfViewer.options.scale || 1.25;
			pdfViewer.trigger("update", { action: "zoom", zoom: pdfViewer.options.scale || "auto" });
			pdfViewer.options.pdfjsProcessing.file.data = e.target.result.split(",")[1];
			pdfViewer._loadDocument();
		}
	}
})

 

Added by admin:

The request is a valid one but it should be extended outside the context of Axios. It will be a good feature to introduce a general approach for fetching a file dynamically - jQuery, Axios, etc.

1 comment
ADMIN
Petar
Posted on: 22 May 2020 11:37

Hi Marcel,

Thank you for sharing the workaround that works in the context of Axios. The request is a valid one but should be extended outside the context of Axios. 

I've added some text below your post and changed the status of the request. Based on the community interest and the votes the request collects, we might consider the implementation of the requested functionality in the future. 

Regards,
Petar
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.