I am trying to open a pdf file on the browser, acrobat or any other default pdf program. For this I need to call LaunchFileAsync() and I need to reference Windows.System to be able to use it. However, this is not working and I can't call any reference.
I tried looking for a specific library or nuget package but I couldn't find anything. The documentation just tells me to use that namespace but it doesn't say anything about how to add the reference. I also tried using a different approach by calling System.Diagnostics.Process.Start(path) and some variations but it doesnt't work using Xamarin apparently.
This is basically what I am trying to implement but there's no namespace found event though I did try implementing it.
string uriToLaunch = #"file://" + #file;
var uri = new Uri(uriToLaunch);
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
Any help would be appreciated.
Have you tried adding an assembly reference in the Reference menu?
In the Solution Explorer, right click your project and go to:
Add -> Reference -> Assemblies -> System.*
Also, make sure not to use platform specific libraries for a mobile project, since this will probably cause compatibility issues. .NET Standard is the way to go.
Use Xamarin.Essentials as it defines the various OS dependancies for you and on UWP uses the native Windows.System.Launcher.LaunchUriAsync:
Xamarin.Essentials.Launcher.OpenAsync
re: Xamarin Docs
Note: Opening file://-based URIs is very restricted in UWP.
If you are not targeting .NET Standard yet, make sure you do that if you want to use System libraries. There are some tutorials on this, but i highly suggest you backup your project before changing from PCL to .NET Standard
TL;DR:
Does anyone know of a way to reference Microsoft.Windows.Ocr (/ WindowsPreview.Media.Ocr.dll ) Assembly on a server-side ASP.Net Web application like MV4 Web API and make use of the OCR Functionality in that assembly to take a photo image as input and extract the text content out of it ? If yes, please provide detailed instructions in your answer.
Question Details (and what I have tried so far)
I am building a web application that takes an image uploaded to the Server (via a file upload UI screen) and then reads the text using OCR and displays the text on the next page, right next to the image that was uploaded.
Since most commercial OCR Libraries cost an arm and length (over $1,300 last time I checked) I thought I can try and use the Microsoft OCR Library Microsoft.Windows.Ocr that is FREE and seems to be very simple and straightforward to use.
So I tried to install the Microsoft.Windows.Ocr Nuget Package to my ASP.Net MVC4 Web API Project and that succeeded.
After that, I looked through my MVC4 Web API Project References, and to my surprise, did not find a reference to Microsoft.Windows.Ocr.dll Assembly.
So then I tried to add a reference to the x86 version of the Microsoft.Windows.Ocr.dll Assembly by browsing to that Assembly in the \packages folder, and selected the WindowsPreview.Media.Ocr.dll from \lib\win81\x86 folder
Note: The Assembly name is WindowsPreview.Media.Ocr.dll and not Microsoft.Windows.Ocr.dll , not sure why!
When I did that and clicked OK, I got the following Error Message.
---------------------------
Microsoft Visual Studio
---------------------------
A reference to
'D:\TestProjects\packages\Microsoft.Windows.Ocr.1.0.0\lib\win81\x86\
WindowsPreview.Media.Ocr.dll' could not be added. Please make sure
that the file is accessible, and that it is a valid assembly
or COM component.
---------------------------
OK
---------------------------
I then found out from the Nuget Page that the "Supported Platforms" are only Windows Phone 8, Windows Phone 8.1, Windows 8.1 (Windows Store apps only).
But surely, there must be a way to use this OCR dll on the Server-side in an ASP.Net Application?
Does anyone know of a way to reference Microsoft.Windows.Ocr (/ WindowsPreview.Media.Ocr.dll ) Assembly on a server-side ASP.Net Web application like MV4 Web API and make use of the OCR Functionality in that assembly to take a photo image as input and extract the text content out of it ?** If yes, please provide detailed instructions in your answer.
Any "hacks" and/or Sample code would be much appreciated!!
Thank you!!
If you are using Visual Studio 2015 and Windows 10, the
Microsoft.Windows.Ocr
has been moved to Universal Windows Platform. It is available as
Windows.Media.Ocr
So you need to upgrade your VS 2015 with tools for Windows 10 enabled.
I did the following and Windows.Media.Ocr got added as a reference in my Web API.
In your Web API project's references right click any of the references and click View in Object Browser. Your Object browser will look something like this
There is a '...' button right next to the "Browse: All components" Box. The tooltip reads "Edit Custom Component set".Click!
In the "Edit Custom Component Set" Box click the Browse Tab and Navigate to "C:/Program Files(x86)/Windows Kits/10/References/Windows.Foundation.UniversalApiContract/1.0.0.0"
and click the winmd file that results and click Add.
Hit Ok!
Now click icon that reads "Add to references in Selected Project in Solution Explorer"(It is the third button from the '...' button next to "Browse:"). You can see that Windows.Media.Ocr is available to use.
Note: The following works only with VS 2015 and windows 10. That too VS 2015 should be updated for Universal Windows Platform(UWP). Check this for a sample OCR.
Hope this helps.
Update
It got imported into my reference but is failing to load though. Hope it provides some start for people.
Thanks!.
You can Skip to Update 2 below for a working solution.
IT WILL THROW A TYPE LOAD EXCEPTION. That being said I am posting because I am trying to do the same thing but can't get the project to run. Here are some basic instructions on how to get the winrt api into your non windows app project.
http://weblogs.thinktecture.com/cnagel/2012/10/calling-winrt-from-windows-desktop-apps.html
Also don't try to reference the dll, reference instead the winmd file.
Here is a sample console app that references the ocr library but when you run the solution it throws the type load exception.(https://github.com/Xandroid4Net/MicrsoftOcrConsoleApp) It should be easily ported from a console app to and asp.net application. I don't know how to fix the type load exception maybe you can get farther than I can. Please post if you do find a solution.
UPDATE 1 (12/1/2014)
More digging revealed the following assembly binding error. Any idea how to set a package Id for a Process?
File: WindowsPreview.Media.Ocr!WindowsPreview.Media.Ocr.OcrEngine, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime.htm
File Contents:
* Assembly Binder Log Entry (12/1/2014 # 11:48:01 PM) *
The operation failed.
Bind result: hr = 0x80073d54. The process has no package identity.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\Users\Wesley\Documents\Dev\ConsoleApplication2\Program.exe
--- A detailed error log follows.
BEGIN : Windows Runtime Type bind.
END : The process has no package identity. (Exception from HRESULT: 0x80073D54)
Update 2 (12/03/2014)
This is a nasty workaround but it worked on my Windows 8.1 Surface Pro 3 tablet. The WebOcr is a webforms but it can easily be refactored for MVC
1) Download https://github.com/Xandroid4Net/CommandLineOcr. This is the psuedo store app.
2) Build and run the app. It will appear to do nothing. That is okay, it will update the registry with a new key that we will need.
3) Download https://github.com/Xandroid4Net/WebOcr.
4) Find OcrCommandLineCaller.cs in the Webocr project.
5) Locate the registry key at HKEY_CURRENT_USER\Software\Classes\ActivatableClasses\Package\Some_Sort_Of_Guid_For_Your_APP\Server\App.App....\AppUserModelId
Refer to this SO question if you need more help finding the registry key. IApplicationActivationManager::ActivateApplication in C#?
6) Update the appActiveManager.ActivateApplication call in OcrCommandLineCaller.cs with the strange guid app identifier found in the registry key.
7) In default.aspx.cs replace the saveAsPath with the path on your machine. In the windows store app there is a static path represented by Windows.Storage.ApplicationData.Current.LocalFolder. This is the path where I saved my images for simplicity.
8) Modify any of the code to your heart's content and let me know if you have any questions.
This is a very rough and nasty solution, but it does work.
I have been using the MODI solution packaged with MS Office for a few years, and was pretty happy with it (it was free if you bought Office). I was rather disappointed when it was discontinued.
I've tried Tesseract... I really wanted to like it, but found it slow and inaccurate for Dutch machine type of good quality... and like you, I could not justify spending anything north $200 for what was essentially a hobby project.
After a desperate search, someone on here pointed me at TOCR (a Transym product). An epiphany followed soon after. ;-)
I think I need to say at this point that I am not affiliated with Transym in any way, and yes, I paid the full price... of 60 pounds! (no typo... sixty quid), which, including VAT, worked out to 113 euros.
It is essentially meant for integrators (it includes a scan/viewer/OCR app, but that is merely meant as a demo - if you buy the license, you get its source code). The API is outdated (it is, as OCR engines go, quite a mature code base), but it is fast, stable, and unexpectedly accurate. Not as accurate as the DokuStar engine or other esoteric engines, but for my application (Dutch and ENglish machine type) it holds its own against various engines that are well north of $1000. Recognition accuracy on Dutch machine type is excellent (it doesn't do handwriting).
In my opinion, in terms of value for money, it is simply ridiculously good.
As to the API: I wrote a rudimentary .NET wrapper around it to suit my needs - this was done in a few evenings.
There is an eval version available on their web site (http://www.transym.com/index.htm). And no, I don't get any money if you do ;-)
I managed to invoke the OCR from Web API by invoking the DLL from powershell. I found also that you cannot invoke this DLL in parallel.
It took me a few days, but here is the repo. Available both as nuget and web API with Windows docker https://github.com/MihaiTheCoder/ocr-all-in-one
I developed Web API project mostly for this question, so hopefully somebody will find it useful.
The powershell that is invoking Windows OCR is here: https://github.com/MihaiTheCoder/ocr-all-in-one/blob/master/Ocr.Wrapper/Resources/Get-Text-Win-OCR.ps1
It is a 2 stage process because the initialization of the OCR engine takes more time, and it is better to have it cached.
IMHO, probably not worth your effort to try to use a library that is not supported on the platform you are targeting.
You could check this answer for some free alternatives.
I managed to get the UWP OCR API working on desktop app using uwpdesktop NuGet.
Install-Package uwpdesktop
You can then make calls to UWP APIs.
I am not a lawyer, but my understanding is the the Microsoft end user license agreement for that library does not allow to use the Microsoft OCR Library for Windows Runtime in your scenario.
Specifically, read the second paragraph, where it forbids to use the software on a server in a production environment:
"2. INSTALLATION AND USE RIGHTS.
a. General. One user may install and use copies of the software to
design, develop, test and demonstrate your programs. You may not use
the software on a server in a production environment."
At the same time, they also restrict the run of the distributable code exclusively to Windows Store or Windows Phone:
"3. ADDITIONAL LICENSING REQUIREMENTS AND/OR USE RIGHTS.
a. Distributable Code. The software contains code that you are
permitted to distribute in programs you develop if you comply with the
terms below.
i. ..
ii. ..
iii. Distribution Restrictions. You may not
..
· distribute Distributable Code to run on a platform other
than the Windows Store or Windows Phone;"
The full EULA can be read at: https://www.microsoft.com/web/webpi/eula/windows_runtime_ocr_library_terms_of_use.htm
MonoTouch Binding refers to my Static Library, which uses FacebookSDK.
Сhain projects:
MonoTouch App -> MonoTouch Binding -> My Static Library -> FacebookSDK
When you add interfaces ApiDefinition, arise errors associated with FacebookSDK how to solve this problem? Maybe someone has already encountered this problem?
Error MT5211: Native linking failed, undefined Objective-C class:
_OBJC_CLASS_$_FBFriendPickerViewController. If '_OBJC_CLASS_$_FBFriendPickerViewController' is a
protocol from a third-party binding, please check that it has the [Protocol] attribute in its
api definition file, otherwise verify that all the necessary frameworks have been referenced and
native libraries are properly linked in. (MT5211)
Remove reference of current the Facebook SDK framework and add the Facebook SDK again by drag and drop it in framework folder.
This will add Facebook SDK path automatically.
I need to develop web application which use youtube api v3 for searching videolist by channel name and author name.
for simple testing
go to youtube api client site
then download sample files of .net.
I downloaded youtube/yt-samples-dotnet from here.
Here i got 4 class files.
no sln.
Then what to do? i mean just open it and run!!!? or something else needed from my side coding?
I already create account and Generate API key.
UPDATE
Now i create new project 3 tier with BAL DAL PAL
In BAL : i added all 4 .cs files
then add reference which is download from here.
I need :
using DotNetOpenAuth.OAuth2;
using Google.Apis.Youtube.v3;
using Google.Apis.Youtube.v3.Data;
then what to do?
As explained in the comment at the top of those files, there are dependencies on the Google APIs Client Library for .NET. You can follow the user guide for getting started, and I'd recommend using the NuGet approach to pulling in the dependent libraries.
Here: https://developers.google.com/api-client-library/dotnet/apis/youtube/v3
Then you can download the library opening the nuget webpage and viewing the package id and the version.
https://www.nuget.org/packages?q=Google.Apis.youtube&prerelease=true&sortOrder=relevance
and then build this url:
https://www.nuget.org/api/v2/package/{packageID}/{packageVersion}
=>
https://www.nuget.org/packages/Google.Apis.YouTube.v3/1.7.0.94-beta
I have a warning when I build my Windows 8 App project in VS2012:
No implementation file was provided for the .winmd file 'C:\Users\luke\LApp\LApp\bin\x86\Debug\Bing.Maps.winmd'. To generate registration information in the app manifest, specify the 'Implementation' metadata on the .winmd reference item in the project file.
I don't really know what other information to provide. I've Googled and it doesn't provide any relevant results. It gives a link to this: http://msdn.microsoft.com/en-us/library/hh708954.aspx but I'm not sure it is the correct thing. I'm pretty sure I have the correct references:
It is a C# project. I used NuGet to add the Bing Maps SDK and it works in my app - I can drag on a map interface and use it in the app. This is just a warning that shows up when building and I have no idea how to get rid of it.
Any help appreciated, thanks.
Is your project a c# project?
Usually WinRT components implemented using .NET are just .winmd files. Both interface and implementation are contained within the .winmd file. Whereas native components (those written in C++) will have separate .winmd and .dll files for interface and implementation respectively.
It would be helpful if you could provide more details about your app project and the repro steps.