Browse Source

PDF Maui Test

master
gene 2 years ago
parent
commit
65095d6830
  1. BIN
      CircleViewer/.vs/CircleViewer/v17/.suo
  2. 6
      CircleViewerMaui/App.xaml.cs
  3. 1
      CircleViewerMaui/AppShell.xaml
  4. 8
      CircleViewerMaui/CircleViewerMaui.csproj
  5. 49
      CircleViewerMaui/MainPage.xaml
  6. 71
      CircleViewerMaui/MainPage.xaml.cs
  7. 7
      CircleViewerMaui/MauiProgram.cs

BIN
CircleViewer/.vs/CircleViewer/v17/.suo

6
CircleViewerMaui/App.xaml.cs

@ -2,8 +2,14 @@
public partial class App : Application
{
private string syncFusionLicenseKey = "MTg3MzUyM0AzMjMxMmUzMTJlMzQzMVhOUDNaUUxSMUExWTB3a1EzK294VjhKcGh3eENlanRIdXR2aWVrSGZUVTg9";
public App()
{
string[] args = Environment.GetCommandLineArgs();
//Register SyncFusion license
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(syncFusionLicenseKey);
InitializeComponent();
MainPage = new AppShell();

1
CircleViewerMaui/AppShell.xaml

@ -7,7 +7,6 @@
Shell.FlyoutBehavior="Disabled">
<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

8
CircleViewerMaui/CircleViewerMaui.csproj

@ -49,11 +49,19 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="5.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="Syncfusion.Maui.PdfViewer" Version="21.1.35" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CDPShared\CDPShared.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="CircleSDK">
<HintPath>..\csharp\src\CircleSDK\bin\Debug\netstandard2.0\CircleSDK.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

49
CircleViewerMaui/MainPage.xaml

@ -1,45 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pdfViewer="http://schemas.syncfusion.com/maui"
x:Class="CircleViewerMaui.MainPage">
<ScrollView>
<ScrollView.GestureRecognizers>
<DragGestureRecognizer />
<DropGestureRecognizer />
</ScrollView.GestureRecognizers>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
<Image
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
HeightRequest="200"
HorizontalOptions="Center" />
<Label
Text="Hello, World!"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="Center" />
<Label
Text="Welcome to .NET Multi-platform App UI"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot net Multi platform App U I"
FontSize="18"
HorizontalOptions="Center" />
<Button
x:Name="CounterBtn"
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ScrollView>
<ContentPage.MenuBarItems>
<MenuBarItem Text="File">
<MenuFlyoutItem Text="Open" Clicked="onOpenClicked"/>
</MenuBarItem>
</ContentPage.MenuBarItems>
<ContentPage.Content>
<pdfViewer:SfPdfViewer x:Name="PdfViewer" VerticalOptions="Fill">
</pdfViewer:SfPdfViewer>
</ContentPage.Content>
</ContentPage>

71
CircleViewerMaui/MainPage.xaml.cs

@ -1,5 +1,6 @@
using System.Reflection;
using CDPShared;
using Syncfusion.Maui.PdfViewer;
namespace CircleViewerMaui;
@ -7,6 +8,8 @@ public partial class MainPage : ContentPage
{
int count = 0;
private CDPWorker _cdp;
Timer _timer;
Boolean _bConnected = false;
public MainPage()
{
@ -14,19 +17,73 @@ public partial class MainPage : ContentPage
{
_cdp = new CDPWorker();
InitializeComponent();
_timer = new Timer(IsReady, null, 250, 250);
}
}
void IsReady(object state)
{
if (_bConnected != _cdp.Ready)
{
_bConnected = _cdp.Ready;
OnReady();
_timer = null;
}
}
void OnReady()
{
// Device.InvokeOnMainThreadAsync(() => { lblConnected.Text = "Connected"; });
}
private void OnCounterClicked(object sender, EventArgs e)
public async Task<string> OpenCirFileAsync()
{
var fileTypes = new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
{
{ DevicePlatform.iOS, new[] { "public.cir" } },
{ DevicePlatform.Android, new[] { "application/cir" } },
{ DevicePlatform.WinUI, new[] { ".cir" } },
{ DevicePlatform.macOS, new[] { ".cir" } }
});
var options = new PickOptions
{
FileTypes = fileTypes,
PickerTitle = "Open .cir File"
};
var result = await FilePicker.PickAsync(options);
if (result != null)
{
count++;
return result.FullPath;
}
return null;
}
if (count == 1)
CounterBtn.Text = $"Clicked {count} time";
else
CounterBtn.Text = $"Clicked {count} times";
private async void onOpenClicked(object sender, EventArgs e)
{
var filePath = await OpenCirFileAsync();
if (filePath != null)
{
ViewFileAsync(filePath);
}
}
SemanticScreenReader.Announce(CounterBtn.Text);
async void ViewFileAsync(string fileToLoad)
{
using (LogMethod.Log(MethodBase.GetCurrentMethod().ReflectedType.Name))
{
var result = await _cdp.Decrypt(fileToLoad);
if (result.Status.Result.GetValueOrDefault(false))
{
byte[] buf = Convert.FromBase64String(result.DecryptedData);
string ext = Path.GetExtension(result.FileName);
PdfViewer.DocumentSource = new MemoryStream(buf);
}
}
}
}

7
CircleViewerMaui/MauiProgram.cs

@ -1,4 +1,6 @@
using Microsoft.Extensions.Logging;
using CommunityToolkit.Maui;
using Microsoft.Extensions.Logging;
using Syncfusion.Maui.Core.Hosting;
namespace CircleViewerMaui;
@ -9,12 +11,15 @@ public static class MauiProgram
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
// Initialize the .NET MAUI Community Toolkit by adding the below line of code
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
builder.ConfigureSyncfusionCore();
#if DEBUG
builder.Logging.AddDebug();
#endif

Loading…
Cancel
Save