Add PDF to PDFViewer from AJAX

1 Answer 238 Views
PDFViewer
Alex
Top achievements
Rank 1
Iron
Iron
Alex asked on 23 Jun 2023, 03:43 PM | edited on 23 Jun 2023, 03:48 PM

Hi. I'm using this plugin for jQuery to download a PDF via AJAX. Here's the code that fetches the PDF from ASP.NET Web API:

fetchFile: function (id) {
	return new Promise(function (resolve, reject) {
		$.ajax({
			async: true,
			dataType: "native",			// Uses the jquery-ajax-native plugin for blobs.
			type: "POST",
			url: `https://someapp.org/api/files/file/fetch/${id}`,
			xhrFields: {				// Uses the jquery-ajax-native plugin for blobs.
				responseType: "blob"
			},
			cache: false
		}).done(function (data) {
			return resolve(data);
		}).fail(function (xhr, status, error) {
			const errorObj = new Error(xhr.responseText || error);
			return reject(errorObj);
		});
	});
}

I would like to feed the BLOB data returned by the fetchPdf function to set the PDFViewer's data. Is this possible? Maybe PDFViewer can fetch via AJAX directly. Any examples?

Thank you.

1 Answer, 1 is accepted

Sort by
1
Accepted
Neli
Telerik team
answered on 28 Jun 2023, 10:31 AM

Hello Alex,

In case you need to load a blob into the PDFViewer you can consider using the pdfjsProcessing.file.data option that specifies the data to be passed to the pdfjs processor. Please take a look at the example linked below that demonstrates how the configuration can be used to load a file in the PDFViewer component

- https://docs.telerik.com/kendo-ui/api/javascript/ui/pdfviewer/configuration/pdfjsprocessing.file.data

Regards,
Neli
Progress Telerik

As of R2 2023, the default icon type will be SVG instead of Font. See this blogpost for more information.
Tags
PDFViewer
Asked by
Alex
Top achievements
Rank 1
Iron
Iron
Answers by
Neli
Telerik team
Share this question
or