void SaveDocument(SaveType type) { if (!SBSDK.IsLicenseValid()) { Alert.ShowLicenseDialog(this); return; } Task.Run(delegate { var input = adapter.GetDocumentUris().ToArray(); var output = GetOutputUri(".pdf"); if (type == SaveType.TIFF) { output = GetOutputUri(".tiff"); // Please note that some compression types are only compatible for 1-bit encoded images (binarized black & white images)! var options = new TiffOptions { OneBitEncoded = true, Compression = TiffCompressionOptions.CompressionCcittfax4, Dpi = 250 }; bool success = SBSDK.WriteTiff(input, output, options); } else if (type == SaveType.OCR) { var languages = SBSDK.GetOcrConfigs().InstalledLanguages.ToArray(); if (languages.Length == 0) { RunOnUiThread(delegate { Alert.Toast(this, "OCR languages blobs are not available"); }); return; } SBSDK.PerformOCR(input, languages, output); } else { SBSDK.CreatePDF(input, output, ScanbotSDK.Xamarin.PDFPageSize.FixedA4); } Java.IO.File file = Copier.Copy(this, output); var intent = new Intent(Intent.ActionView, output); var authority = ApplicationContext.PackageName + ".provider"; var uri = FileProvider.GetUriForFile(this, authority, file); intent.SetDataAndType(uri, MimeUtils.GetMimeByName(file.Name)); intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask); intent.AddFlags(ActivityFlags.GrantReadUriPermission | ActivityFlags.GrantWriteUriPermission); RunOnUiThread(delegate { StartActivity(Intent.CreateChooser(intent, output.LastPathSegment)); Alert.Toast(this, "File saved to: " + output.Path); }); }); }
private void OnSaveButtonClick(object sender, EventArgs e) { var input = PageRepository.DocumentImageURLs; var docs = NSSearchPathDirectory.DocumentDirectory; var nsurl = NSFileManager.DefaultManager.GetUrls(docs, NSSearchPathDomain.User)[0]; var controller = UIAlertController.Create(Texts.save, Texts.SaveHow, UIAlertControllerStyle.ActionSheet); var title = "Oops!"; var body = "Something went wrong with saving your file. Please try again"; if (!SBSDK.IsLicenseValid()) { title = "Oops"; body = "Your license has expired"; Alert.Show(this, title, body); return; } var pdf = CreateButton(Texts.save_without_ocr, delegate { var output = new NSUrl(nsurl.AbsoluteString + Guid.NewGuid() + ".pdf"); SBSDK.CreatePDF(input, output, PDFPageSize.FixedA4); OpenDocument(output, false); }); var ocr = CreateButton(Texts.save_with_ocr, delegate { var output = new NSUrl(nsurl.AbsoluteString + Guid.NewGuid() + ".pdf"); var languages = SBSDK.GetOcrConfigs().InstalledLanguages; try { SBSDK.PerformOCR(input, languages.ToArray(), output); OpenDocument(output, true); } catch (Exception ex) { body = ex.Message; Alert.Show(this, title, body); } }); var tiff = CreateButton(Texts.Tiff, delegate { var output = new NSUrl(nsurl.AbsoluteString + Guid.NewGuid() + ".tiff"); // Please note that some compression types are only compatible for 1-bit encoded images (binarized black & white images)! var options = new TiffOptions { OneBitEncoded = true, Compression = TiffCompressionOptions.CompressionCcittfax4, Dpi = 250 }; bool success = SBSDK.WriteTiff(input, output, options); if (success) { title = "Info"; body = "TIFF file saved to: " + output.Path; } Alert.Show(this, title, body); }); var cancel = CreateButton("Cancel", delegate { }, UIAlertActionStyle.Cancel); controller.AddAction(pdf); controller.AddAction(ocr); controller.AddAction(tiff); controller.AddAction(cancel); UIPopoverPresentationController presentationPopover = controller.PopoverPresentationController; if (presentationPopover != null) { presentationPopover.SourceView = View; presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up; } PresentViewController(controller, true, null); }