Reputation: 1254
I am using pdf.js library in my application. It has integrated really well except for when i am trying to download the document. Everytime i download a specific file it gets downloaded as document.pdf
I have quite a lot of files to download and this is creating a bit of confusion.
My code goes as below:
<iframe src="pdf_viewer/web/viewer.html?file=/docs/resumes/1b763820-e262-4f76-8502-8872a3cb52e8&filename=sample.pdf"></iframe>
my first parameter is the file id and the second parameter is the name with which the document should be downloaded as.
Below code is the one present in the pdf viewer viewer.js file
function getPDFFileNameFromURL(url) {
var defaultFilename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'document.pdf';
console.log(url);
console.log(defaultFilename);
if (isDataSchema(url)) {
console.warn('getPDFFileNameFromURL: ' + 'ignoring "data:" URL for performance reasons.');
return defaultFilename;
}
var reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
var reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
var splitURI = reURI.exec(url);
var suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
if (suggestedFilename) {
suggestedFilename = suggestedFilename[0];
if (suggestedFilename.indexOf('%') !== -1) {
try {
suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
} catch (ex) {}
}
}
return suggestedFilename || defaultFilename;
}
From my understanding of the code, what i am doing regarding the input is right. Where could i be going wrong ?
Upvotes: 1
Views: 5044
Reputation: 1254
i figured out the solution
<iframe src="pdf_viewer/web/viewer.html?file=/docs/resumes/1b763820-e262-4f76-8502-8872a3cb52e8?sample.pdf"></iframe>
This takes the input in the url, now i can extract filename from the url
Upvotes: 5