Skip to content
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
1 change: 1 addition & 0 deletions Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Document doc = new();
Page page = doc.NewPage();

Expand Down
26 changes: 16 additions & 10 deletions MuPDF.NET/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.InteropServices;
using System.Text;
using mupdf;
using Newtonsoft.Json.Linq;

namespace MuPDF.NET
{
Expand Down Expand Up @@ -720,17 +721,21 @@ public void InitDocument()
Dictionary<string, string> values = new Dictionary<string, string>()
{
{ "format", "format" },
{ "title", "info:Title" },
{ "author", "info:Author" },
{ "subject", "info:Subject" },
{ "keywords", "info:Keywords" },
{ "creator", "info:Creator" },
{ "producer", "info:Producer" },
{ "creationDate", "info:CreationDate" },
{ "modDate", "info:ModDate" },
{ "trapped", "info:Trapped" }
};

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
values.Add("title", "info:Title");
values.Add("author", "info:Author");
values.Add("subject", "info:Subject");
values.Add("keywords", "info:Keywords");
values.Add("creator", "info:Creator");
values.Add("producer", "info:Producer");
values.Add("creationDate", "info:CreationDate");
values.Add("modDate", "info:ModDate");
values.Add("trapped", "info:Trapped");
}

foreach ((string key, string value) in values)
{
MetaData.Add(key, GetMetadata(value));
Expand Down Expand Up @@ -4029,7 +4034,8 @@ public void Select(List<int> list)
Marshal.Copy(list.ToArray(), 0, pNumbers, list.Count);
SWIGTYPE_p_int swigNumbers = new SWIGTYPE_p_int(pNumbers, true);

pdf.pdf_rearrange_pages(list.Count, swigNumbers);
pdf.pdf_rearrange_pages(list.Count, swigNumbers, pdf_clean_options_structure.PDF_CLEAN_STRUCTURE_DROP);

ResetPageRefs();
}

Expand Down
33 changes: 25 additions & 8 deletions MuPDF.NET/MuPDF.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net8.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);net7.0-tizen</TargetFrameworks> -->
<UseMaui>true</UseMaui>
<UseMaui>false</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>

Expand All @@ -16,7 +16,7 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>MuPDF.NET</Title>
<Version>3.0.0</Version>
<Version>3.1.2-rc.1</Version>
<Authors>Maksym Tkachuk, Jamie Lemon, Chris Palman</Authors>
<Company>Artifex</Company>
<Description>A C# binding for MuPDF</Description>
Expand All @@ -29,6 +29,10 @@
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
</PropertyGroup>

<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<DefineConstants>$(DefineConstants);WINDOWS</DefineConstants>
</PropertyGroup>

<ItemGroup>
<None Include="..\LICENSE.md">
<Pack>True</Pack>
Expand Down Expand Up @@ -56,15 +60,28 @@
<PackageReference Update="Microsoft.Maui.Controls.Compatibility" Version="8.0.14" />
</ItemGroup>

<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<EmbeddedResource Include="mupdfcsharp.dll">
<ItemGroup>
<EmbeddedResource Include="libs\mupdf\linux\libmupdf.so">
<LogicalName>libmupdf.so</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="libs\mupdf\linux\libmupdf.so.26.0">
<LogicalName>libmupdf.so.26.0</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="libs\mupdf\linux\libmupdfcpp.so">
<LogicalName>libmupdfcpp.so</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="libs\mupdf\linux\libmupdfcpp.so.26.0">
<LogicalName>libmupdfcpp.so.26.0</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="libs\mupdf\linux\mupdfcsharp.so">
<LogicalName>mupdfcsharp.so</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="libs\mupdf\windows\mupdfcsharp.dll">
<LogicalName>mupdfcsharp.dll</LogicalName>
</EmbeddedResource>
</ItemGroup>
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<EmbeddedResource Include="mupdfcpp64.dll">
<EmbeddedResource Include="libs\mupdf\windows\mupdfcpp64.dll">
<LogicalName>mupdfcpp64.dll</LogicalName>
</EmbeddedResource>
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion MuPDF.NET/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Maui;
using mupdf;
using static System.Net.Mime.MediaTypeNames;
using static MuPDF.NET.Global;
Expand Down
2 changes: 2 additions & 0 deletions MuPDF.NET/Platforms/Android/PlatformClass1.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace MuPDF.NET
{
#if ANDROID
// All the code in this file is only included on Android.
public class PlatformClass1
{
}
#endif
}
2 changes: 2 additions & 0 deletions MuPDF.NET/Platforms/MacCatalyst/PlatformClass1.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace MuPDF.NET
{
#if MACCATALYST
// All the code in this file is only included on Mac Catalyst.
public class PlatformClass1
{
}
#endif
}
2 changes: 2 additions & 0 deletions MuPDF.NET/Platforms/Tizen/PlatformClass1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace MuPDF.NET
{
#if TVOS
// All the code in this file is only included on Tizen.
public class PlatformClass1
{
}
#endif
}
2 changes: 2 additions & 0 deletions MuPDF.NET/Platforms/Windows/PlatformClass1.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace MuPDF.NET
{
#if WINDOWS
// All the code in this file is only included on Windows.
public class PlatformClass1
{
}
#endif
}
2 changes: 2 additions & 0 deletions MuPDF.NET/Platforms/iOS/PlatformClass1.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace MuPDF.NET
{
#if IOS
// All the code in this file is only included on iOS.
public class PlatformClass1
{
}
#endif
}
2 changes: 1 addition & 1 deletion MuPDF.NET/TextPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ internal void MakeTextPage2Dict(PageInfo pageDict, bool raw)
style.Font = GetFontName(
new FzFont(mupdf.mupdf.ll_fz_keep_font(ch.font))
);
style.Color = ch.color;
style.Color = (int)ch.argb;
style.Asc = (
new FzFont(mupdf.mupdf.ll_fz_keep_font(ch.font))
).fz_font_ascender();
Expand Down
128 changes: 107 additions & 21 deletions MuPDF.NET/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Maui.Storage;
using mupdf;
using Newtonsoft.Json;
using static MuPDF.NET.Global;
Expand Down Expand Up @@ -6792,22 +6791,99 @@ internal static string GetFontName(fz_font font)
return name.Substring(s + 1, name.Length - s - 1);
}

internal static void LoadEmbeddedDll()
internal static void LoadEmbeddedDllForWindows()
{
var assembly = Assembly.GetExecutingAssembly();
var resourceStream = assembly.GetManifestResourceStream("mupdfcpp64.dll");
var tempFile = File.Create("mupdfcpp64.dll");
string binaryDir = AppContext.BaseDirectory;
if (!File.Exists(binaryDir + "mupdfcpp64.dll"))
{
var assembly = Assembly.GetExecutingAssembly();
var resourceStream = assembly.GetManifestResourceStream("mupdfcpp64.dll");
var tempFile = File.Create(binaryDir + "mupdfcpp64.dll");

resourceStream?.CopyTo(tempFile);
resourceStream?.Dispose();
tempFile.Dispose();
resourceStream?.CopyTo(tempFile);
resourceStream?.Dispose();
tempFile.Dispose();
}

resourceStream = assembly.GetManifestResourceStream("mupdfcsharp.dll");
tempFile = File.Create("mupdfcsharp.dll");
if (!File.Exists(binaryDir + "mupdfcsharp.dll"))
{
var assembly = Assembly.GetExecutingAssembly();
var resourceStream = assembly.GetManifestResourceStream("mupdfcsharp.dll");
var tempFile = File.Create(binaryDir + "mupdfcsharp.dll");

resourceStream?.CopyTo(tempFile);
resourceStream?.Dispose();
tempFile.Dispose();
resourceStream?.CopyTo(tempFile);
resourceStream?.Dispose();
tempFile.Dispose();
}
}

internal static void LoadEmbeddedDllForLinux()
{
string binaryDir = AppContext.BaseDirectory;
if (!File.Exists(binaryDir + "libmupdf.so"))
{
var assembly = Assembly.GetExecutingAssembly();
var resourceStream = assembly.GetManifestResourceStream("libmupdf.so");
if (resourceStream != null)
{
var tempFile = File.Create(binaryDir + "libmupdf.so");
resourceStream.CopyTo(tempFile);
resourceStream.Dispose();
tempFile.Dispose();
}
}

if (!File.Exists(binaryDir + "libmupdf.so.26.0"))
{
var assembly = Assembly.GetExecutingAssembly();
var resourceStream = assembly.GetManifestResourceStream("libmupdf.so.26.0");
if (resourceStream != null)
{
var tempFile = File.Create(binaryDir + "libmupdf.so.26.0");
resourceStream.CopyTo(tempFile);
resourceStream.Dispose();
tempFile.Dispose();
}
}

if (!File.Exists(binaryDir + "libmupdfcpp.so"))
{
var assembly = Assembly.GetExecutingAssembly();
var resourceStream = assembly.GetManifestResourceStream("libmupdfcpp.so");
if (resourceStream != null)
{
var tempFile = File.Create(binaryDir + "libmupdfcpp.so");
resourceStream.CopyTo(tempFile);
resourceStream.Dispose();
tempFile.Dispose();
}
}

if (!File.Exists(binaryDir + "libmupdfcpp.so.26.0"))
{
var assembly = Assembly.GetExecutingAssembly();
var resourceStream = assembly.GetManifestResourceStream("libmupdfcpp.so.26.0");
if (resourceStream != null)
{
var tempFile = File.Create(binaryDir + "libmupdfcpp.so.26.0");
resourceStream.CopyTo(tempFile);
resourceStream.Dispose();
tempFile.Dispose();
}
}

if (!File.Exists(binaryDir + "mupdfcsharp.dll"))
{
var assembly = Assembly.GetExecutingAssembly();
var resourceStream = assembly.GetManifestResourceStream("mupdfcsharp.so");
if (resourceStream != null)
{
var tempFile = File.Create(binaryDir + "mupdfcsharp.dll");
resourceStream.CopyTo(tempFile);
resourceStream.Dispose();
tempFile.Dispose();
}
}
}

internal static void AddLayerConfig(
Expand Down Expand Up @@ -6869,16 +6945,26 @@ internal static void SetDotCultureForNumber()

public static void InitApp()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return;

if (Utils.IsInitialized)
return;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
if (Utils.IsInitialized)
return;

Utils.SetDotCultureForNumber();
if (!File.Exists("mupdfcsharp.dll"))
Utils.LoadEmbeddedDll();
Utils.SetDotCultureForNumber();
Utils.LoadEmbeddedDllForWindows();
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
if (Utils.IsInitialized)
return;

Utils.SetDotCultureForNumber();
Utils.LoadEmbeddedDllForLinux();
}
else
{
return;
}
Utils.IsInitialized = true;
}

Expand Down
1 change: 1 addition & 0 deletions MuPDF.NET/libs/mupdf/linux/libmupdf.so
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libmupdf.so.26.0
Binary file added MuPDF.NET/libs/mupdf/linux/libmupdf.so.26.0
Binary file not shown.
1 change: 1 addition & 0 deletions MuPDF.NET/libs/mupdf/linux/libmupdfcpp.so
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libmupdfcpp.so.26.0
Binary file added MuPDF.NET/libs/mupdf/linux/libmupdfcpp.so.26.0
Binary file not shown.
Binary file added MuPDF.NET/libs/mupdf/linux/mupdfcsharp.so
Binary file not shown.
Binary file added MuPDF.NET/libs/mupdf/windows/mupdfcpp64.dll
Binary file not shown.
Binary file added MuPDF.NET/libs/mupdf/windows/mupdfcsharp.dll
Binary file not shown.
Loading