Skip to content
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: 14 additions & 0 deletions Annotations/TextPolygonSample/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:TextPolygonSample"
x:Class="TextPolygonSample.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 Annotations/TextPolygonSample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace TextPolygonSample
{
public partial class App : Application
{
public App()
{
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Ix0oFS8QJAw9HSQvXkVhQlBad1RDX3xKf0x/TGpQb19xflBPallYVBYiSV9jS3tTfkdnWHdbd3dWRGZUWU91Xg==");
InitializeComponent();
}

protected override Window CreateWindow(IActivationState? activationState)
{
return new Window(new AppShell());
}
}
}
14 changes: 14 additions & 0 deletions Annotations/TextPolygonSample/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="TextPolygonSample.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TextPolygonSample"
Title="TextPolygonSample">

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

</Shell>
10 changes: 10 additions & 0 deletions Annotations/TextPolygonSample/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace TextPolygonSample
{
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
}
Binary file not shown.
11 changes: 11 additions & 0 deletions Annotations/TextPolygonSample/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?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="TextPolygonSample.MainPage">

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

</ContentPage>
128 changes: 128 additions & 0 deletions Annotations/TextPolygonSample/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using Syncfusion.Maui.PdfViewer;
using System.Globalization;

namespace TextPolygonSample
{
public partial class MainPage : ContentPage
{
// Define a variable to hold the polygon bounds and thickness for positioning other annotations
RectF polygonBounds;
float polygonThickness;
PolygonAnnotation? polygonAnnotation;
FreeTextAnnotation? textAnnotation;

public MainPage()
{
InitializeComponent();

// Load a PDF document embedded in the project resources
Stream? documentStream = this.GetType().Assembly.GetManifestResourceStream("TextPolygonSample.Assets.Annotations.pdf");

// Load the PDF document into the SfPdfViewer
PdfViewer.LoadDocument(documentStream);

// Call method to convert coordinates and add polygon annotations to the PDF
ConvertAndAddPolygonAnnotation();

// Create and add free text annotation within the polygon
CreateAndAddFreeTextAnnotation();
}

// Converts coordinate to polygon points and adds polygon and text annotations
void ConvertAndAddPolygonAnnotation()
{
// Example coordinates for a polygon
var coordinates = "M50 27L111 27L111 63L50 63";

// Create and add polygon annotation based on coordinate
CreateAndAddPolygonAnnotation(coordinates);
}

// Creates and adds a free text annotation inside the polygon annotation
private void CreateAndAddFreeTextAnnotation()
{
// Text to be displayed within the free text annotation
string text = "TOMTEST";

// Calculate position and size of the free text annotation
float FreeTextX = polygonBounds.X + polygonThickness;
float FreeTextY = polygonBounds.Y + polygonThickness;
float FreeTextWidth = polygonBounds.Width - polygonThickness;
float FreeTextHeight = polygonBounds.Height - polygonThickness;

// Define bounds for the free text annotation
RectF freeTextBounds = new RectF(FreeTextX, FreeTextY, FreeTextWidth, FreeTextHeight);

// Create a free text annotation and add it to the PDF viewer
textAnnotation = new FreeTextAnnotation(text, 1, freeTextBounds);
PdfViewer.AddAnnotation(textAnnotation);
}

// Converts coordinates to a list of points for the polygon annotation
public List<PointF> ConvertCoordinatesToPolygonPoints(string coordinatesData)
{
// List to hold the parsed points
var points = new List<PointF>();

// Split the coordinates data into commands based on the 'M' (move to) and 'L' (line to) commands
string[] commands = coordinatesData.Split(new char[] { 'M', 'L' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var command in commands)
{
// Separate each command into X and Y coordinates
string[] coords = command.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (coords.Length >= 2)
{
// Parse the coordinates and add to the list as a PointF object
float x = float.Parse(coords[0], CultureInfo.InvariantCulture);
float y = float.Parse(coords[1], CultureInfo.InvariantCulture);
points.Add(new PointF(x, y));
}
}
return points;
}

// Creates a polygon annotation from a list of points
private PolygonAnnotation CreatePolygonAnnotation(List<PointF> polygonPoints)
{
// Create the polygon annotation and set its properties
PolygonAnnotation polygonAnnotation = new PolygonAnnotation(polygonPoints, 1);
polygonAnnotation.Color = Colors.Black; // Set annotation color
polygonAnnotation.Opacity = 25; // Set annotation opacity

// Set the bounds and thickness for use in positioning other annotations
polygonBounds = polygonAnnotation.Bounds;
polygonThickness = polygonAnnotation.BorderWidth;

// Set a solid border style for the polygon
polygonAnnotation.BorderStyle = BorderStyle.Solid;

return polygonAnnotation;
}

// Parses coordinate, creates a polygon annotation, and adds it to the PDF viewer
private void CreateAndAddPolygonAnnotation(string coordinate)
{
// Convert coordinate to a list of polygon points
List<PointF> polygonPoints = ConvertCoordinatesToPolygonPoints(coordinate);

// Create the polygon annotation from the points
polygonAnnotation = CreatePolygonAnnotation(polygonPoints);

// Add the polygon annotation to the PDF document
PdfViewer.AddAnnotation(polygonAnnotation);
}

//private void PdfViewer_AnnotationEdited(object sender, AnnotationEventArgs e)
//{
// if (e.Annotation is FreeTextAnnotation annotation && annotation == textAnnotation && polygonAnnotation != null)
// {
// polygonBounds = annotation.Bounds;
// }
// if (polygonAnnotation != null)
// {
// polygonAnnotation.Bounds = polygonBounds;
// polygonAnnotation.Points = new List<PointF>() { new PointF(polygonBounds.X, polygonBounds.Y), new PointF(polygonBounds.X + polygonBounds.Width, polygonBounds.Y), new PointF(polygonBounds.X, polygonBounds.Y + polygonBounds.Height), new PointF(polygonBounds.X + polygonBounds.Width, polygonBounds.Y + polygonBounds.Height) };
// }
//}
}
}
27 changes: 27 additions & 0 deletions Annotations/TextPolygonSample/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.Logging;
using Syncfusion.Maui.Core.Hosting;

namespace TextPolygonSample
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureSyncfusionCore()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
11 changes: 11 additions & 0 deletions Annotations/TextPolygonSample/Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace TextPolygonSample
{
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
}
16 changes: 16 additions & 0 deletions Annotations/TextPolygonSample/Platforms/Android/MainApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Android.App;
using Android.Runtime;

namespace TextPolygonSample
{
[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#512BD4</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
</resources>
10 changes: 10 additions & 0 deletions Annotations/TextPolygonSample/Platforms/MacCatalyst/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Foundation;

namespace TextPolygonSample
{
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- See https://aka.ms/maui-publish-app-store#add-entitlements for more information about adding entitlements.-->
<dict>
<!-- App Sandbox must be enabled to distribute a MacCatalyst app through the Mac App Store. -->
<key>com.apple.security.app-sandbox</key>
<true/>
<!-- When App Sandbox is enabled, this value is required to open outgoing network connections. -->
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>

38 changes: 38 additions & 0 deletions Annotations/TextPolygonSample/Platforms/MacCatalyst/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- The Mac App Store requires you specify if the app uses encryption. -->
<!-- Please consult https://developer.apple.com/documentation/bundleresources/information_property_list/itsappusesnonexemptencryption -->
<!-- <key>ITSAppUsesNonExemptEncryption</key> -->
<!-- Please indicate <true/> or <false/> here. -->

<!-- Specify the category for your app here. -->
<!-- Please consult https://developer.apple.com/documentation/bundleresources/information_property_list/lsapplicationcategorytype -->
<!-- <key>LSApplicationCategoryType</key> -->
<!-- <string>public.app-category.YOUR-CATEGORY-HERE</string> -->
<key>UIDeviceFamily</key>
<array>
<integer>2</integer>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
</dict>
</plist>
16 changes: 16 additions & 0 deletions Annotations/TextPolygonSample/Platforms/MacCatalyst/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ObjCRuntime;
using UIKit;

namespace TextPolygonSample
{
public class Program
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, typeof(AppDelegate));
}
}
}
17 changes: 17 additions & 0 deletions Annotations/TextPolygonSample/Platforms/Tizen/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using Microsoft.Maui;
using Microsoft.Maui.Hosting;

namespace TextPolygonSample
{
internal class Program : MauiApplication
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

static void Main(string[] args)
{
var app = new Program();
app.Run(args);
}
}
}
15 changes: 15 additions & 0 deletions Annotations/TextPolygonSample/Platforms/Tizen/tizen-manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="maui-application-id-placeholder" version="0.0.0" api-version="9" xmlns="http://tizen.org/ns/packages">
<profile name="common" />
<ui-application appid="maui-application-id-placeholder" exec="TextPolygonSample.dll" multiple="false" nodisplay="false" taskmanage="true" type="dotnet" launch_mode="single">
<label>maui-application-title-placeholder</label>
<icon>maui-appicon-placeholder</icon>
<metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true" />
</ui-application>
<shortcut-list />
<privileges>
<privilege>http://tizen.org/privilege/internet</privilege>
</privileges>
<dependencies />
<provides-appdefined-privileges />
</manifest>
8 changes: 8 additions & 0 deletions Annotations/TextPolygonSample/Platforms/Windows/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<maui:MauiWinUIApplication
x:Class="TextPolygonSample.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui"
xmlns:local="using:TextPolygonSample.WinUI">

</maui:MauiWinUIApplication>
Loading