Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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: 14 additions & 0 deletions Toolbar customization/InsertToolbarItems/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:InsertToolbarItems"
x:Class="InsertToolbarItems.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
16 changes: 16 additions & 0 deletions Toolbar customization/InsertToolbarItems/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace InsertToolbarItems
{
public partial class App : Application
{
public App()
{
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Add valid license key");
InitializeComponent();
}

protected override Window CreateWindow(IActivationState? activationState)
{
return new Window(new AppShell());
}
}
}
14 changes: 14 additions & 0 deletions Toolbar customization/InsertToolbarItems/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="InsertToolbarItems.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:InsertToolbarItems"
Title="InsertToolbarItems">

<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

</Shell>
10 changes: 10 additions & 0 deletions Toolbar customization/InsertToolbarItems/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace InsertToolbarItems
{
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
}
Binary file not shown.
101 changes: 101 additions & 0 deletions Toolbar customization/InsertToolbarItems/FileService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace InsertToolbarItems
{
/// <summary>
/// Provides the functionality to open and save PDF files.
/// </summary>
public partial class FileService
{
/// <summary>
/// Shows a file picker and lets the user choose the required PDF file.
/// </summary>
/// <returns>The data of the PDF file that is chosen by the user.</returns>
public async static Task<PdfFileData?> OpenFile(string fileExtension)
{
FilePickerFileType pdfFileType = new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>{
{ DevicePlatform.iOS, new[] { $"com.adobe.{fileExtension}" } },
{ DevicePlatform.Android, new[] { $"application/{fileExtension}" } },
{ DevicePlatform.WinUI, new[] { fileExtension } },
{ DevicePlatform.MacCatalyst, new[] { fileExtension } },
});
PickOptions options = new()
{
PickerTitle = "Please select a PDF file",
};
#if !ANDROID
options.FileTypes = pdfFileType;
#else
if (fileExtension == "pdf")
options.FileTypes = pdfFileType;
#endif
return await PickFile(options, fileExtension);
}
static async Task<PdfFileData?> PickFile(PickOptions options, string fileExtension)
{
try
{
var result = await FilePicker.Default.PickAsync(options);
if (result != null)
{
if (result.FileName != null)
{
if (result.FileName.EndsWith($".{fileExtension}", StringComparison.OrdinalIgnoreCase))
{
return new PdfFileData(result.FileName, await result.OpenReadAsync());
}
else
Application.Current?.Windows[0].Page?.DisplayAlert("Error", $"Pick a file of type {fileExtension}", "OK");
}
}
return null;
}
catch (Exception ex)
{
string message;
if (ex != null && string.IsNullOrEmpty(ex.Message) == false)
message = ex.Message;
else
message = "File open failed.";
Application.Current?.Windows[0].Page?.DisplayAlert("Error", message, "OK");
}
return null;
}
/// <summary>
/// Saves the PDF stream with given file name using platform specific file saving APIs.
/// </summary>
/// <param name="fileName">The file name with which the PDF needs to be saved.</param>
/// <param name="fileStream">The stream of the PDF to be saved.</param>
/// <returns></returns>
public async static Task<string?> SaveAsAsync(string fileName, Stream fileStream)
{
return await PlatformSaveAsAsync(fileName, fileStream);
}

/// <summary>
/// Writes the given stream to the specified file path.
/// </summary>
/// <param name="stream">The stream of the PDF file to be written.</param>
/// <param name="filePath">The file path to which the PDF file needs to be written.</param>
/// <returns></returns>
static async Task WriteStream(Stream stream, string? filePath)
{
if (!string.IsNullOrEmpty(filePath))
{
await using var fileStream = new FileStream(filePath, FileMode.OpenOrCreate);
fileStream.SetLength(0);
if (stream.CanSeek)
{
stream.Seek(0, SeekOrigin.Begin);
}

await stream.CopyToAsync(fileStream).ConfigureAwait(false);
Copy link
Collaborator

@Deepak1799 Deepak1799 Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this copy is required instead of directly used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have optimized the code sir

Copy link
Collaborator Author

@Nandhakumar-SF4686 Nandhakumar-SF4686 Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For optimization I have created a method and used in three platforms sir

Copy link
Collaborator Author

@Nandhakumar-SF4686 Nandhakumar-SF4686 Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to copy the input stream into the file for saving

}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions Toolbar customization/InsertToolbarItems/InsertToolbarItems.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net9.0-tizen</TargetFrameworks> -->

<!-- Note for MacCatalyst:
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

<OutputType>Exe</OutputType>
<RootNamespace>InsertToolbarItems</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<!-- Display name -->
<ApplicationTitle>InsertToolbarItems</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.companyname.inserttoolbaritems</ApplicationId>

<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
<WindowsPackageType>None</WindowsPackageType>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<None Remove="Assets\PDF_Succinctly.pdf" />
<None Remove="Images\After Toolbar Item Insertion.png" />
<None Remove="Images\Before Toolbar Item Insertion.png" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Assets\PDF_Succinctly.pdf" />
<EmbeddedResource Include="Images\After Toolbar Item Insertion.png" />
<EmbeddedResource Include="Images\Before Toolbar Item Insertion.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="Syncfusion.Maui.PdfViewer" Version="*" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions Toolbar customization/InsertToolbarItems/InsertToolbarItems.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36203.30 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InsertToolbarItems", "InsertToolbarItems.csproj", "{773AA570-9D7E-4621-9F49-91AD746F5094}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{773AA570-9D7E-4621-9F49-91AD746F5094}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{773AA570-9D7E-4621-9F49-91AD746F5094}.Debug|Any CPU.Build.0 = Debug|Any CPU
{773AA570-9D7E-4621-9F49-91AD746F5094}.Release|Any CPU.ActiveCfg = Release|Any CPU
{773AA570-9D7E-4621-9F49-91AD746F5094}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B8544DAF-EDF6-4AC3-8C43-DA0D9ACB7EDE}
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions Toolbar customization/InsertToolbarItems/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?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:syncfusion="clr-namespace:Syncfusion.Maui.PdfViewer;assembly=Syncfusion.Maui.PdfViewer"
x:Class="InsertToolbarItems.MainPage">


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unwanted extra line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed it sir

<Grid>
<syncfusion:SfPdfViewer x:Name="pdfViewer"/>
</Grid>

</ContentPage>
Loading