Skip to content

Commit b975dc0

Browse files
committed
1017354: Added proper sample project for MAUI.
1 parent f4d314b commit b975dc0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+181
-163
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="CreateMAUIPDFSample/CreateMAUIPDFSample.csproj" />
3+
</Solution>

Getting Started/MAUI/CreatePdfDemoSample/CreatePdfDemoSample/App.xaml renamed to Getting Started/MAUI/CreateMAUIPDFSample/CreateMAUIPDFSample/App.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version = "1.0" encoding = "UTF-8" ?>
22
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4-
xmlns:local="clr-namespace:CreatePdfDemoSample"
5-
x:Class="CreatePdfDemoSample.App">
4+
xmlns:local="clr-namespace:CreateMAUIPDFSample"
5+
x:Class="CreateMAUIPDFSample.App">
66
<Application.Resources>
77
<ResourceDictionary>
88
<ResourceDictionary.MergedDictionaries>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
3+
namespace CreateMAUIPDFSample
4+
{
5+
public partial class App : Application
6+
{
7+
public App()
8+
{
9+
InitializeComponent();
10+
}
11+
12+
protected override Window CreateWindow(IActivationState? activationState)
13+
{
14+
return new Window(new AppShell());
15+
}
16+
}
17+
}

Getting Started/MAUI/CreatePdfDemoSample/CreatePdfDemoSample/AppShell.xaml renamed to Getting Started/MAUI/CreateMAUIPDFSample/CreateMAUIPDFSample/AppShell.xaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<Shell
3-
x:Class="CreatePdfDemoSample.AppShell"
3+
x:Class="CreateMAUIPDFSample.AppShell"
44
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
55
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6-
xmlns:local="clr-namespace:CreatePdfDemoSample"
7-
Shell.FlyoutBehavior="Disabled"
8-
Title="CreatePdfDemoSample">
6+
xmlns:local="clr-namespace:CreateMAUIPDFSample"
7+
Title="CreateMAUIPDFSample">
98

109
<ShellContent
1110
Title="Home"

Getting Started/MAUI/CreatePdfDemoSample/CreatePdfDemoSample/AppShell.xaml.cs renamed to Getting Started/MAUI/CreateMAUIPDFSample/CreateMAUIPDFSample/AppShell.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace CreatePdfDemoSample
1+
namespace CreateMAUIPDFSample
22
{
33
public partial class AppShell : Shell
44
{

Getting Started/MAUI/CreatePdfDemoSample/CreatePdfDemoSample/CreatePdfDemoSample.csproj renamed to Getting Started/MAUI/CreateMAUIPDFSample/CreateMAUIPDFSample/CreateMAUIPDFSample.csproj

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
5-
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.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);net8.0-tizen</TargetFrameworks> -->
4+
<TargetFrameworks>net10.0-android;net10.0-ios;net10.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net10.0-windows10.0.19041.0</TargetFrameworks>
86

97
<!-- Note for MacCatalyst:
108
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
@@ -14,28 +12,30 @@
1412
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
1513

1614
<OutputType>Exe</OutputType>
17-
<RootNamespace>CreatePdfDemoSample</RootNamespace>
15+
<RootNamespace>CreateMAUIPDFSample</RootNamespace>
1816
<UseMaui>true</UseMaui>
1917
<SingleProject>true</SingleProject>
2018
<ImplicitUsings>enable</ImplicitUsings>
2119
<Nullable>enable</Nullable>
2220

2321
<!-- Display name -->
24-
<ApplicationTitle>CreatePdfDemoSample</ApplicationTitle>
22+
<ApplicationTitle>CreateMAUIPDFSample</ApplicationTitle>
2523

2624
<!-- App Identifier -->
27-
<ApplicationId>com.companyname.createpdfdemosample</ApplicationId>
25+
<ApplicationId>com.companyname.CreateMAUIPDFSample</ApplicationId>
2826

2927
<!-- Versions -->
3028
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
3129
<ApplicationVersion>1</ApplicationVersion>
3230

33-
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
34-
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
31+
<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
32+
<WindowsPackageType>None</WindowsPackageType>
33+
34+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
35+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
3536
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
3637
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
3738
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
38-
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
3939
</PropertyGroup>
4040

4141
<ItemGroup>
@@ -48,7 +48,7 @@
4848
<!-- Images -->
4949
<MauiImage Include="Resources\Images\*" />
5050
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />
51-
51+
5252
<!-- Custom Fonts -->
5353
<MauiFont Include="Resources\Fonts\*" />
5454

@@ -63,16 +63,33 @@
6363
</ItemGroup>
6464

6565
<ItemGroup>
66-
<EmbeddedResource Include="Resources\Pdf\AdventureCycle.txt" />
67-
<EmbeddedResource Include="Resources\Pdf\AdventureWork.png" />
68-
<EmbeddedResource Include="Resources\Pdf\arial.ttf" />
66+
<EmbeddedResource Include="Resources\Pdf\AdventureCycle.txt">
67+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
68+
</EmbeddedResource>
69+
<EmbeddedResource Include="Resources\Pdf\AdventureWork.png">
70+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
71+
</EmbeddedResource>
72+
<EmbeddedResource Include="Resources\Pdf\arial.ttf">
73+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
74+
</EmbeddedResource>
6975
</ItemGroup>
7076

7177
<ItemGroup>
7278
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
73-
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
74-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
75-
<PackageReference Include="Syncfusion.Pdf.NET" Version="*" />
79+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.0" />
80+
<PackageReference Include="Syncfusion.Pdf.NET" Version="33.1.44" />
81+
</ItemGroup>
82+
83+
<ItemGroup>
84+
<Compile Update="Platforms\Android\SaveAndroid.cs">
85+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
86+
</Compile>
87+
<Compile Update="Platforms\iOS\SaveIOS.cs">
88+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
89+
</Compile>
90+
<Compile Update="Services\SaveService.cs">
91+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
92+
</Compile>
7693
</ItemGroup>
7794

7895
</Project>

Getting Started/MAUI/CreatePdfDemoSample/CreatePdfDemoSample/CreatePdfDemoSample.csproj.user renamed to Getting Started/MAUI/CreateMAUIPDFSample/CreateMAUIPDFSample/CreateMAUIPDFSample.csproj.user

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
5-
<ActiveDebugFramework>net8.0-android</ActiveDebugFramework>
6-
<ActiveDebugProfile>Pixel 5 - API 33 (Android 13.0 - API 33)</ActiveDebugProfile>
7-
<SelectedPlatformGroup>Emulator</SelectedPlatformGroup>
8-
<DefaultDevice>pixel_5_-_api_33</DefaultDevice>
5+
<ActiveDebugFramework>net10.0-windows10.0.19041.0</ActiveDebugFramework>
6+
<ActiveDebugProfile>Windows Machine</ActiveDebugProfile>
7+
<SelectedPlatformGroup>RemoteDevice</SelectedPlatformGroup>
98
</PropertyGroup>
109
<PropertyGroup Condition="'$(TargetPlatformIdentifier)'=='iOS'">
1110
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
1211
<PlatformTarget>arm64</PlatformTarget>
1312
</PropertyGroup>
14-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'">
13+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net10.0-android|AnyCPU'">
1514
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
1615
</PropertyGroup>
1716
<ItemGroup>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
x:Class="CreateMAUIPDFSample.MainPage">
5+
6+
<ScrollView>
7+
<Button
8+
x:Name="Btn"
9+
Text="Create PDF"
10+
FontAttributes="Bold"
11+
Grid.Row="3"
12+
Clicked="createPdf_Click"
13+
HorizontalOptions="Center"
14+
VerticalOptions="Center"/>
15+
</ScrollView>
16+
17+
</ContentPage>

Getting Started/MAUI/CreatePdfDemoSample/CreatePdfDemoSample/MainPage.xaml.cs renamed to Getting Started/MAUI/CreateMAUIPDFSample/CreateMAUIPDFSample/MainPage.xaml.cs

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CreatePdfDemoSample.Services;
1+
using CreateMAUIPDFSample.Services;
22
using Syncfusion.Drawing;
33
using Syncfusion.Pdf;
44
using Syncfusion.Pdf.Graphics;
@@ -8,8 +8,7 @@
88
using PointF = Syncfusion.Drawing.PointF;
99
using SizeF = Syncfusion.Drawing.SizeF;
1010

11-
12-
namespace CreatePdfDemoSample
11+
namespace CreateMAUIPDFSample
1312
{
1413
public partial class MainPage : ContentPage
1514
{
@@ -27,14 +26,11 @@ public void createPdf_Click(object sender, EventArgs e)
2726
PdfPage page = document.Pages.Add();
2827
//Create PDF graphics for the page.
2928
PdfGraphics graphics = page.Graphics;
30-
3129
RectangleF TotalPriceCellBounds = RectangleF.Empty;
3230
RectangleF QuantityCellBounds = RectangleF.Empty;
33-
3431
//Get the page width and height
3532
float pageWidth = page.GetClientSize().Width;
3633
float pageHeight = page.GetClientSize().Height;
37-
3834
//Set the header height
3935
float headerHeight = 90;
4036
//Create brush with light blue color.
@@ -45,45 +41,34 @@ public void createPdf_Click(object sender, EventArgs e)
4541
PdfBrush darkBlueBrush = new PdfSolidBrush(darkBlue);
4642
//Create brush with white color.
4743
PdfBrush whiteBrush = new PdfSolidBrush(Color.FromArgb(255, 255, 255, 255));
48-
4944
//Get the font file stream from assembly.
5045
Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly;
51-
string basePath = "CreatePdfDemoSample.Resources.Pdf.";
46+
string basePath = "CreateMAUIPDFSample.Resources.Pdf.";
5247
Stream fontStream = assembly.GetManifestResourceStream(basePath + "arial.ttf");
53-
5448
//Create PdfTrueTypeFont from stream with different size.
5549
PdfTrueTypeFont headerFont = new(fontStream, 30, PdfFontStyle.Regular);
5650
PdfTrueTypeFont arialRegularFont = new(fontStream, 18, PdfFontStyle.Regular);
5751
PdfTrueTypeFont arialBoldFont = new(fontStream, 9, PdfFontStyle.Bold);
58-
5952
//Create string format.
6053
PdfStringFormat format = new();
6154
format.Alignment = PdfTextAlignment.Center;
6255
format.LineAlignment = PdfVerticalAlignment.Middle;
63-
6456
float y = 0;
6557
float x = 0;
66-
6758
//Set the margins of address.
6859
float margin = 30;
69-
7060
//Set the line space.
7161
float lineSpace = 10;
72-
7362
//Create border pen and draw the border to PDF page.
7463
PdfColor borderColor = Color.FromArgb(255, 142, 170, 219);
7564
PdfPen borderPen = new(borderColor, 1f);
7665
graphics.DrawRectangle(borderPen, new RectangleF(0, 0, pageWidth, pageHeight));
77-
7866
//Create a new PdfGrid
7967
PdfGrid grid = new();
80-
8168
//Add five columns to the grid.
8269
grid.Columns.Add(5);
83-
8470
//Create the header row of the grid.
8571
PdfGridRow[] headerRow = grid.Headers.Add(1);
86-
8772
//Set style to the header row and set value to the header cells.
8873
headerRow[0].Style.BackgroundBrush = new PdfSolidBrush(new PdfColor(68, 114, 196));
8974
headerRow[0].Style.TextBrush = PdfBrushes.White;
@@ -93,15 +78,13 @@ public void createPdf_Click(object sender, EventArgs e)
9378
headerRow[0].Cells[2].Value = "Price ($)";
9479
headerRow[0].Cells[3].Value = "Quantity";
9580
headerRow[0].Cells[4].Value = "Total ($)";
96-
9781
//Add products to the grid table.
9882
AddProducts("CA-1098", "AWC Logo Cap", 8.99, 2, 17.98, grid);
9983
AddProducts("LJ-0192", "Long-Sleeve Logo Jersey,M", 49.99, 3, 149.97, grid);
10084
AddProducts("So-B909-M", "Mountain Bike Socks,M", 9.50, 2, 19, grid);
10185
AddProducts("LJ-0192", "Long-Sleeve Logo Jersey,M", 49.99, 4, 199.96, grid);
10286
AddProducts("FK-5136", "ML Fork", 175.49, 6, 1052.94, grid);
10387
AddProducts("HL-U509", "Sports-100 Helmet,Black", 34.99, 1, 34.99, grid);
104-
10588
#region Header
10689

10790
//Fill the header with light blue brush
@@ -137,7 +120,6 @@ public void createPdf_Click(object sender, EventArgs e)
137120
y += arialRegularFont.Height + lineSpace;
138121
//Draw text to PDF page with provided font and location.
139122
graphics.DrawString("Date: " + DateTime.Now.ToString("dddd dd, MMMM yyyy"), arialRegularFont, PdfBrushes.Black, new PointF(x, y));
140-
141123
y = headerHeight + margin;
142124
x = margin;
143125
//Draw text to PDF page with provided font and location.
@@ -150,7 +132,6 @@ public void createPdf_Click(object sender, EventArgs e)
150132
graphics.DrawString("9920 BridgePointe Parkway,", arialRegularFont, PdfBrushes.Black, new PointF(x, y));
151133
y += arialRegularFont.Height + lineSpace;
152134
graphics.DrawString("9365550136", arialRegularFont, PdfBrushes.Black, new PointF(x, y));
153-
154135
#region Grid
155136
//Set width to grid columns.
156137
grid.Columns[0].Width = 110;
@@ -227,10 +208,8 @@ public void createPdf_Click(object sender, EventArgs e)
227208
borderPen.DashStyle = PdfDashStyle.Custom;
228209
borderPen.DashPattern = new float[] { 3, 3 };
229210
graphics.DrawLine(borderPen, new PointF(0, pageHeight - 100), new PointF(pageWidth, pageHeight - 100));
230-
231211
//Get the image file stream from assembly.
232212
Stream imageStream = assembly.GetManifestResourceStream(basePath + "AdventureWork.png");
233-
234213
//Create PDF bitmap image from stream.
235214
PdfBitmap bitmap = new(imageStream);
236215
//Draw the image to PDF page.
@@ -241,26 +220,16 @@ public void createPdf_Click(object sender, EventArgs e)
241220
size = arialRegularFont.MeasureString("800 Interchange Blvd.");
242221
x = pageWidth - size.Width - margin;
243222
graphics.DrawString("800 Interchange Blvd.", arialRegularFont, PdfBrushes.Black, new PointF(x, y));
244-
245223
//Calculate the text position and draw the text to PDF page.
246224
y += arialRegularFont.Height + lineSpace;
247225
size = arialRegularFont.MeasureString("Suite 2501, Austin, TX 78721");
248226
x = pageWidth - size.Width - margin;
249227
graphics.DrawString("Suite 2501, Austin, TX 78721", arialRegularFont, PdfBrushes.Black, new PointF(x, y));
250-
251228
//Calculate the text position and draw the text to PDF page.
252229
y += arialRegularFont.Height + lineSpace;
253230
size = arialRegularFont.MeasureString("Any Questions? support@adventure-works.com");
254231
x = pageWidth - size.Width - margin;
255232
graphics.DrawString("Any Questions? support@adventure-works.com", arialRegularFont, PdfBrushes.Black, new PointF(x, y));
256-
257-
258-
//Add a new blank PDF page.
259-
PdfPage page1 = document.Pages.Add();
260-
261-
//Draw the image to the PDF page.
262-
page1.Graphics.DrawImage(bitmap, 0, 0, 200, 200);
263-
264233
using MemoryStream ms = new();
265234
//Save the PDF document to MemoryStream.
266235
document.Save(ms);
@@ -270,7 +239,6 @@ public void createPdf_Click(object sender, EventArgs e)
270239
//Saves the memory stream as file using the SaveService instance.
271240
SaveService save = new SaveService();
272241
save.SaveAndView("output.pdf", "application/pdf", ms);
273-
274242
void Grid_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args)
275243
{
276244
PdfGrid grid = sender as PdfGrid;
@@ -286,8 +254,6 @@ void Grid_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args)
286254
}
287255
}
288256
}
289-
290-
291257
//Create and row for the grid.
292258
void AddProducts(string productId, string productName, double price, int quantity, double total, PdfGrid grid)
293259
{
@@ -312,9 +278,6 @@ private float GetTotalAmount(PdfGrid grid)
312278
Total += result;
313279
}
314280
return Total;
315-
316281
}
317-
318282
}
319-
320283
}

Getting Started/MAUI/CreatePdfDemoSample/CreatePdfDemoSample/MauiProgram.cs renamed to Getting Started/MAUI/CreateMAUIPDFSample/CreateMAUIPDFSample/MauiProgram.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.Extensions.Logging;
22

3-
namespace CreatePdfDemoSample
3+
namespace CreateMAUIPDFSample
44
{
55
public static class MauiProgram
66
{

0 commit comments

Comments
 (0)