Exemple #1
0
        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);
                });
            });
        }
Exemple #2
0
        void AssignCreateTiffButtonHandler()
        {
            var createTiffButton = FindViewById <Button>(Resource.Id.createTiffButton);

            createTiffButton.Click += delegate
            {
                if (!CheckScanbotSDKLicense())
                {
                    return;
                }
                if (!CheckDocumentImage())
                {
                    return;
                }

                DebugLog("Starting TIFF creation...");

                Task.Run(() =>
                {
                    try
                    {
                        var tiffOutputUri = GenerateRandomFileUrlInDemoTempStorage(".tiff");
                        var images        = new AndroidNetUri[] { documentImageUri }; // add more images for PDF pages here
                        // The SDK call is sync!
                        SBSDK.WriteTiff(images, tiffOutputUri, new TiffOptions {
                            OneBitEncoded = true
                        });
                        DebugLog("TIFF file created: " + tiffOutputUri);
                        ShowAlertDialog("TIFF file created: " + tiffOutputUri, onDismiss: () =>
                        {
                            OpenSharingDialog(tiffOutputUri, "image/tiff");
                        });
                    }
                    catch (Exception e)
                    {
                        ErrorLog("Error creating TIFF", e);
                    }
                });
            };
        }
        partial void CreateTiffFileTouchUpInside(UIButton sender)
        {
            if (!CheckScanbotSDKLicense())
            {
                return;
            }
            if (!CheckDocumentImageUrl())
            {
                return;
            }

            Task.Run(() =>
            {
                DebugLog("Creating TIFF file ...");
                var images            = new NSUrl[] { documentImageUrl }; // add more images for multipage TIFF
                var tiffOutputFileUrl = GenerateRandomFileUrlInDemoTempStorage(".tiff");
                SBSDK.WriteTiff(images, tiffOutputFileUrl, new TiffOptions {
                    OneBitEncoded = true
                });
                DebugLog("TIFF file created: " + tiffOutputFileUrl);
                ShowMessage("TIFF file created", "" + tiffOutputFileUrl);
            });
        }
Exemple #4
0
        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);
        }