Skip to content

Commit

Permalink
Add support for net8.0-ios
Browse files Browse the repository at this point in the history
This commit addes support for net8.0-ios to the library and the MauiApp test. It will only work on the device (no support for iossimulator runtime)

MauiApp - added the code to associate the first page image to the Image control
  • Loading branch information
Dan Ardelean committed Oct 16, 2024
1 parent d8f9c66 commit 5d04c5a
Show file tree
Hide file tree
Showing 12 changed files with 330 additions and 119 deletions.
3 changes: 2 additions & 1 deletion src/FrameworkTests/MauiApp/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<Image HeightRequest="200"
HorizontalOptions="Center"
x:Name="imgTest"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
Source="dotnet_bot.png" />

Expand All @@ -23,7 +24,7 @@
HorizontalOptions="Center"
SemanticProperties.Description="Welcome to dot net Multi platform App U I"
SemanticProperties.HeadingLevel="Level2"
Text="Tab the button below to test PDFtoImage." />
Text="Tap the button below to test PDFtoImage." />

<Button x:Name="CounterBtn"
Clicked="OnCounterClicked"
Expand Down
25 changes: 21 additions & 4 deletions src/FrameworkTests/MauiApp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace PDFtoImage.FrameworkTests.MauiApp
using SkiaSharp;

namespace PDFtoImage.FrameworkTests.MauiApp
{
public partial class MainPage : ContentPage
{
Expand All @@ -7,17 +9,32 @@ public MainPage()
InitializeComponent();
}

private SKBitmap _bitmap;
private async void OnCounterClicked(object sender, EventArgs e)
{
try
{
using var input = await FileSystem.OpenAppPackageFileAsync("SocialPreview.pdf");
using var ms = new MemoryStream();
input.CopyTo(ms);
input.CopyTo(ms);

_bitmap = PDFtoImage.Conversion.ToImage(ms, 0);
OutputLabel.Text = $"SocialPreview.pdf size: {_bitmap.Width}x{_bitmap.Height}";

SKImage image = SKImage.FromBitmap(_bitmap);
SKData encodedData = image.Encode(SKEncodedImageFormat.Png, 100);
string imagePath = Path.Combine(FileSystem.CacheDirectory, "image.png");
var bitmapImageStream = File.Open(imagePath,
FileMode.Create,
FileAccess.Write,
FileShare.None);
encodedData.SaveTo(bitmapImageStream);
bitmapImageStream.Flush(true);
bitmapImageStream.Dispose();

imgTest.Source = ImageSource.FromFile(imagePath);

using var bitmap = PDFtoImage.Conversion.ToImage(ms, 0);

OutputLabel.Text = $"SocialPreview.pdf size: {bitmap.Width}x{bitmap.Height}";
}
catch (Exception ex)
{
Expand Down
15 changes: 11 additions & 4 deletions src/FrameworkTests/MauiApp/MauiApp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-android</TargetFrameworks>
<TargetFrameworks>net8.0-android;net8.0-ios</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.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);net8.0-tizen</TargetFrameworks> -->
Expand Down Expand Up @@ -30,6 +30,13 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='net8.0-ios'">
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
Expand All @@ -49,9 +56,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.90" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.90" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.92" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.92" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/PDFtoImage/Compatibility/Conversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace PDFtoImage.Compatibility
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("iOS")]
[SupportedOSPlatform("Android31.0")]
#endif
[Obsolete("This class is for backward compatibility. Use PDFtoImage.Conversion instead.", false)]
Expand Down
1 change: 1 addition & 0 deletions src/PDFtoImage/Conversion.Base64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace PDFtoImage
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("iOS")]
[SupportedOSPlatform("Android31.0")]
#endif
public static partial class Conversion
Expand Down
1 change: 1 addition & 0 deletions src/PDFtoImage/Conversion.ByteArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace PDFtoImage
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("iOS")]
[SupportedOSPlatform("Android31.0")]
#endif
public static partial class Conversion
Expand Down
1 change: 1 addition & 0 deletions src/PDFtoImage/Conversion.Deprecated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace PDFtoImage
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("iOS")]
[SupportedOSPlatform("Android31.0")]
#endif
public static partial class Conversion
Expand Down
1 change: 1 addition & 0 deletions src/PDFtoImage/Conversion.Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace PDFtoImage
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("iOS")]
[SupportedOSPlatform("Android31.0")]
#endif
public static partial class Conversion
Expand Down
1 change: 1 addition & 0 deletions src/PDFtoImage/Conversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace PDFtoImage
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("iOS")]
[SupportedOSPlatform("Android31.0")]
#endif
public static partial class Conversion
Expand Down
217 changes: 107 additions & 110 deletions src/PDFtoImage/PDFtoImage.csproj
Original file line number Diff line number Diff line change
@@ -1,111 +1,108 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- Assembly -->
<PropertyGroup>
<TargetFrameworks>net462;net471;net481;net6.0;net7.0;net8.0;net8.0-android;netstandard2.0</TargetFrameworks>
<AssemblyName>PDFtoImage</AssemblyName>
<RootNamespace>PDFtoImage</RootNamespace>
<EmbedAllSources>true</EmbedAllSources>
<AssemblyOriginatorKeyFile>PDFtoImage.snk</AssemblyOriginatorKeyFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Configurations>Debug;Release;ReleaseSigned</Configurations>
<ProjectGuid>{A6F86FA0-87FE-406E-BA86-5A128D59DA12}</ProjectGuid>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>
</PropertyGroup>

<!-- NuGet -->
<PropertyGroup>
<VersionPrefix>4.1.1</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Authors>David Sungaila</Authors>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>Icon_128.png</PackageIcon>
<PackageProjectUrl>https://github.com/sungaila/PDFtoImage</PackageProjectUrl>
<PackageIconUrl>https://raw.githubusercontent.com/sungaila/PDFtoImage/master/etc/Icon_128.png</PackageIconUrl>
<Description>A .NET library to render PDF files into images.</Description>
<PackageReleaseNotes>- Fixed DllNotFoundException for WebAssembly.</PackageReleaseNotes>
<PackageTags>PDF Bitmap Image Convert Conversion C# PDFium SkiaSharp Skia PNG JPG JPEG WEBP Xamarin Android MAUI wasm WebAssembly</PackageTags>
<RepositoryUrl>https://github.com/sungaila/PDFtoImage.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<!-- C# compiler -->
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<Features>strict</Features>
<WarningsAsErrors>nullable</WarningsAsErrors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<!-- Debug builds -->
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<VersionSuffix>debug</VersionSuffix>
</PropertyGroup>

<!-- Release builds -->
<PropertyGroup Condition="'$(Configuration)'=='Release' or '$(Configuration)'=='ReleaseSigned'">
<SignAssembly>true</SignAssembly>
<Optimize>true</Optimize>
<Deterministic>true</Deterministic>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<!-- Roslyn analyzer for public APIs -->
<ItemGroup>
<AdditionalFiles Include="PublicAPI\$(TargetFramework)\PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI\$(TargetFramework)\PublicAPI.Unshipped.txt" />
</ItemGroup>

<!-- NuGet Icon -->
<ItemGroup>
<None Include="..\..\etc\Icon_128.png" Pack="true" PackagePath="" />
<None Include="..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>

<!-- SourceLink build steps and NuGet packages -->
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="2.88.8" PrivateAssets="analyzers" />
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" PrivateAssets="all" />
</ItemGroup>

<!-- Shared packages -->
<ItemGroup Condition="'$(TargetFramework)'!='net8.0-android'">
<PackageReference Include="bblanchon.PDFium.Linux" Version="130.0.6721" PrivateAssets="analyzers" />
<PackageReference Include="bblanchon.PDFium.macOS" Version="130.0.6721" PrivateAssets="analyzers" />
<PackageReference Include="bblanchon.PDFium.Win32" Version="130.0.6721" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.macOS" Version="2.88.8" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.Win32" Version="2.88.8" PrivateAssets="analyzers" />
</ItemGroup>

<!-- .NET Framework packages -->
<ItemGroup Condition="'$(TargetFramework)'=='net462'">
<PackageReference Include="System.ValueTuple" Version="4.5.0" PrivateAssets="all" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" PrivateAssets="all" />
</ItemGroup>

<!-- .NET packages -->
<ItemGroup Condition="'$(TargetFramework)'=='net6.0' or '$(TargetFramework)'=='net7.0' or '$(TargetFramework)'=='net8.0'">
<!-- NOP -->
</ItemGroup>

<!-- Android packages -->
<ItemGroup Condition="'$(TargetFramework)'=='net8.0-android'">
<PackageReference Include="bblanchon.PDFium.Android" Version="130.0.6721" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.Android" Version="2.88.8" PrivateAssets="analyzers" />
</ItemGroup>

<!-- Blazor WebAssembly stuff -->
<ItemGroup Condition="'$(TargetFramework)'=='net7.0' or '$(TargetFramework)'=='net8.0'">
<PackageReference Include="SkiaSharp.NativeAssets.WebAssembly" Version="2.88.8" PrivateAssets="analyzers" />
<PackageReference Include="Sungaila.PDFium.BlazorWebAssembly" Version="131.0.6728" PrivateAssets="analyzers" />
</ItemGroup>

<Import Project="PDFtoImage.PropertiesSigning.targets" />
<Import Project="PDFtoImage.CodeSigning.targets" />
<Import Project="PDFtoImage.PackageSigning.targets" />
<?xml version="1.0" encoding="UTF-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<!-- Assembly -->
<PropertyGroup>
<TargetFrameworks>net462;net471;net481;net6.0;net7.0;net8.0;net8.0-android;netstandard2.0;net8.0-ios</TargetFrameworks>
<AssemblyName>PDFtoImage</AssemblyName>
<RootNamespace>PDFtoImage</RootNamespace>
<EmbedAllSources>true</EmbedAllSources>
<AssemblyOriginatorKeyFile>PDFtoImage.snk</AssemblyOriginatorKeyFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Configurations>Debug;Release;ReleaseSigned</Configurations>
<ProjectGuid>{A6F86FA0-87FE-406E-BA86-5A128D59DA12}</ProjectGuid>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>
</PropertyGroup>
<!-- NuGet -->
<PropertyGroup>
<VersionPrefix>4.1.3</VersionPrefix>
<VersionSuffix>
</VersionSuffix>
<Authors>David Sungaila</Authors>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>Icon_128.png</PackageIcon>
<PackageProjectUrl>https://github.com/sungaila/PDFtoImage</PackageProjectUrl>
<PackageIconUrl>https://raw.githubusercontent.com/sungaila/PDFtoImage/master/etc/Icon_128.png</PackageIconUrl>
<Description>A .NET library to render PDF files into images.</Description>
<PackageReleaseNotes>- Fixed DllNotFoundException for WebAssembly.</PackageReleaseNotes>
<PackageTags>PDF Bitmap Image Convert Conversion C# PDFium SkiaSharp Skia PNG JPG JPEG WEBP Xamarin Android MAUI wasm WebAssembly</PackageTags>
<RepositoryUrl>https://github.com/sungaila/PDFtoImage.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<!-- C# compiler -->
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<Features>strict</Features>
<WarningsAsErrors>nullable</WarningsAsErrors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<!-- Debug builds -->
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<VersionSuffix>debug</VersionSuffix>
</PropertyGroup>
<!-- Release builds -->
<PropertyGroup Condition="'$(Configuration)'=='Release' or '$(Configuration)'=='ReleaseSigned'">
<SignAssembly>true</SignAssembly>
<Optimize>true</Optimize>
<Deterministic>true</Deterministic>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
<!-- Roslyn analyzer for public APIs -->
<ItemGroup>
<AdditionalFiles Include="PublicAPI\$(TargetFramework)\PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI\$(TargetFramework)\PublicAPI.Unshipped.txt" />
</ItemGroup>
<!-- NuGet Icon -->
<ItemGroup>
<None Include="..\..\etc\Icon_128.png" Pack="true" PackagePath="" />
<None Include="..\..\README.md" Pack="true" PackagePath="" />
</ItemGroup>
<!-- SourceLink build steps and NuGet packages -->
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="2.88.8" PrivateAssets="analyzers" />
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" PrivateAssets="all" />
</ItemGroup>
<!-- Shared packages -->
<ItemGroup Condition="'$(TargetFramework)'!='net8.0-android' and '$(TargetFramework)'!='net8.0-ios' ">
<PackageReference Include="bblanchon.PDFium.Linux" Version="130.0.6721" PrivateAssets="analyzers" />
<PackageReference Include="bblanchon.PDFium.macOS" Version="130.0.6721" PrivateAssets="analyzers" />
<PackageReference Include="bblanchon.PDFium.Win32" Version="130.0.6721" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.macOS" Version="2.88.8" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.Win32" Version="2.88.8" PrivateAssets="analyzers" />
</ItemGroup>
<!-- .NET Framework packages -->
<ItemGroup Condition="'$(TargetFramework)'=='net462'">
<PackageReference Include="System.ValueTuple" Version="4.5.0" PrivateAssets="all" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" PrivateAssets="all" />
</ItemGroup>
<!-- .NET packages -->
<ItemGroup Condition="'$(TargetFramework)'=='net6.0' or '$(TargetFramework)'=='net7.0' or '$(TargetFramework)'=='net8.0'">
<!-- NOP -->
</ItemGroup>
<!-- Android packages -->
<ItemGroup Condition="'$(TargetFramework)'=='net8.0-android'">
<PackageReference Include="bblanchon.PDFium.Android" Version="130.0.6721" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.Android" Version="2.88.8" PrivateAssets="analyzers" />
</ItemGroup>
<!-- iOS packages -->
<PropertyGroup Condition="'$(TargetFramework)'=='net8.0-ios'">
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net8.0-ios'">
<PackageReference Include="bblanchon.PDFium.iOS" Version="130.0.6721" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.iOS" Version="2.88.8" PrivateAssets="analyzers" />
</ItemGroup>
<!-- Blazor WebAssembly stuff -->
<ItemGroup Condition="'$(TargetFramework)'=='net7.0' or '$(TargetFramework)'=='net8.0'">
<PackageReference Include="SkiaSharp.NativeAssets.WebAssembly" Version="2.88.8" PrivateAssets="analyzers" />
<PackageReference Include="Sungaila.PDFium.BlazorWebAssembly" Version="131.0.6728" PrivateAssets="analyzers" />
</ItemGroup>
<Import Project="PDFtoImage.PropertiesSigning.targets" />
<Import Project="PDFtoImage.CodeSigning.targets" />
<Import Project="PDFtoImage.PackageSigning.targets" />
</Project>
Loading

0 comments on commit 5d04c5a

Please sign in to comment.