Merge pull request #1411 from ONLYOFFICE/feature/download-pdf

[DE] Save pdf/xps to other formats
This commit is contained in:
Julia Radzhabova 2021-12-14 14:18:20 +03:00 committed by GitHub
commit f2200af147
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 66 deletions

View file

@ -87,7 +87,6 @@ define([
'menu:show': _.bind(this.menuFilesShowHide, this, 'show'), 'menu:show': _.bind(this.menuFilesShowHide, this, 'show'),
'item:click': _.bind(this.clickMenuFileItem, this), 'item:click': _.bind(this.clickMenuFileItem, this),
'saveas:format': _.bind(this.clickSaveAsFormat, this), 'saveas:format': _.bind(this.clickSaveAsFormat, this),
'savecopy:format': _.bind(this.clickSaveCopyAsFormat, this),
'settings:apply': _.bind(this.applySettings, this), 'settings:apply': _.bind(this.applySettings, this),
'create:new': _.bind(this.onCreateNew, this), 'create:new': _.bind(this.onCreateNew, this),
'recent:open': _.bind(this.onOpenRecent, this) 'recent:open': _.bind(this.onOpenRecent, this)
@ -244,11 +243,11 @@ define([
case 'save-desktop': this.api.asc_DownloadAs(); break; case 'save-desktop': this.api.asc_DownloadAs(); break;
case 'saveas': case 'saveas':
if ( isopts ) close_menu = false; if ( isopts ) close_menu = false;
else this.clickSaveAsFormat(undefined); else this.clickSaveAsFormat();
break; break;
case 'save-copy': case 'save-copy':
if ( isopts ) close_menu = false; if ( isopts ) close_menu = false;
else this.clickSaveCopyAsFormat(undefined); else this.clickSaveAsFormat(undefined, undefined, true);
break; break;
case 'print': this.api.asc_Print(new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86)); break; case 'print': this.api.asc_Print(new Asc.asc_CDownloadOptions(null, Common.Utils.isChrome || Common.Utils.isOpera || Common.Utils.isGecko && Common.Utils.firefoxVersion>86)); break;
case 'exit': Common.NotificationCenter.trigger('goback'); break; case 'exit': Common.NotificationCenter.trigger('goback'); break;
@ -307,8 +306,12 @@ define([
} }
}, },
clickSaveAsFormat: function(menu, format) { _saveAsFormat: function(menu, format, ext, textParams) {
var needDownload = !!ext;
if (menu) { if (menu) {
var options = new Asc.asc_CDownloadOptions(format, needDownload);
options.asc_setTextParams(textParams);
if (format == Asc.c_oAscFileType.TXT || format == Asc.c_oAscFileType.RTF) { if (format == Asc.c_oAscFileType.TXT || format == Asc.c_oAscFileType.RTF) {
Common.UI.warning({ Common.UI.warning({
closable: false, closable: false,
@ -317,10 +320,11 @@ define([
buttons: ['ok', 'cancel'], buttons: ['ok', 'cancel'],
callback: _.bind(function(btn){ callback: _.bind(function(btn){
if (btn == 'ok') { if (btn == 'ok') {
this.isFromFileDownloadAs = ext;
if (format == Asc.c_oAscFileType.TXT) if (format == Asc.c_oAscFileType.TXT)
Common.NotificationCenter.trigger('download:advanced', Asc.c_oAscAdvancedOptionsID.TXT, this.api.asc_getAdvancedOptions(), 2, new Asc.asc_CDownloadOptions(format)); Common.NotificationCenter.trigger('download:advanced', Asc.c_oAscAdvancedOptionsID.TXT, this.api.asc_getAdvancedOptions(), 2, options);
else else
this.api.asc_DownloadAs(new Asc.asc_CDownloadOptions(format)); this.api.asc_DownloadAs(options);
menu.hide(); menu.hide();
} }
}, this) }, this)
@ -337,78 +341,55 @@ define([
callback: _.bind(function(btn, dontshow){ callback: _.bind(function(btn, dontshow){
if (dontshow) Common.localStorage.setItem("de-hide-save-compatible", 1); if (dontshow) Common.localStorage.setItem("de-hide-save-compatible", 1);
if (btn == 'ok') { if (btn == 'ok') {
this.api.asc_DownloadAs(new Asc.asc_CDownloadOptions(format)); this.isFromFileDownloadAs = ext;
this.api.asc_DownloadAs(options);
menu.hide(); menu.hide();
} }
}, this) }, this)
}); });
} else { } else {
var opts = new Asc.asc_CDownloadOptions(Asc.c_oAscFileType.DOCX); this.isFromFileDownloadAs = ext;
opts.asc_setCompatible(!!Common.Utils.InternalSettings.get("de-settings-compatible")); options.asc_setCompatible(!!Common.Utils.InternalSettings.get("de-settings-compatible"));
this.api.asc_DownloadAs(opts); this.api.asc_DownloadAs(options);
menu.hide(); menu.hide();
} }
} else { } else {
this.api.asc_DownloadAs(new Asc.asc_CDownloadOptions(format)); this.isFromFileDownloadAs = ext;
this.api.asc_DownloadAs(options);
menu.hide(); menu.hide();
} }
} else } else {
this.api.asc_DownloadOrigin(); this.isFromFileDownloadAs = needDownload;
this.api.asc_DownloadOrigin(needDownload);
}
}, },
clickSaveCopyAsFormat: function(menu, format, ext) { clickSaveAsFormat: function(menu, format, ext) { // ext isn't undefined for save copy as
if (menu) { var me = this,
if (format == Asc.c_oAscFileType.TXT || format == Asc.c_oAscFileType.RTF) { fileType = this.getApplication().getController('Main').document.fileType;
Common.UI.warning({ if ( /^pdf|xps|oxps$/.test(fileType)) {
closable: false, if (format===undefined || format == Asc.c_oAscFileType.PDF || format == Asc.c_oAscFileType.PDFA || format == Asc.c_oAscFileType.XPS)
title: this.notcriticalErrorTitle, this._saveAsFormat(undefined, format, ext); // download original
msg: (format == Asc.c_oAscFileType.TXT) ? this.warnDownloadAs : this.warnDownloadAsRTF, else {
buttons: ['ok', 'cancel'], (new Common.Views.OptionsDialog({
callback: _.bind(function(btn){ width: 300,
if (btn == 'ok') { title: this.titleConvertOptions,
this.isFromFileDownloadAs = ext; label: this.textGroup,
if (format == Asc.c_oAscFileType.TXT) items: [
Common.NotificationCenter.trigger('download:advanced', Asc.c_oAscAdvancedOptionsID.TXT, this.api.asc_getAdvancedOptions(), 2, new Asc.asc_CDownloadOptions(format, true)); {caption: this.textChar, value: Asc.c_oAscTextAssociation.Char, checked: true},
else {caption: this.textLine, value: Asc.c_oAscTextAssociation.Line, checked: false},
this.api.asc_DownloadAs(new Asc.asc_CDownloadOptions(format, true)); {caption: this.textParagraph, value: Asc.c_oAscTextAssociation.Block, checked: false}
menu.hide(); ],
handler: function (dlg, result) {
if (result=='ok') {
me._saveAsFormat(menu, format, ext, new AscCommon.asc_CTextParams(dlg.getSettings()));
} }
}, this) Common.NotificationCenter.trigger('edit:complete', me.toolbar);
});
} else if (format == Asc.c_oAscFileType.DOCX) {
if (!Common.Utils.InternalSettings.get("de-settings-compatible") && !Common.localStorage.getBool("de-hide-save-compatible") && this.api.asc_isCompatibilityMode()) {
Common.UI.warning({
closable: false,
width: 600,
title: this.notcriticalErrorTitle,
msg: this.txtCompatible,
buttons: ['ok', 'cancel'],
dontshow: true,
callback: _.bind(function(btn, dontshow){
if (dontshow) Common.localStorage.setItem("de-hide-save-compatible", 1);
if (btn == 'ok') {
this.isFromFileDownloadAs = ext;
this.api.asc_DownloadAs(new Asc.asc_CDownloadOptions(format, true));
menu.hide();
} }
}, this) })).show();
});
} else {
this.isFromFileDownloadAs = ext;
var opts = new Asc.asc_CDownloadOptions(Asc.c_oAscFileType.DOCX, true);
opts.asc_setCompatible(!!Common.Utils.InternalSettings.get("de-settings-compatible"));
this.api.asc_DownloadAs(opts);
menu.hide();
}
} else {
this.isFromFileDownloadAs = ext;
this.api.asc_DownloadAs(new Asc.asc_CDownloadOptions(format, true));
menu.hide();
}
} else {
this.isFromFileDownloadAs = true;
this.api.asc_DownloadOrigin(true);
} }
} else
this._saveAsFormat(menu, format, ext);
}, },
onDownloadUrl: function(url, fileType) { onDownloadUrl: function(url, fileType) {
@ -944,7 +925,12 @@ define([
warnDownloadAs : 'If you continue saving in this format all features except the text will be lost.<br>Are you sure you want to continue?', warnDownloadAs : 'If you continue saving in this format all features except the text will be lost.<br>Are you sure you want to continue?',
warnDownloadAsRTF : 'If you continue saving in this format some of the formatting might be lost.<br>Are you sure you want to continue?', warnDownloadAsRTF : 'If you continue saving in this format some of the formatting might be lost.<br>Are you sure you want to continue?',
txtUntitled: 'Untitled', txtUntitled: 'Untitled',
txtCompatible: 'The document will be saved to the new format. It will allow to use all the editor features, but might affect the document layout.<br>Use the \'Compatibility\' option of the advanced settings if you want to make the files compatible with older MS Word versions.' txtCompatible: 'The document will be saved to the new format. It will allow to use all the editor features, but might affect the document layout.<br>Use the \'Compatibility\' option of the advanced settings if you want to make the files compatible with older MS Word versions.',
titleConvertOptions: 'Grouping options',
textGroup: 'Group by',
textChar: 'Char',
textLine: 'Line',
textParagraph: 'Paragraph'
}, DE.Controllers.LeftMenu || {})); }, DE.Controllers.LeftMenu || {}));
}); });

View file

@ -1454,10 +1454,10 @@ define([
this.appOptions.canChat = false; this.appOptions.canChat = false;
} }
var type = /^(?:(pdf|djvu|xps|oxps))$/.exec(this.document.fileType); var type = /^(?:(djvu))$/.exec(this.document.fileType);
this.appOptions.canDownloadOrigin = this.permissions.download !== false && (type && typeof type[1] === 'string'); this.appOptions.canDownloadOrigin = this.permissions.download !== false && (type && typeof type[1] === 'string');
this.appOptions.canDownload = this.permissions.download !== false && (!type || typeof type[1] !== 'string'); this.appOptions.canDownload = this.permissions.download !== false && (!type || typeof type[1] !== 'string');
this.appOptions.canUseThumbnails = this.appOptions.canUseViwerNavigation = /^(?:(pdf|djvu|xps))$/.test(this.document.fileType); this.appOptions.canUseThumbnails = this.appOptions.canUseViwerNavigation = /^(?:(pdf|djvu|xps|oxps))$/.test(this.document.fileType);
this.appOptions.canDownloadForms = this.appOptions.canLicense && this.appOptions.canDownload; this.appOptions.canDownloadForms = this.appOptions.canLicense && this.appOptions.canDownload;
this.appOptions.fileKey = this.document.key; this.appOptions.fileKey = this.document.key;

View file

@ -98,6 +98,11 @@ define([
}, },
render: function() { render: function() {
if (/^pdf|xps|oxps$/.test(this.fileType)) {
this.formats[0].splice(1, 1); // remove pdf
this.formats[1].splice(1, 1); // remove pdfa
this.formats[3].push({name: 'Original', imgCls: 'pdf', type: ''});
}
if (this.mode && !this.mode.canFeatureForms) { if (this.mode && !this.mode.canFeatureForms) {
this.formats[2].splice(1, 2); this.formats[2].splice(1, 2);
this.formats[2] = this.formats[2].concat(this.formats[3]); this.formats[2] = this.formats[2].concat(this.formats[3]);
@ -126,7 +131,7 @@ define([
onFormatClick: function(e) { onFormatClick: function(e) {
var type = e.currentTarget.attributes['format']; var type = e.currentTarget.attributes['format'];
if (!_.isUndefined(type) && this.menu) { if (!_.isUndefined(type) && this.menu) {
this.menu.fireEvent('saveas:format', [this.menu, parseInt(type.value)]); this.menu.fireEvent('saveas:format', [this.menu, type.value ? parseInt(type.value) : undefined]);
} }
} }
}); });
@ -181,6 +186,11 @@ define([
}, },
render: function() { render: function() {
if (/^pdf|xps|oxps$/.test(this.fileType)) {
this.formats[0].splice(1, 1); // remove pdf
this.formats[1].splice(1, 1); // remove pdfa
this.formats[3].push({name: 'Original', imgCls: 'pdf', type: '', ext: true});
}
if (this.mode && !this.mode.canFeatureForms) { if (this.mode && !this.mode.canFeatureForms) {
this.formats[2].splice(1, 2); this.formats[2].splice(1, 2);
this.formats[2] = this.formats[2].concat(this.formats[3]); this.formats[2] = this.formats[2].concat(this.formats[3]);
@ -210,7 +220,7 @@ define([
var type = e.currentTarget.attributes['format'], var type = e.currentTarget.attributes['format'],
ext = e.currentTarget.attributes['format-ext']; ext = e.currentTarget.attributes['format-ext'];
if (!_.isUndefined(type) && !_.isUndefined(ext) && this.menu) { if (!_.isUndefined(type) && !_.isUndefined(ext) && this.menu) {
this.menu.fireEvent('savecopy:format', [this.menu, parseInt(type.value), ext.value]); this.menu.fireEvent('saveas:format', [this.menu, type.value ? parseInt(type.value) : undefined, ext.value]);
} }
} }
}); });