1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-21 23:58:07 +02:00

Content disposition filename

File name is extracted from headers.
This commit is contained in:
Juan Salvador Perez Garcia 2018-01-13 09:01:50 +01:00 committed by Jonas Jenwald
parent 96c573ad38
commit eb1f6f4c24
8 changed files with 139 additions and 21 deletions

View file

@ -154,6 +154,7 @@ let PDFViewerApplication = {
baseUrl: '',
externalServices: DefaultExternalServices,
_boundEvents: {},
contentDispositionFileName: null,
// Called once when the document is loaded.
initialize(appConfig) {
@ -678,6 +679,7 @@ let PDFViewerApplication = {
this.downloadComplete = false;
this.url = '';
this.baseUrl = '';
this.contentDispositionFileName = null;
this.pdfSidebar.reset();
this.pdfOutlineViewer.reset();
@ -801,7 +803,8 @@ let PDFViewerApplication = {
let url = this.baseUrl;
// Use this.url instead of this.baseUrl to perform filename detection based
// on the reference fragment as ultimate fallback if needed.
let filename = getPDFFileNameFromURL(this.url);
let filename = this.contentDispositionFileName ||
getPDFFileNameFromURL(this.url);
let downloadManager = this.downloadManager;
downloadManager.onerror = (err) => {
// This error won't really be helpful because it's likely the
@ -1153,9 +1156,11 @@ let PDFViewerApplication = {
});
});
pdfDocument.getMetadata().then(({ info, metadata, }) => {
pdfDocument.getMetadata().then(
({ info, metadata, contentDispositionFileName, }) => {
this.documentInfo = info;
this.metadata = metadata;
this.contentDispositionFileName = contentDispositionFileName;
// Provides some basic debug information
console.log('PDF ' + pdfDocument.fingerprint + ' [' +
@ -1181,6 +1186,10 @@ let PDFViewerApplication = {
this.setTitle(pdfTitle + ' - ' + document.title);
}
if (!pdfTitle && contentDispositionFileName) {
this.setTitle(contentDispositionFileName);
}
if (info.IsAcroFormPresent) {
console.warn('Warning: AcroForm/XFA is not supported');
this.fallback(UNSUPPORTED_FEATURES.forms);