Skip to content

Commit

Permalink
Update NuGet packages and remove workaround (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungaila authored Oct 25, 2024
1 parent 1409472 commit c059474
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 72 deletions.
3 changes: 1 addition & 2 deletions src/FrameworkTests/MauiApp/Platforms/iOS/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ObjCRuntime;
using UIKit;
using UIKit;

namespace PDFtoImage.FrameworkTests.MauiApp
{
Expand Down
6 changes: 2 additions & 4 deletions src/PDFtoImage/Conversion.Base64.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using PDFtoImage.Internals;
using SkiaSharp;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;

#if NET6_0_OR_GREATER
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
Expand Down Expand Up @@ -296,7 +294,7 @@ internal static void SaveImpl(Stream imageStream, SKEncodedImageFormat format, s
throw new ArgumentNullException(nameof(imageStream));

using var bitmap = ToImage(pdfAsBase64String, page, password, options);
bitmap.EncodeExt(imageStream, format, 100);
bitmap.Encode(imageStream, format, 100);
}
#endif
}
Expand Down
5 changes: 2 additions & 3 deletions src/PDFtoImage/Conversion.ByteArray.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using PDFtoImage.Internals;
using SkiaSharp;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Drawing;
Expand Down Expand Up @@ -326,7 +325,7 @@ internal static void SaveImpl(Stream imageStream, SKEncodedImageFormat format, b
throw new ArgumentNullException(nameof(imageStream));

using var bitmap = ToImage(pdfAsByteArray, page, password, options);
bitmap.EncodeExt(imageStream, format, 100);
bitmap.Encode(imageStream, format, 100);
}
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions src/PDFtoImage/Conversion.Deprecated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ internal static void SaveImpl(string filename, SKEncodedImageFormat format, Stre
internal static void SaveImpl(Stream stream, SKEncodedImageFormat format, Stream pdfStream, bool leaveOpen = false, string? password = null, int page = 0, RenderOptions options = default)
{
using var bitmap = ToImage(pdfStream, leaveOpen, password, page, options);
bitmap.EncodeExt(stream, format, 100);
bitmap.Encode(stream, format, 100);
}

#if NET6_0_OR_GREATER
Expand All @@ -481,7 +481,7 @@ internal static void SaveImpl(Stream imageStream, SKEncodedImageFormat format, b
throw new ArgumentNullException(nameof(imageStream));

using var bitmap = ToImage(pdfAsByteArray, password, page, options);
bitmap.EncodeExt(imageStream, format, 100);
bitmap.Encode(imageStream, format, 100);
}

#if NET6_0_OR_GREATER
Expand All @@ -505,7 +505,7 @@ internal static void SaveImpl(Stream imageStream, SKEncodedImageFormat format, s
throw new ArgumentNullException(nameof(imageStream));

using var bitmap = ToImage(pdfAsBase64String, password, page, options);
bitmap.EncodeExt(imageStream, format, 100);
bitmap.Encode(imageStream, format, 100);
}
}
}
2 changes: 1 addition & 1 deletion src/PDFtoImage/Conversion.Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ internal static void SaveImpl(string filename, SKEncodedImageFormat format, Stre
internal static void SaveImpl(Stream stream, SKEncodedImageFormat format, Stream pdfStream, Index page, bool leaveOpen = false, string? password = null, RenderOptions options = default)
{
using var bitmap = ToImage(pdfStream, page, leaveOpen, password, options);
bitmap.EncodeExt(stream, format, 100);
bitmap.Encode(stream, format, 100);
}
#endif
}
Expand Down
28 changes: 0 additions & 28 deletions src/PDFtoImage/Internals/SKBitmapExtensions.cs

This file was deleted.

14 changes: 7 additions & 7 deletions src/PDFtoImage/PDFtoImage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

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

Expand All @@ -83,9 +83,9 @@
<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="3.0.0-preview.4.1" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.macOS" Version="3.0.0-preview.4.1" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.Win32" Version="3.0.0-preview.4.1" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.0.0-preview.5.4" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.macOS" Version="3.0.0-preview.5.4" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.Win32" Version="3.0.0-preview.5.4" PrivateAssets="analyzers" />
</ItemGroup>

<!-- .NET Framework packages -->
Expand All @@ -102,18 +102,18 @@
<!-- Android packages -->
<ItemGroup Condition="'$(TargetFramework)'=='net8.0-android' or '$(TargetFramework)'=='net9.0-android'">
<PackageReference Include="bblanchon.PDFium.Android" Version="130.0.6721" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.Android" Version="3.0.0-preview.4.1" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.Android" Version="3.0.0-preview.5.4" PrivateAssets="analyzers" />
</ItemGroup>

<!-- iOS packages -->
<ItemGroup Condition="'$(TargetFramework)'=='net8.0-ios' or '$(TargetFramework)'=='net9.0-ios'">
<PackageReference Include="bblanchon.PDFium.iOS" Version="130.0.6721" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.iOS" Version="3.0.0-preview.4.1" PrivateAssets="analyzers" />
<PackageReference Include="SkiaSharp.NativeAssets.iOS" Version="3.0.0-preview.5.4" PrivateAssets="analyzers" />
</ItemGroup>

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

Expand Down
11 changes: 5 additions & 6 deletions src/Tests/AspectRatioTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PDFtoImage.Internals;
using PDFtoImage.Tests;
using System.IO;
using static PDFtoImage.Conversion;
Expand Down Expand Up @@ -353,7 +352,7 @@ public void IgnoreDpi(string fileName, int? width = null, int? height = null, bo
{
using var outputStream = CreateOutputStream(expectedPath);

ToImage(inputStream, true, options: new(Dpi: i, Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: withAspectRatio)).EncodeExt(outputStream, SkiaSharp.SKEncodedImageFormat.Jpeg, 100);
ToImage(inputStream, true, options: new(Dpi: i, Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: withAspectRatio)).Encode(outputStream, SkiaSharp.SKEncodedImageFormat.Jpeg, 100);
CompareStreams(expectedPath, outputStream);
}
}
Expand All @@ -376,8 +375,8 @@ public void IgnoreAspectRatio(string fileName, int width, int height)
using var outputStream1 = CreateOutputStream(expectedPath);
using var outputStream2 = CreateOutputStream(expectedPath);

ToImage(inputStream, true, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: false)).EncodeExt(outputStream1, SkiaSharp.SKEncodedImageFormat.Jpeg, 100);
ToImage(inputStream, true, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: true)).EncodeExt(outputStream2, SkiaSharp.SKEncodedImageFormat.Jpeg, 100);
ToImage(inputStream, true, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: false)).Encode(outputStream1, SkiaSharp.SKEncodedImageFormat.Jpeg, 100);
ToImage(inputStream, true, options: new(Width: width, Height: height, WithAnnotations: true, WithFormFill: true, WithAspectRatio: true)).Encode(outputStream2, SkiaSharp.SKEncodedImageFormat.Jpeg, 100);

CompareStreams(expectedPath, outputStream1);
CompareStreams(expectedPath, outputStream2);
Expand All @@ -401,8 +400,8 @@ public void IgnoreAspectRatioWithDpi(string fileName, int dpi)
using var outputStream1 = CreateOutputStream(expectedPath);
using var outputStream2 = CreateOutputStream(expectedPath);

ToImage(inputStream, true, options: new(Dpi: dpi, WithAnnotations: true, WithFormFill: true, WithAspectRatio: false)).EncodeExt(outputStream1, SkiaSharp.SKEncodedImageFormat.Jpeg, 100);
ToImage(inputStream, true, options: new(Dpi: dpi, WithAnnotations: true, WithFormFill: true, WithAspectRatio: true)).EncodeExt(outputStream2, SkiaSharp.SKEncodedImageFormat.Jpeg, 100);
ToImage(inputStream, true, options: new(Dpi: dpi, WithAnnotations: true, WithFormFill: true, WithAspectRatio: false)).Encode(outputStream1, SkiaSharp.SKEncodedImageFormat.Jpeg, 100);
ToImage(inputStream, true, options: new(Dpi: dpi, WithAnnotations: true, WithFormFill: true, WithAspectRatio: true)).Encode(outputStream2, SkiaSharp.SKEncodedImageFormat.Jpeg, 100);

CompareStreams(expectedPath, outputStream1);
CompareStreams(expectedPath, outputStream2);
Expand Down
17 changes: 8 additions & 9 deletions src/Tests/BatchingTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PDFtoImage.Internals;
using PDFtoImage.Tests;
using SkiaSharp;
using System;
Expand Down Expand Up @@ -63,7 +62,7 @@ public void ToImagesWithSelectionOdd()
{
var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{selection[i]}.png");
using var outputStream = CreateOutputStream(expectedPath);
bitmap.EncodeExt(outputStream, SKEncodedImageFormat.Png, 100);
bitmap.Encode(outputStream, SKEncodedImageFormat.Png, 100);

CompareStreams(expectedPath, outputStream);
i++;
Expand Down Expand Up @@ -151,7 +150,7 @@ public void ToImagesWithRangeAll()
{
var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{i}.png");
using var outputStream = CreateOutputStream(expectedPath);
bitmap.EncodeExt(outputStream, SKEncodedImageFormat.Png, 100);
bitmap.Encode(outputStream, SKEncodedImageFormat.Png, 100);

CompareStreams(expectedPath, outputStream);
i++;
Expand All @@ -171,7 +170,7 @@ public void ToImagesWithRangeSecondHalf()
{
var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{i}.png");
using var outputStream = CreateOutputStream(expectedPath);
bitmap.EncodeExt(outputStream, SKEncodedImageFormat.Png, 100);
bitmap.Encode(outputStream, SKEncodedImageFormat.Png, 100);

CompareStreams(expectedPath, outputStream);
i++;
Expand All @@ -191,7 +190,7 @@ public void ToImagesWithSelectionEven()
{
var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{selection[i]}.png");
using var outputStream = CreateOutputStream(expectedPath);
bitmap.EncodeExt(outputStream, SKEncodedImageFormat.Png, 100);
bitmap.Encode(outputStream, SKEncodedImageFormat.Png, 100);

CompareStreams(expectedPath, outputStream);
i++;
Expand All @@ -211,7 +210,7 @@ public async Task ToImagesWithRangeAllAsync()
{
var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{i}.png");
using var outputStream = CreateOutputStream(expectedPath);
bitmap.EncodeExt(outputStream, SKEncodedImageFormat.Png, 100);
bitmap.Encode(outputStream, SKEncodedImageFormat.Png, 100);

CompareStreams(expectedPath, outputStream);
i++;
Expand All @@ -231,7 +230,7 @@ public async Task ToImagesWithRangeSecondHalfAsync()
{
var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{i}.png");
using var outputStream = CreateOutputStream(expectedPath);
bitmap.EncodeExt(outputStream, SKEncodedImageFormat.Png, 100);
bitmap.Encode(outputStream, SKEncodedImageFormat.Png, 100);

CompareStreams(expectedPath, outputStream);
i++;
Expand All @@ -251,7 +250,7 @@ public async Task ToImagesWithSelectionEvenAsync()
{
var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{selection[i]}.png");
using var outputStream = CreateOutputStream(expectedPath);
bitmap.EncodeExt(outputStream, SKEncodedImageFormat.Png, 100);
bitmap.Encode(outputStream, SKEncodedImageFormat.Png, 100);

CompareStreams(expectedPath, outputStream);
i++;
Expand All @@ -271,7 +270,7 @@ public async Task ToImagesWithSelectionOddAsync()
{
var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{selection[i]}.png");
using var outputStream = CreateOutputStream(expectedPath);
bitmap.EncodeExt(outputStream, SKEncodedImageFormat.Png, 100);
bitmap.Encode(outputStream, SKEncodedImageFormat.Png, 100);

CompareStreams(expectedPath, outputStream);
i++;
Expand Down
13 changes: 6 additions & 7 deletions src/Tests/ComparisonTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PDFtoImage.Internals;
using PDFtoImage.Tests;
using SkiaSharp;
using System;
Expand Down Expand Up @@ -83,7 +82,7 @@ public void SaveWebpPages(bool withAnnotations = false)
var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.webp");

using var outputStream = CreateOutputStream(expectedPath);
image.EncodeExt(outputStream, SKEncodedImageFormat.Webp, 100);
image.Encode(outputStream, SKEncodedImageFormat.Webp, 100);

CompareStreams(expectedPath, outputStream);

Expand All @@ -106,7 +105,7 @@ public async Task SaveWebpPagesAsync(bool withAnnotations = false)
var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.webp");

using var outputStream = CreateOutputStream(expectedPath);
image.EncodeExt(outputStream, SKEncodedImageFormat.Webp, 100);
image.Encode(outputStream, SKEncodedImageFormat.Webp, 100);

CompareStreams(expectedPath, outputStream);

Expand Down Expand Up @@ -182,7 +181,7 @@ public void SavePngPages(bool withAnnotations = false)
var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.png");

using var outputStream = CreateOutputStream(expectedPath);
image.EncodeExt(outputStream, SKEncodedImageFormat.Png, 100);
image.Encode(outputStream, SKEncodedImageFormat.Png, 100);

CompareStreams(expectedPath, outputStream);

Expand All @@ -205,7 +204,7 @@ public async Task SavePngPagesAsync(bool withAnnotations = false)
var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.png");

using var outputStream = CreateOutputStream(expectedPath);
image.EncodeExt(outputStream, SKEncodedImageFormat.Png, 100);
image.Encode(outputStream, SKEncodedImageFormat.Png, 100);

CompareStreams(expectedPath, outputStream);

Expand Down Expand Up @@ -281,7 +280,7 @@ public void SaveJpegPages(bool withAnnotations = false)
var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.jpg");

using var outputStream = CreateOutputStream(expectedPath);
image.EncodeExt(outputStream, SKEncodedImageFormat.Jpeg, 100);
image.Encode(outputStream, SKEncodedImageFormat.Jpeg, 100);

CompareStreams(expectedPath, outputStream);

Expand All @@ -304,7 +303,7 @@ public async Task SaveJpegPagesAsync(bool withAnnotations = false)
var expectedPath = Path.Combine("..", "Assets", "Expected", GetPlatformAsString(), $"Wikimedia_Commons_web_{page}{(withAnnotations ? "_ANNOT" : string.Empty)}.jpg");

using var outputStream = CreateOutputStream(expectedPath);
image.EncodeExt(outputStream, SKEncodedImageFormat.Jpeg, 100);
image.Encode(outputStream, SKEncodedImageFormat.Jpeg, 100);

CompareStreams(expectedPath, outputStream);

Expand Down
3 changes: 1 addition & 2 deletions src/WebConverter/Pages/Index.razor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.Extensions.Logging;
using Microsoft.JSInterop;
using PDFtoImage.Internals;
using PDFtoImage.WebConverter.Models;
using SkiaSharp;
using System;
Expand Down Expand Up @@ -183,7 +182,7 @@ await Task.Factory.StartNew(() =>
DpiRelativeToBounds: Model.DpiRelativeToBounds
)
);
encodeSuccess = bitmap!.EncodeExt(Model.Output, Model.Format, Model.Quality);
encodeSuccess = bitmap!.Encode(Model.Output, Model.Format, Model.Quality);
}, TaskCreationOptions.LongRunning);

if (!encodeSuccess)
Expand Down

0 comments on commit c059474

Please sign in to comment.