Skip to content
This repository was archived by the owner on Apr 22, 2026. It is now read-only.
Open
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
3 changes: 0 additions & 3 deletions src/PdfiumViewer.Demo/FodyWeavers.xml

This file was deleted.

64 changes: 0 additions & 64 deletions src/PdfiumViewer.Demo/FodyWeavers.xsd

This file was deleted.

7 changes: 3 additions & 4 deletions src/PdfiumViewer.Demo/PdfiumViewer.Demo.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<ApplicationIcon>icon.ico</ApplicationIcon>
<Version>1.0.5</Version>
Expand Down Expand Up @@ -47,8 +47,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
<PackageReference Include="PropertyChanged.Fody" Version="3.2.8" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions src/PdfiumViewer.Demo/Properties/Annotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ public sealed class ItemCanBeNullAttribute : Attribute { }
AttributeTargets.Property | AttributeTargets.Delegate)]
public sealed class StringFormatMethodAttribute : Attribute
{
/// <summary>
/// Set the format string of an annotated method.
/// </summary>
/// <param name="formatParameterName">
/// Specifies which parameter of an annotated method should be treated as the format string
/// </param>
Expand Down
29 changes: 20 additions & 9 deletions src/PdfiumViewer/Core/NativeMethods.Pdfium.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ partial class NativeMethods
// threads, even when there are multiple AppDomain's in play.
private static readonly string LockString = string.Intern("e362349b-001d-4cb2-bf55-a71606a3e36f");

public static void FPDF_AddRef()
public static void FPDF_InitLibrary()
{
lock (LockString)
{
Imports.FPDF_AddRef();
Imports.FPDF_InitLibrary();
}
}

public static void FPDF_Release()
public static void FPDF_DestroyLibrary()
{
lock (LockString)
{
Imports.FPDF_Release();
Imports.FPDF_DestroyLibrary();
}
}

Expand Down Expand Up @@ -589,11 +589,22 @@ private static int FPDF_SaveBlock(IntPtr fileWrite, IntPtr data, uint size)

private static class Imports
{
[DllImport("pdfium.dll")]
public static extern void FPDF_AddRef();

[DllImport("pdfium.dll")]
public static extern void FPDF_Release();
// LibraryImport is not supported by Blazor WebAssembly
#if NET7_0_OR_GREATER && FALSE
[LibraryImport("pdfium")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void FPDF_InitLibrary();

[LibraryImport("pdfium")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void FPDF_DestroyLibrary();
#else
[DllImport("pdfium", CallingConvention = CallingConvention.Cdecl)]
public static extern void FPDF_InitLibrary();

[DllImport("pdfium", CallingConvention = CallingConvention.Cdecl)]
public static extern void FPDF_DestroyLibrary();
#endif

[DllImport("pdfium.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr FPDF_LoadCustomDocument([MarshalAs(UnmanagedType.LPStruct)] FPDF_FILEACCESS access, string password);
Expand Down
12 changes: 8 additions & 4 deletions src/PdfiumViewer/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ private static bool TryLoadNativeLibrary(string path)
if (path == null)
return false;

path = Path.Combine(path, IntPtr.Size == 4 ? "x86" : "x64");
if(IntPtr.Size == 4)
{
path = Path.Combine(path, "runtimes", "win-x86","native");
}
else
{
path = Path.Combine(path, "runtimes", "win-x64", "native");
}
path = Path.Combine(path, "Pdfium.dll");

return File.Exists(path) && LoadLibrary(path) != IntPtr.Zero;
Expand Down Expand Up @@ -119,16 +126,13 @@ public enum FileMapAccess : uint
[DllImport("user32.dll")]
public static extern int ScrollWindowEx(IntPtr hWnd, int dx, int dy, IntPtr prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, uint flags);

[SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class MemoryMappedHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public MemoryMappedHandle()
: base(true)
{
}

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
protected override bool ReleaseHandle()
{
return CloseHandle(handle);
Expand Down
10 changes: 2 additions & 8 deletions src/PdfiumViewer/Core/PdfException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Runtime.Serialization;
using PdfiumViewer.Enums;
using PdfiumViewer.Enums;
using System;

#pragma warning disable 1591

Expand Down Expand Up @@ -50,10 +49,5 @@ public PdfException(string message, Exception innerException)
: base(message, innerException)
{
}

protected PdfException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
4 changes: 2 additions & 2 deletions src/PdfiumViewer/Core/PdfLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void EnsureLoaded()

private PdfLibrary()
{
NativeMethods.FPDF_AddRef();
NativeMethods.FPDF_InitLibrary();
}

~PdfLibrary()
Expand All @@ -39,7 +39,7 @@ private void Dispose(bool disposing)
{
if (!_disposed)
{
NativeMethods.FPDF_Release();
NativeMethods.FPDF_DestroyLibrary();

_disposed = true;
}
Expand Down
3 changes: 0 additions & 3 deletions src/PdfiumViewer/FodyWeavers.xml

This file was deleted.

64 changes: 0 additions & 64 deletions src/PdfiumViewer/FodyWeavers.xsd

This file was deleted.

12 changes: 6 additions & 6 deletions src/PdfiumViewer/PdfiumViewer.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0-windows</TargetFrameworks>
<TargetFrameworks>net8.0-windows</TargetFrameworks>
<UseWPF>true</UseWPF>
<Version>1.0.6</Version>
<Authors>Behzad Khosravifar</Authors>
Expand All @@ -18,13 +18,13 @@
<PackageReleaseNotes>.Net 5 Support</PackageReleaseNotes>
<AssemblyVersion>1.0.6.0</AssemblyVersion>
<FileVersion>1.0.6.0</FileVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PdfiumViewer.Native.x86.v8-xfa" Version="2018.4.8.256" />
<PackageReference Include="PdfiumViewer.Native.x86_64.v8-xfa" Version="2018.4.8.256" />
<PackageReference Include="PropertyChanged.Fody" Version="3.2.8" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
<PackageReference Include="bblanchon.PDFiumV8.Win32" Version="124.0.6350"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="System.Drawing.Common" Version="8.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/PdfiumViewer/ScrollPanel.PdfDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using CommunityToolkit.Mvvm.ComponentModel;
using PdfiumViewer.Core;
using PdfiumViewer.Drawing;
using PdfiumViewer.Enums;
Expand Down
Loading