public override void LayoutSubviews() { base.LayoutSubviews(); nfloat largePadding = 20; nfloat x = largePadding; nfloat y = largePadding; nfloat w = Frame.Width - 2 * x; nfloat h = Frame.Width / 6; if (SBSDK.IsLicenseValid()) { h = 0; } LicenseIndicator.Frame = new CGRect(x, y, w, h); x = 0; y += h + largePadding; w = Frame.Width; h = DocumentScanner.Height; DocumentScanner.Frame = new CGRect(x, y, w, h); y += h + largePadding; h = DataDetectors.Height; DataDetectors.Frame = new CGRect(x, y, w, h); ContentSize = new CGSize(Frame.Width, DataDetectors.Frame.Bottom); }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); if (!SBSDK.IsLicenseValid()) { ContentView.LayoutSubviews(); } foreach (ScannerButton button in ContentView.DocumentScanner.Buttons) { button.Click += OnScannerButtonClick; } foreach (ScannerButton button in ContentView.BarcodeDetectors.Buttons) { button.Click += OnBarcodeButtonClick; } foreach (ScannerButton button in ContentView.DataDetectors.Buttons) { button.Click += OnDataButtonClick; } CameraCallback.Selected += OnScanComplete; }
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); }); }); }
bool CheckScanbotSDKLicense() { if (SBSDK.IsLicenseValid()) { // Trial period, valid trial license or valid production license. return(true); } ShowErrorMessage("Scanbot SDK (trial) license has expired!"); return(false); }
protected override void OnResume() { base.OnResume(); if (!SBSDK.IsLicenseValid()) { Alert.ShowLicenseDialog(this); } UpdateVisibility(); }
bool CheckScanbotSDKLicense() { if (SBSDK.IsLicenseValid()) { // Trial period, valid trial license or valid production license. return(true); } Toast.MakeText(this, "Scanbot SDK (trial) license has expired!", ToastLength.Long).Show(); return(false); }
bool CheckLicense() { if (SBSDK.IsLicenseValid()) { LicenseIndicator.Visibility = ViewStates.Gone; } else { LicenseIndicator.Visibility = ViewStates.Visible; Alert.Toast(this, "Invalid or missing license"); } return(SBSDK.IsLicenseValid()); }
private void OnScannerButtonClick(object sender, EventArgs e) { if (!SBSDK.IsLicenseValid()) { ContentView.LayoutSubviews(); return; } var button = (ScannerButton)sender; if (button.Data.Code == ListItemCode.ScanDocument) { var config = SBSDKUIDocumentScannerConfiguration.DefaultConfiguration; config.BehaviorConfiguration.MultiPageEnabled = true; config.BehaviorConfiguration.IgnoreBadAspectRatio = true; config.TextConfiguration.PageCounterButtonTitle = "%d Page(s)"; config.TextConfiguration.TextHintOK = "Don't move.\nCapturing document..."; config.UiConfiguration.BottomBarBackgroundColor = UIColor.Blue; config.UiConfiguration.BottomBarButtonsColor = UIColor.White; // see further customization configs... var controller = SBSDKUIDocumentScannerViewController .CreateNewWithConfiguration(config, CameraCallback); controller.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; PresentViewController(controller, false, null); } else if (button.Data.Code == ListItemCode.ImportImage) { ImagePicker.Instance.Present(this); ImagePicker.Instance.Controller.FinishedPickingMedia += ImageImported; } else if (button.Data.Code == ListItemCode.ViewImages) { OpenImageListController(); } }
private void OnDataButtonClick(object sender, EventArgs e) { if (!SBSDK.IsLicenseValid()) { ContentView.LayoutSubviews(); return; } var button = (ScannerButton)sender; if (button.Data.Code == ListItemCode.ScannerMRZ) { var config = SBSDKUIMachineCodeScannerConfiguration.DefaultConfiguration; config.TextConfiguration.CancelButtonTitle = "Done"; //config.TextConfiguration.FinderTextHint = "Custom finder text ..." // see further customization configs var viewSize = View.Frame.Size; var targetWidth = viewSize.Width - ((viewSize.Width * 0.058) * 2); var aspect = new SBSDKAspectRatio(targetWidth, targetWidth * 0.3); config.UiConfiguration.FinderAspectRatio = aspect; var controller = SBSDKUIMRZScannerViewController .CreateNewWithConfiguration(config, Delegates.MRZ); PresentViewController(controller, true, null); } else if (button.Data.Code == ListItemCode.WorkflowDC) { var ratios = new SBSDKAspectRatio[] { // DC form A5 portrait (e.g. white sheet, AUB Muster 1b/E (1/2018)) new SBSDKAspectRatio(148.0, 210.0), // DC form A6 landscape (e.g. yellow sheet, AUB Muster 1b (1.2018)) new SBSDKAspectRatio(148.0, 105.0) }; var title = "Please align the DC form in the frame."; var name = "DisabilityCertificateFlow"; var steps = new SBSDKUIWorkflowStep[] { new SBSDKUIScanDisabilityCertificateWorkflowStep( title, "", ratios, true, WorkflowStepValidator.OnDCFormStep ) }; PresentController(name, steps); } else if (button.Data.Code == ListItemCode.WorkflowMRZImage) { var title = "Please align the Machine readable card with the form in the frame"; var name = "MRZScanFlow"; var steps = new SBSDKUIWorkflowStep[] { new SBSDKUIScanMachineReadableZoneWorkflowStep( title, "", MRZRatios, true, WorkflowStepValidator.OnIDCardBackStep ) }; PresentController(name, steps); } else if (button.Data.Code == ListItemCode.WorkflowMRZFrontBack) { var name = "MRZBackFrontScanFlow"; var steps = new SBSDKUIWorkflowStep[] { new SBSDKUIWorkflowStep( "Step 1/2", "Please scan the front side of your ID card", MRZRatios, true, false, null, WorkflowStepValidator.OnIDCardFrontStep ), new SBSDKUIScanMachineReadableZoneWorkflowStep( "Step 2/2", "Please scan the back side of your ID card", MRZRatios, true, WorkflowStepValidator.OnIDCardBackStep ) }; PresentController(name, steps); } else if (button.Data.Code == ListItemCode.WorkflowSEPA) { var name = "SEPAScanFlow"; var steps = new SBSDKUIWorkflowStep[] { new SBSDKUIScanPayFormWorkflowStep( "Please scan a SEPA PayForm", "", false, WorkflowStepValidator.OnPayFormStep ) }; PresentController(name, steps); } else if (button.Data.Code == ListItemCode.WorkflowQR) { var name = "QRCodeScanFlow"; var types = SBSDKUIMachineCodesCollection.TwoDimensionalBarcodes; var steps = new SBSDKUIWorkflowStep[] { new SBSDKUIScanBarCodeWorkflowStep("Scan your QR code", "", types, new SBSDKAspectRatio(1, 1), WorkflowStepValidator.OnBarCodeStep) }; PresentController(name, steps); } else if (button.Data.Code == ListItemCode.ScannerEHIC) { var configuration = SBSDKUIHealthInsuranceCardScannerConfiguration.DefaultConfiguration; var controller = SBSDKUIHealthInsuranceCardScannerViewController .CreateNewWithConfiguration(configuration, Delegates.EHIC); controller.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; PresentViewController(controller, false, null); } else if (button.Data.Code == ListItemCode.ScannerBarcode) { var configuration = SBSDKUIMachineCodeScannerConfiguration.DefaultConfiguration; var controller = SBSDKUIBarcodeScannerViewController .CreateNewWithAcceptedMachineCodeTypes( SBSDKBarcodeType.AllTypes, configuration, Delegates.Barcode); controller.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; PresentViewController(controller, false, null); } }
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); }