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

Add access to local file capability #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 8 additions & 6 deletions Source/SimplePdfViewer/SimplePdfViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
<AssemblyName>SimplePdfViewer</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<TargetPlatformVersion>10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.18362.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<RuntimeIdentifiers>win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -102,10 +103,6 @@
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SimplePdfViewerControl.xaml.cs">
Expand All @@ -120,6 +117,11 @@
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>5.1.0</Version>
</PackageReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
Expand Down
23 changes: 18 additions & 5 deletions Source/SimplePdfViewer/SimplePdfViewerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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
{
Expand All @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions Source/SimplePdfViewer/UriExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
16 changes: 0 additions & 16 deletions Source/SimplePdfViewer/project.json

This file was deleted.