[Libreoffice-commits] online.git: ios/Mobile loleaflet/src

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Feb 26 15:52:50 UTC 2019


 ios/Mobile/DocumentViewController.mm |   27 +++++++++++++++++++++++++++
 loleaflet/src/control/Toolbar.js     |    8 ++++++--
 2 files changed, 33 insertions(+), 2 deletions(-)

New commits:
commit 62ffd2c8358c7f7f9d52471a313f1a053eb967fb
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Tue Feb 26 17:44:00 2019 +0200
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Tue Feb 26 17:45:39 2019 +0200

    tdf#122584: Implement printing in the iOS app
    
    I don't have an AirPrint printer so I couldn't verify that it actually
    prints, but the system print dialog is displayed and shows a preview
    correctly, so I am fairly sure it works.
    
    Change-Id: I5e8a704386cd5053b8689dc63f26e545df323193

diff --git a/ios/Mobile/DocumentViewController.mm b/ios/Mobile/DocumentViewController.mm
index fa3d77648..b6c128b56 100644
--- a/ios/Mobile/DocumentViewController.mm
+++ b/ios/Mobile/DocumentViewController.mm
@@ -294,6 +294,32 @@
             self.webView.hidden = false;
 
             return;
+        } else if ([message.body isEqualToString:@"PRINT"]) {
+
+            // Create the PDF to print.
+
+            std::string printFile = Util::createRandomTmpDir() + "/print.pdf";
+            NSURL *printURL = [NSURL fileURLWithPath:[NSString stringWithUTF8String:printFile.c_str()] isDirectory:NO];
+            lok_document->saveAs([[printURL absoluteString] UTF8String], "pdf", nullptr);
+
+            UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
+            UIPrintInfo *printInfo = [UIPrintInfo printInfo];
+            printInfo.outputType = UIPrintInfoOutputGeneral;
+            printInfo.orientation = UIPrintInfoOrientationPortrait; // FIXME Check the document?
+            printInfo.jobName = @"Document"; // FIXME
+
+            pic.printInfo = printInfo;
+            pic.printingItem = printURL;
+
+            [pic presentFromRect:CGRectZero
+                          inView:self.webView
+                        animated:YES
+               completionHandler:^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
+                    LOG_TRC("print completion handler gets " << (completed?"YES":"NO"));
+                    std::remove(printFile.c_str());
+                }];
+
+            return;
         }
 
         const char *buf = [message.body UTF8String];
@@ -309,3 +335,4 @@
 @end
 
 // vim:set shiftwidth=4 softtabstop=4 expandtab:
+
diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js
index 7e871a0db..3a2a2ddd2 100644
--- a/loleaflet/src/control/Toolbar.js
+++ b/loleaflet/src/control/Toolbar.js
@@ -81,8 +81,12 @@ L.Map.include({
 	},
 
 	print: function () {
-		this.showBusy(_('Downloading...'), false);
-		this.downloadAs('print.pdf', 'pdf', null, 'print');
+		if (window.ThisIsTheiOSApp) {
+			window.postMobileMessage('PRINT');
+		} else {
+			this.showBusy(_('Downloading...'), false);
+			this.downloadAs('print.pdf', 'pdf', null, 'print');
+		}
 	},
 
 	saveAs: function (url, format, options) {


More information about the Libreoffice-commits mailing list