Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EPIC-4628] Xamarin DS 4.2.1 #86

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="ScanbotSDK.Xamarin">
<Version>4.2.0</Version>
<Version>4.2.1-alpha.2</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
Expand Down
105 changes: 89 additions & 16 deletions Classical-Components-Demo/Droid/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ protected override void OnCreate(Bundle savedInstanceState)
AssignApplyImageFilterButtonHandler();
AssignImportImageButtonHandler();
AssignCreatePdfButtonHandler();
AssignCreateTiffButtonHandler();
AssignOcrButtonsHandler();
AssignCreateSandwichPdfButtonHandler();
AssignCreateTiffButtonHandler();
AssignCheckRecognizerUiButtonHandler();

PermissionUtils.Request(this, FindViewById(Resource.Layout.Main));
Expand Down Expand Up @@ -185,14 +186,26 @@ void AssignCreatePdfButtonHandler()

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

Task.Run(() =>
Task.Run(async () =>
{
try
{
var pdfOutputUri = GenerateRandomFileUrlInDemoTempStorage(".pdf");
var images = new AndroidNetUri[] { documentImageUri }; // add more images for PDF pages here
// The SDK call is sync!
SBSDK.CreatePDF(images, pdfOutputUri, PDFPageSize.A4);
var inputUris = new AndroidNetUri[] { documentImageUri }; // add more images for PDF pages here
var pdfOutputUri = await SBSDK.CreatePDF(inputUris,
new PDFConfiguration
{
PageOrientation = PDFPageOrientation.Auto,
PageSize = PDFPageSize.A4,
PdfAttributes = new PDFAttributes
{
Author = "Scanbot User",
Creator = "ScanbotSDK",
Title = "ScanbotSDK PDF",
Subject = "Generating a sandwiched PDF",
Keywords = new[] { "x-platform", "ios", "android" },
}
});

DebugLog("PDF file created: " + pdfOutputUri);
ShowAlertDialog("PDF file created: " + pdfOutputUri, onDismiss: () =>
{
Expand Down Expand Up @@ -255,17 +268,22 @@ void AssignOcrButtonsHandler()
Task.Run(() => {
try
{
var pdfOutputUri = GenerateRandomFileUrlInDemoTempStorage(".pdf");
var images = new AndroidNetUri[] { documentImageUri }; // add more images for OCR here
var inputUris = new AndroidNetUri[] { documentImageUri }; // add more images for OCR here

// The SDK call is sync!
var result = SBSDK.PerformOCR(images, SBSDK.GetOcrConfigs(), pdfOutputUri);
DebugLog("Recognized OCR text: " + result.RecognizedText);
DebugLog("Sandwiched PDF file created: " + pdfOutputUri);
ShowAlertDialog(result.RecognizedText, "OCR Result", () =>
{
OpenSharingDialog(pdfOutputUri, "application/pdf");
});
// NOTE:
// The default OCR engine is 'OcrConfig.ScanbotOCR' which is ML based. This mode doesn't expect the Langauges array.
// If you wish to use the previous engine please use 'OcrConfig.Tesseract(...)'. The Languages array is mandatory in this mode.
// Uncomment the below code to use the past legacy 'OcrConfig.Tesseract(...)' engine mode.
// var ocrConfig = OcrConfig.Tesseract(withLanguageString: new List<string>{ "en", "de" });

// Using the default OCR option
var ocrConfig = OcrConfig.ScanbotOCR;

var ocrResult = SBSDK.PerformOCR(inputUris, ocrConfig);

DebugLog("Recognized OCR text: " + ocrResult.RecognizedText);
ShowAlertDialog(ocrResult.RecognizedText, "OCR Result", () => { });
}
catch (Exception e)
{
Expand All @@ -282,6 +300,61 @@ void AssignOcrButtonsHandler()
};
}

private void AssignCreateSandwichPdfButtonHandler()
{
var createSandwichPdfButton = FindViewById<Button>(Resource.Id.createSandwichPdfButton);
createSandwichPdfButton.Click += delegate
{
if (!CheckScanbotSDKLicense()) { return; }
if (!CheckDocumentImage()) { return; }

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

Task.Run(async () =>
{
// NOTE:
// The default OCR engine is 'OcrConfig.ScanbotOCR' which is ML based. This mode doesn't expect the Langauges array.
// If you wish to use the previous engine please use 'OcrConfig.Tesseract(...)'. The Languages array is mandatory in this mode.
// Uncomment the below code to use the past legacy 'OcrConfig.Tesseract(...)' engine mode.
//var ocrConfig = OcrConfig.Tesseract(withLanguageString: new List<string>{ "en", "de" });

// You may also use the default InstalledLanguages property in the OCR configuration.
// SBSDK.GetOcrConfigs() returns all the default OCR configurations from the SDK.
//var languages = SBSDK.GetOcrConfigs().InstalledLanguages;

// Using the default OCR option
var ocrConfig = OcrConfig.ScanbotOCR;

try
{
var inputUris = new AndroidNetUri[] { documentImageUri }; // add more images for PDF pages here
var pdfOutputUri = await SBSDK.CreateSandwichPDF(inputUris,
new PDFConfiguration
{
PageOrientation = PDFPageOrientation.Auto,
PageSize = PDFPageSize.A4,
PdfAttributes = new PDFAttributes
{
Author = "Scanbot User",
Creator = "ScanbotSDK",
Title = "ScanbotSDK PDF",
Subject = "Generating a sandwiched PDF",
Keywords = new[] { "x-platform", "ios", "android" },
}
}, ocrConfig);
ShowAlertDialog("PDF file created: " + pdfOutputUri, onDismiss: () =>
{
OpenSharingDialog(pdfOutputUri, "application/pdf");
});
}
catch (Exception e)
{
ErrorLog("Error creating PDF", e);
}
});
};
}

void AssignCheckRecognizerUiButtonHandler()
{
FindViewById<Button>(Resource.Id.checkUiButton).Click += delegate
Expand Down Expand Up @@ -513,7 +586,7 @@ void OpenSharingDialog(AndroidNetUri publicFileUri, string mimeType)

var authority = ApplicationContext.PackageName + ".provider";
var uri = FileProvider.GetUriForFile(this, authority, new Java.IO.File(publicFileUri.Path));

shareIntent.PutExtra(Intent.ExtraStream, uri);
StartActivity(shareIntent);
}
Expand Down
17 changes: 13 additions & 4 deletions Classical-Components-Demo/Droid/Resources/layout/Main.axml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,25 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/createPdfButton" />

<Button
android:text="Create TIFF"
android:text="Perform OCR"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/createTiffButton" />
android:id="@+id/performOcrButton" />

<Button
android:text="Perform OCR"
android:text="Create Sandwich PDF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/performOcrButton" />
android:id="@+id/createSandwichPdfButton" />

<Button
android:text="Create TIFF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/createTiffButton" />

<Button
android:text="Generic Document Recognizer UI"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="ScanbotSDK.Xamarin">
<Version>4.2.0</Version>
<Version>4.2.1-alpha.2</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
Expand Down
40 changes: 32 additions & 8 deletions Classical-Components-Demo/iOS/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="299">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="299">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -12,7 +12,7 @@
<objects>
<navigationController id="299" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="301">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
Expand Down Expand Up @@ -203,9 +203,33 @@
</constraints>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="44" id="8WY-El-eTg">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="44" id="uyI-2u-5dx">
<rect key="frame" x="0.0" y="358" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="uyI-2u-5dx" id="bO0-Xh-S21">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="OgR-4q-5Yn">
<rect key="frame" x="20" y="7" width="335" height="30"/>
<state key="normal" title="Create Sandwich PDF">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="CreateSandwichPdfTouchUpInside:" destination="719" eventType="touchUpInside" id="eV2-oX-Qnu"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="OgR-4q-5Yn" secondAttribute="trailing" constant="20" id="0Eb-dc-DNm"/>
<constraint firstItem="OgR-4q-5Yn" firstAttribute="leading" secondItem="bO0-Xh-S21" secondAttribute="leading" constant="20" id="LUJ-nn-jiC"/>
<constraint firstItem="OgR-4q-5Yn" firstAttribute="top" secondItem="bO0-Xh-S21" secondAttribute="top" constant="7" id="UBa-0B-E5b"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="44" id="8WY-El-eTg">
<rect key="frame" x="0.0" y="402" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="8WY-El-eTg" id="5Uo-ls-qR5">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
Expand All @@ -228,7 +252,7 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="44" id="pnR-hN-B1f">
<rect key="frame" x="0.0" y="402" width="375" height="44"/>
<rect key="frame" x="0.0" y="446" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="pnR-hN-B1f" id="Y5c-fO-XPl">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
Expand All @@ -252,7 +276,7 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="316" id="749">
<rect key="frame" x="0.0" y="446" width="375" height="316"/>
<rect key="frame" x="0.0" y="490" width="375" height="316"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="749" id="750">
<rect key="frame" x="0.0" y="0.0" width="375" height="316"/>
Expand Down Expand Up @@ -281,7 +305,7 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="34" id="751">
<rect key="frame" x="0.0" y="762" width="375" height="34"/>
<rect key="frame" x="0.0" y="806" width="375" height="34"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="751" id="752">
<rect key="frame" x="0.0" y="0.0" width="375" height="34"/>
Expand All @@ -302,7 +326,7 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="34" id="1553">
<rect key="frame" x="0.0" y="796" width="375" height="34"/>
<rect key="frame" x="0.0" y="840" width="375" height="34"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="1553" id="1554">
<rect key="frame" x="0.0" y="0.0" width="375" height="34"/>
Expand Down
Loading