Skip to content

Commit 140aee7

Browse files
authored
Merge pull request #72 from SyncfusionExamples/PDFAutoSave
865752 - Create a blog sample for how to load and save files from AWS cloud storage
2 parents 21202d8 + 1711d5c commit 140aee7

40 files changed

+1629
-0
lines changed

Save/AutoSavePDFinAWS/App.xaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:AutoSavePDFinAWS"
5+
xmlns:converters="clr-namespace:AutoSavePDFinAWS"
6+
x:Class="AutoSavePDFinAWS.App">
7+
<Application.Resources>
8+
<ResourceDictionary>
9+
<ResourceDictionary.MergedDictionaries>
10+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
11+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
12+
</ResourceDictionary.MergedDictionaries>
13+
<converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
14+
</ResourceDictionary>
15+
</Application.Resources>
16+
</Application>

Save/AutoSavePDFinAWS/App.xaml.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace AutoSavePDFinAWS
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Add valid license key");
8+
InitializeComponent();
9+
}
10+
11+
protected override Window CreateWindow(IActivationState? activationState)
12+
{
13+
return new Window(new AppShell());
14+
}
15+
}
16+
}

Save/AutoSavePDFinAWS/AppShell.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="AutoSavePDFinAWS.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:AutoSavePDFinAWS"
7+
Title="AutoSavePDFinAWS">
8+
9+
<ShellContent
10+
Title="Home"
11+
ContentTemplate="{DataTemplate local:MainPage}"
12+
Route="MainPage" />
13+
14+
</Shell>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace AutoSavePDFinAWS
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
6+
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
7+
<!-- <TargetFrameworks>$(TargetFrameworks);net9.0-tizen</TargetFrameworks> -->
8+
9+
<!-- Note for MacCatalyst:
10+
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
11+
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
12+
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
13+
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
14+
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
15+
16+
<OutputType>Exe</OutputType>
17+
<RootNamespace>AutoSavePDFinAWS</RootNamespace>
18+
<UseMaui>true</UseMaui>
19+
<SingleProject>true</SingleProject>
20+
<ImplicitUsings>enable</ImplicitUsings>
21+
<Nullable>enable</Nullable>
22+
23+
<!-- Display name -->
24+
<ApplicationTitle>AutoSavePDFinAWS</ApplicationTitle>
25+
26+
<!-- App Identifier -->
27+
<ApplicationId>com.companyname.autosavepdfinaws</ApplicationId>
28+
29+
<!-- Versions -->
30+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
31+
<ApplicationVersion>1</ApplicationVersion>
32+
33+
<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
34+
<WindowsPackageType>None</WindowsPackageType>
35+
36+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
37+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
38+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
39+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
40+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
41+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
42+
</PropertyGroup>
43+
44+
<ItemGroup>
45+
<!-- App Icon -->
46+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
47+
48+
<!-- Splash Screen -->
49+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
50+
51+
<!-- Images -->
52+
<MauiImage Include="Resources\Images\*" />
53+
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />
54+
55+
<!-- Custom Fonts -->
56+
<MauiFont Include="Resources\Fonts\*" />
57+
58+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
59+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
60+
</ItemGroup>
61+
62+
<ItemGroup>
63+
<PackageReference Include="AWSSDK.S3" Version="*" />
64+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
65+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
66+
<PackageReference Include="Syncfusion.Maui.PdfViewer" Version="*" />
67+
</ItemGroup>
68+
69+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36203.30 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoSavePDFinAWS", "AutoSavePDFinAWS.csproj", "{626306A7-D53A-409E-A65E-2D1D3714EC3F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{626306A7-D53A-409E-A65E-2D1D3714EC3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{626306A7-D53A-409E-A65E-2D1D3714EC3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{626306A7-D53A-409E-A65E-2D1D3714EC3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{626306A7-D53A-409E-A65E-2D1D3714EC3F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {BADD224A-DD7D-497F-A2D1-4D59A4DC92AA}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace AutoSavePDFinAWS
9+
{
10+
/// <summary>
11+
/// Value converter that inverts boolean values for data binding scenarios.
12+
/// Used in XAML to bind UI elements that need the opposite of a boolean property.
13+
/// For example, enabling a Save button when Auto-Save is disabled.
14+
/// </summary>
15+
public class InverseBooleanConverter : IValueConverter
16+
{
17+
/// <summary>
18+
/// Converts a boolean value to its inverse.
19+
/// </summary>
20+
/// <param name="value">The boolean value to convert</param>
21+
/// <param name="targetType">The type of the binding target property (must be bool)</param>
22+
/// <param name="parameter">Optional parameter for the converter (not used)</param>
23+
/// <param name="culture">Culture information for the conversion (not used)</param>
24+
/// <returns>The inverted boolean value</returns>
25+
/// <exception cref="InvalidOperationException">Thrown when target type is not boolean</exception>
26+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
27+
{
28+
// Validate that the target type is boolean
29+
if (targetType != typeof(bool))
30+
throw new InvalidOperationException("The target must be a boolean");
31+
32+
// Return the inverse of the input boolean value
33+
return value is bool boolValue ? !boolValue : false;
34+
}
35+
36+
/// <summary>
37+
/// Converts back from the inverted value to the original (not supported).
38+
/// This converter is designed for one-way binding only.
39+
/// </summary>
40+
/// <param name="value">The value to convert back</param>
41+
/// <param name="targetType">The type to convert to</param>
42+
/// <param name="parameter">Optional parameter for the converter</param>
43+
/// <param name="culture">Culture information for the conversion</param>
44+
/// <returns>Not supported</returns>
45+
/// <exception cref="NotSupportedException">Always thrown as this operation is not supported</exception>
46+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
47+
{
48+
throw new NotSupportedException("InverseBooleanConverter does not support ConvertBack operation");
49+
}
50+
}
51+
}

Save/AutoSavePDFinAWS/MainPage.xaml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:pdfViewer="clr-namespace:Syncfusion.Maui.PdfViewer;assembly=Syncfusion.Maui.PdfViewer"
5+
x:Class="AutoSavePDFinAWS.MainPage">
6+
7+
<!-- UI resource definitions -->
8+
<ContentPage.Resources>
9+
<ResourceDictionary>
10+
11+
<!-- Toolbar button style -->
12+
<Style x:Key="ToolbarButtonStyle"
13+
TargetType="Button">
14+
<Setter Property="CornerRadius"
15+
Value="6" />
16+
<Setter Property="Padding"
17+
Value="10,6" />
18+
<Setter Property="Margin"
19+
Value="5,0" />
20+
<Setter Property="BackgroundColor"
21+
Value="#3B82F6" />
22+
<Setter Property="TextColor"
23+
Value="White" />
24+
<Setter Property="FontAttributes"
25+
Value="Bold" />
26+
27+
<!-- Visual states for button -->
28+
<Setter Property="VisualStateManager.VisualStateGroups">
29+
<VisualStateGroupList>
30+
<VisualStateGroup Name="CommonStates">
31+
<!-- Normal state - default blue appearance -->
32+
<VisualState Name="Normal" />
33+
34+
<!-- Disabled state - muted gray appearance -->
35+
<VisualState Name="Disabled">
36+
<VisualState.Setters>
37+
<Setter Property="BackgroundColor"
38+
Value="#E5E7EB" />
39+
<Setter Property="TextColor"
40+
Value="#1F2937" />
41+
</VisualState.Setters>
42+
</VisualState>
43+
</VisualStateGroup>
44+
</VisualStateGroupList>
45+
</Setter>
46+
</Style>
47+
</ResourceDictionary>
48+
</ContentPage.Resources>
49+
50+
<!-- Main layout grid -->
51+
<Grid RowSpacing="0">
52+
<Grid.RowDefinitions>
53+
<RowDefinition Height="Auto" />
54+
<!-- Toolbar row - auto-sized -->
55+
<RowDefinition Height="*" />
56+
<!-- PDF viewer row - fills remaining space -->
57+
</Grid.RowDefinitions>
58+
59+
<!-- Toolbar -->
60+
<Border Grid.Row="0"
61+
BackgroundColor="#F3F4F6"
62+
Padding="12"
63+
StrokeThickness="0">
64+
<Grid ColumnSpacing="12">
65+
<Grid.ColumnDefinitions>
66+
<ColumnDefinition Width="*" />
67+
<!-- Notification area - takes remaining space -->
68+
<ColumnDefinition Width="Auto" />
69+
<!-- Button area - auto-sized -->
70+
</Grid.ColumnDefinitions>
71+
72+
<!-- Status notification label -->
73+
<Label Grid.Column="0"
74+
x:Name="NotificationLabel"
75+
Text="{Binding NotificationText}"
76+
HorizontalOptions="Start"
77+
VerticalOptions="Center" />
78+
79+
<!-- Toolbar controls -->
80+
<HorizontalStackLayout Grid.Column="1">
81+
82+
<!-- Save button (manual) -->
83+
<Button x:Name="SaveButton"
84+
FontSize="20"
85+
Text="&#xe75f;"
86+
VerticalOptions="Center"
87+
FontFamily="MauiMaterialAssets"
88+
ToolTipProperties.Text="Save PDF file manually"
89+
Style="{StaticResource ToolbarButtonStyle}"
90+
Command="{Binding SavePdfCommand}"
91+
IsEnabled="{Binding IsAutoSaveEnabled, Converter={StaticResource InverseBooleanConverter}}"/>
92+
93+
<!-- Auto-save toggle -->
94+
<Border StrokeThickness="1"
95+
Padding="0,0,12,0"
96+
Margin="4,0"
97+
Stroke="LightGray"
98+
VerticalOptions="Center">
99+
<StackLayout Orientation="Horizontal" VerticalOptions="Center">
100+
<CheckBox IsChecked="{Binding IsAutoSaveEnabled}" VerticalOptions="Center" />
101+
<Label Text="Auto Save" VerticalOptions="Center" />
102+
</StackLayout>
103+
</Border>
104+
105+
</HorizontalStackLayout>
106+
</Grid>
107+
</Border>
108+
109+
<!-- PDF Viewer with event handlers -->
110+
<pdfViewer:SfPdfViewer Grid.Row="1"
111+
x:Name="PdfViewer"
112+
DocumentLoaded="PdfViewer_DocumentLoaded"
113+
DocumentUnloaded="PdfViewer_DocumentUnloaded"
114+
AnnotationAdded="PdfViewer_AnnotationAdded"
115+
AnnotationRemoved="PdfViewer_AnnotationRemoved"
116+
AnnotationEdited="PdfViewer_AnnotationEdited"
117+
FormFieldValueChanged="PdfViewer_FormFieldValueChanged" />
118+
</Grid>
119+
120+
</ContentPage>

0 commit comments

Comments
 (0)