tdf#126968: Implement "Save as PDF" in the iOS app

For now, add an entry "Save as PDF" to the File menu in the iOS app.
Handle in an iOS-specific way in ChildSession::downloadAs(). The PDF
is saved in the app's document directory on the device. The name of
the PDF is the basename of the document being edited with the "pdf"
extension.

Change-Id: Ib0059a86b03b978996eb4cadf230ba7f0abcba62
Reviewed-on: https://gerrit.libreoffice.org/77961
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Tested-by: Tor Lillqvist <tml@collabora.com>
This commit is contained in:
Tor Lillqvist 2019-08-22 15:47:12 +03:00
parent 1b27ed045d
commit 634be102c7
3 changed files with 18 additions and 1 deletions

View file

@ -879,6 +879,15 @@ bool ChildSession::downloadAs(const char* /*buffer*/, int /*length*/, const std:
filterOptions += std::string(",Watermark=") + getWatermarkText() + std::string("WATERMARKEND");
}
#ifdef IOS
NSArray<NSString *> *pathComponents = [[NSURL URLWithString:[NSString stringWithUTF8String:getDocURL().c_str()]] pathComponents];
NSString *baseName = [[pathComponents lastObject] stringByDeletingPathExtension];
NSURL *documentDirectory = [NSFileManager.defaultManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask][0];
NSURL *pdfURL = [documentDirectory URLByAppendingPathComponent:[baseName stringByAppendingString:@".pdf"]];
getLOKitDocument()->saveAs([[pdfURL absoluteString] UTF8String],
format.empty() ? nullptr : format.c_str(),
filterOptions.empty() ? nullptr : filterOptions.c_str());
#else
// The file is removed upon downloading.
const std::string tmpDir = FileUtil::createRandomDir(JAILED_DOCUMENT_ROOT);
// Prevent user inputting anything funny here.
@ -898,6 +907,7 @@ bool ChildSession::downloadAs(const char* /*buffer*/, int /*length*/, const std:
sendTextFrame("downloadas: jail=" + _jailId + " dir=" + tmpDir + " name=" + name +
" port=" + std::to_string(ClientPortNumber) + " id=" + id);
#endif
return true;
}

View file

@ -27,6 +27,7 @@ L.Control.Menubar = L.Control.extend({
{name: _('Word 2003 Document (.doc)'), id: 'downloadas-doc', type: 'action'},
{name: _('Word Document (.docx)'), id: 'downloadas-docx', type: 'action'},
{name: _('Rich Text (.rtf)'), id: 'downloadas-rtf', type: 'action'}]},
{name: _('Save as PDF'), id: 'downloadas-pdf', mobileapp: true, type: 'action'},
{name: _('Sign document'), id: 'signdocument', type: 'action'},
{type: 'separator'},
{name: _('Close document'), id: 'closedocument', type: 'action'}
@ -250,6 +251,7 @@ L.Control.Menubar = L.Control.extend({
{name: _('ODF presentation (.odp)'), id: 'downloadas-odp', type: 'action'},
{name: _('PowerPoint 2003 Presentation (.ppt)'), id: 'downloadas-ppt', type: 'action'},
{name: _('PowerPoint Presentation (.pptx)'), id: 'downloadas-pptx', type: 'action'}]},
{name: _('Save as PDF'), id: 'downloadas-pdf', mobileapp: true, type: 'action'},
{type: 'separator'},
{name: _('Close document'), id: 'closedocument', type: 'action'}
]},
@ -338,6 +340,7 @@ L.Control.Menubar = L.Control.extend({
{name: _('ODF spreadsheet (.ods)'), id: 'downloadas-ods', type: 'action'},
{name: _('Excel 2003 Spreadsheet (.xls)'), id: 'downloadas-xls', type: 'action'},
{name: _('Excel Spreadsheet (.xlsx)'), id: 'downloadas-xlsx', type: 'action'}]},
{name: _('Save as PDF'), id: 'downloadas-pdf', mobileapp: true, type: 'action'},
{type: 'separator'},
{name: _('Close document'), id: 'closedocument', type: 'action'}
]},
@ -996,6 +999,9 @@ L.Control.Menubar = L.Control.extend({
if (menu[i].mobileapp == false && window.ThisIsAMobileApp) {
continue;
}
if (menu[i].mobileapp == true && !window.ThisIsAMobileApp) {
continue;
}
var ulItem = L.DomUtil.create('ul', '', liItem);
var subitemList = this._createMenu(menu[i].menu);
if (!subitemList.length) {

View file

@ -72,7 +72,8 @@ L.Map.include({
options = '';
}
this.showBusy(_('Downloading...'), false);
if (!window.ThisIsAMobileApp)
this.showBusy(_('Downloading...'), false);
this._socket.sendMessage('downloadas ' +
'name=' + encodeURIComponent(name) + ' ' +
'id=' + id + ' ' +