From 1d45e6e7032f829c61d0a5d7e363661c19ff88dd Mon Sep 17 00:00:00 2001 From: Ivan Akira Date: Thu, 7 May 2020 15:41:19 +0700 Subject: [PATCH] Add access to local file capability --- Source/SimplePdfViewer/SimplePdfViewer.csproj | 14 ++++++----- .../SimplePdfViewerControl.xaml.cs | 23 +++++++++++++++---- Source/SimplePdfViewer/UriExtension.cs | 10 ++++++++ Source/SimplePdfViewer/project.json | 16 ------------- 4 files changed, 36 insertions(+), 27 deletions(-) delete mode 100644 Source/SimplePdfViewer/project.json diff --git a/Source/SimplePdfViewer/SimplePdfViewer.csproj b/Source/SimplePdfViewer/SimplePdfViewer.csproj index 19e4d96..31c5343 100644 --- a/Source/SimplePdfViewer/SimplePdfViewer.csproj +++ b/Source/SimplePdfViewer/SimplePdfViewer.csproj @@ -11,11 +11,12 @@ SimplePdfViewer en-US UAP - 10.0.10240.0 - 10.0.10240.0 + 10.0.18362.0 + 10.0.18362.0 14 512 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot AnyCPU @@ -102,10 +103,6 @@ false prompt - - - - @@ -120,6 +117,11 @@ MSBuild:Compile + + + 5.1.0 + + 14.0 diff --git a/Source/SimplePdfViewer/SimplePdfViewerControl.xaml.cs b/Source/SimplePdfViewer/SimplePdfViewerControl.xaml.cs index b55a054..e7aba58 100644 --- a/Source/SimplePdfViewer/SimplePdfViewerControl.xaml.cs +++ b/Source/SimplePdfViewer/SimplePdfViewerControl.xaml.cs @@ -39,7 +39,7 @@ public bool IsZoomEnabled public static readonly DependencyProperty IsZoomEnabledProperty = DependencyProperty.Register("IsZoomEnabled", typeof(bool), typeof(SimplePdfViewerControl), new PropertyMetadata(true, OnIsZoomEnabledChanged)); - + internal ZoomMode ZoomMode { get { return IsZoomEnabled ? ZoomMode.Enabled : ZoomMode.Disabled; } @@ -90,13 +90,17 @@ public async Task LoadAsync() } else { - if(Source.IsFile || !Source.IsWebUri()) + if (Source.IsWebUri()) { - await LoadFromLocalAsync(); + await LoadFromRemoteAsync(); } - else if(Source.IsWebUri()) + else if (Source.IsFile && Source.IsApplicationUri()) { - await LoadFromRemoteAsync(); + await LoadFromApplicationAsync(); + } + else if (Source.IsFile) + { + await LoadFromLocalAsync(); } else { @@ -119,6 +123,15 @@ private async Task LoadFromRemoteAsync() } private async Task LoadFromLocalAsync() + { + StorageFile f = await + StorageFile.GetFileFromPathAsync(Source.LocalPath); + PdfDocument doc = await PdfDocument.LoadFromFileAsync(f); + + Load(doc); + } + + private async Task LoadFromApplicationAsync() { StorageFile f = await StorageFile.GetFileFromApplicationUriAsync(Source); diff --git a/Source/SimplePdfViewer/UriExtension.cs b/Source/SimplePdfViewer/UriExtension.cs index e1924ce..29694f4 100644 --- a/Source/SimplePdfViewer/UriExtension.cs +++ b/Source/SimplePdfViewer/UriExtension.cs @@ -13,5 +13,15 @@ public static bool IsWebUri(this Uri uri) } return false; } + + public static bool IsApplicationUri(this Uri uri) + { + if (uri != null) + { + var str = uri.ToString().ToLower(); + return str.StartsWith("ms-appx://") || str.StartsWith("ms-appx://"); + } + return false; + } } } diff --git a/Source/SimplePdfViewer/project.json b/Source/SimplePdfViewer/project.json deleted file mode 100644 index 92d1456..0000000 --- a/Source/SimplePdfViewer/project.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "dependencies": { - "Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0" - }, - "frameworks": { - "uap10.0": {} - }, - "runtimes": { - "win10-arm": {}, - "win10-arm-aot": {}, - "win10-x86": {}, - "win10-x86-aot": {}, - "win10-x64": {}, - "win10-x64-aot": {} - } -} \ No newline at end of file