Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify and improve pdfium native lib loading #47

Merged
merged 10 commits into from
Oct 12, 2023
Merged
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
22 changes: 16 additions & 6 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ jobs:
dotnet-version: 7.x
- name: Setup .NET workload android
run: dotnet workload install android
- name: Setup .NET workload maui-android
run: dotnet workload install maui-android
- name: Setup .NET workload ios
run: dotnet workload install ios
- name: Setup .NET workload maui-ios
run: dotnet workload install maui-ios
- name: Setup .NET workload maccatalyst
run: dotnet workload install maccatalyst
- name: Setup .NET workload maui-maccatalyst
run: dotnet workload install maui-maccatalyst
- name: Setup .NET workload maui-windows
run: dotnet workload install maui-windows
- name: Setup .NET workload wasm-tools
run: dotnet workload install wasm-tools
- name: Setup JDK 17
Expand All @@ -80,7 +92,7 @@ jobs:
java-package: jdk
distribution: 'zulu'
- name: Restore
run: dotnet restore src/PDFtoImage.sln
run: msbuild src/PDFtoImage.sln /t:restore
- name: Build
run: msbuild src/PDFtoImage.sln /p:Configuration=${{ github.event_name != 'workflow_dispatch' && 'Debug' || inputs.build_configuration }} /p:VersionSuffix=ci /p:RestorePackages=false
- name: Pack
Expand Down Expand Up @@ -214,8 +226,6 @@ jobs:
run: dotnet tool install --global dotnet-coverage
- name: Setup .NET workload android
run: dotnet workload install android
- name: Setup .NET workload wasm-tools
run: dotnet workload install wasm-tools
- name: Setup JDK 17
uses: actions/setup-java@main
with:
Expand Down Expand Up @@ -248,7 +258,7 @@ jobs:
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"sungaila_PDFtoImage" /o:"sungaila" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
dotnet restore src/PDFtoImage.sln
msbuild src/PDFtoImage.sln /p:Configuration=${{ github.event_name != 'workflow_dispatch' && 'Debug' || inputs.build_configuration }}
dotnet-coverage collect "dotnet test src/PDFtoImage.sln --verbosity detailed" -f xml -o "coverage.xml"
dotnet restore src/PDFtoImage.SonarCloud.slnf
msbuild src/PDFtoImage.SonarCloud.slnf /p:Configuration=${{ github.event_name != 'workflow_dispatch' && 'Debug' || inputs.build_configuration }}
dotnet-coverage collect "dotnet test src/PDFtoImage.SonarCloud.slnf --verbosity detailed" -f xml -o "coverage.xml"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
2 changes: 0 additions & 2 deletions .github/workflows/githubpages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ jobs:
uses: actions/setup-dotnet@main
with:
dotnet-version: 7.x
- name: Setup .NET workload android
run: dotnet workload install android
- name: Setup .NET workload wasm-tools
run: dotnet workload install wasm-tools
- name: Update relative paths
Expand Down
35 changes: 34 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,37 @@ FodyWeavers.xsd
*.msp

# JetBrains Rider
*.sln.iml
*.sln.iml

# Xamarin
*.userprefs
*.user
bin
Configuration.Override.props
Configuration.OperatingSystem.props
obj
packages
.DS_Store
.nuget
*.nupkg
TestResult.xml
TestResult-*.xml
TestResult-*.csv
.vs/
.vscode/
.gradle/
Resource.designer.cs
logcat-*.txt
apk-sizes-*.txt
*.rawproto
*.binlog
*.ProjectImports.zip
*~
external/monodroid/
external/mono/
tests/api-compatibility/reference/*/*.dll
tests/api-compatibility/reference/*/*.cs
Novell
*.patch
*.keystore
/omnisharp.json
2 changes: 1 addition & 1 deletion src/Console/Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<AssemblyName>PDFtoImage.Console</AssemblyName>
<RootNamespace>PDFtoImage.Console</RootNamespace>
<StartupObject>PDFtoImage.Console.Program</StartupObject>
<Version>2.4.2</Version>
<Version>2.5.0</Version>
<Configurations>Debug;Release;ReleaseSigned</Configurations>
</PropertyGroup>

Expand Down
25 changes: 25 additions & 0 deletions src/FrameworkTests/AspNetCore/AspNetCore.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>PDFtoImage.FrameworkTests.AspNetCore</AssemblyName>
<RootNamespace>PDFtoImage.FrameworkTests.AspNetCore</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\PDFtoImage\PDFtoImage.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<Content Update="wwwroot\SocialPreview.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
35 changes: 35 additions & 0 deletions src/FrameworkTests/AspNetCore/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace PDFtoImage.FrameworkTests.AspNetCore
{
public class Program
{
private static IWebHostEnvironment? _hostingEnvironment;

public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

_hostingEnvironment = app.Services.GetService<IWebHostEnvironment>();

app.MapGet("/", GetOutput);

app.Run();
}

private static string GetOutput()
{
try
{
using var input = new FileStream(Path.Combine(_hostingEnvironment!.WebRootPath, "SocialPreview.pdf"), FileMode.Open, FileAccess.Read);

using var bitmap = PDFtoImage.Conversion.ToImage(input);

Check warning on line 25 in src/FrameworkTests/AspNetCore/Program.cs

View workflow job for this annotation

GitHub Actions / Build

This call site is reachable on all platforms. 'Conversion.ToImage(Stream, string?, int, int, int?, int?, bool, bool, bool, PdfRotation)' is only supported on: 'Android' 31.0 and later, 'Linux', 'macOS/OSX', 'Windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

return $"SocialPreview.pdf size: {bitmap.Width}x{bitmap.Height}";
}
catch (Exception ex)
{
return ex.ToString();
}
}
}
}
37 changes: 37 additions & 0 deletions src/FrameworkTests/AspNetCore/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:23307",
"sslPort": 44323
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5005",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7074;http://localhost:5005",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
8 changes: 8 additions & 0 deletions src/FrameworkTests/AspNetCore/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions src/FrameworkTests/AspNetCore/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Binary file not shown.
15 changes: 15 additions & 0 deletions src/FrameworkTests/MauiApp/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Application
x:Class="PDFtoImage.FrameworkTests.MauiApp.App"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
12 changes: 12 additions & 0 deletions src/FrameworkTests/MauiApp/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace PDFtoImage.FrameworkTests.MauiApp
{
public partial class App : Application
{
public App()
{
InitializeComponent();

MainPage = new AppShell();
}
}
}
14 changes: 14 additions & 0 deletions src/FrameworkTests/MauiApp/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="PDFtoImage.FrameworkTests.MauiApp.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:PDFtoImage.FrameworkTests.MauiApp"
Shell.FlyoutBehavior="Disabled">

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

</Shell>
10 changes: 10 additions & 0 deletions src/FrameworkTests/MauiApp/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace PDFtoImage.FrameworkTests.MauiApp
{
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
}
37 changes: 37 additions & 0 deletions src/FrameworkTests/MauiApp/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="PDFtoImage.FrameworkTests.MauiApp.MainPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

<ScrollView>
<VerticalStackLayout Padding="30,0"
Spacing="25"
VerticalOptions="Center">

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

<Label FontSize="32"
HorizontalOptions="Center"
SemanticProperties.HeadingLevel="Level1"
Text="Hello, World!" />

<Label x:Name="OutputLabel"
FontSize="18"
HorizontalOptions="Center"
SemanticProperties.Description="Welcome to dot net Multi platform App U I"
SemanticProperties.HeadingLevel="Level2"
Text="Tab the button below to test PDFtoImage." />

<Button x:Name="CounterBtn"
Clicked="OnCounterClicked"
HorizontalOptions="Center"
SemanticProperties.Hint="Counts the number of times you click"
Text="Click me" />

</VerticalStackLayout>
</ScrollView>

</ContentPage>
28 changes: 28 additions & 0 deletions src/FrameworkTests/MauiApp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace PDFtoImage.FrameworkTests.MauiApp
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}

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);

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

Check warning on line 18 in src/FrameworkTests/MauiApp/MainPage.xaml.cs

View workflow job for this annotation

GitHub Actions / Build

This call site is reachable on: 'iOS' 11.0 and later, 'maccatalyst' 11.0 and later. 'Conversion.ToImage(Stream, string?, int, int, int?, int?, bool, bool, bool, PdfRotation)' is only supported on: 'Android' 31.0 and later, 'Linux', 'macOS/OSX', 'Windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 18 in src/FrameworkTests/MauiApp/MainPage.xaml.cs

View workflow job for this annotation

GitHub Actions / Build

This call site is reachable on: 'MacCatalyst' 13.1 and later. 'Conversion.ToImage(Stream, string?, int, int, int?, int?, bool, bool, bool, PdfRotation)' is only supported on: 'Android' 31.0 and later, 'Linux', 'macOS/OSX', 'Windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

OutputLabel.Text = $"SocialPreview.pdf size: {bitmap.Width}x{bitmap.Height}";
}
catch (Exception ex)
{
OutputLabel.Text = ex.ToString();
}
}
}
}
Loading