Skip to content

Commit

Permalink
Update PDFium binaries to version 4955 and add support for UTF-8 char…
Browse files Browse the repository at this point in the history
…acters in document filenames. (#62)

See original PDFium commit here https://pdfium.googlesource.com/pdfium/+/98e0feb735a547c51f31b1da6aa9004542ef728c

Co-authored-by: Dmitry Zhelnin <[email protected]>
  • Loading branch information
DmitryZhelnin and Dmitry Zhelnin authored Apr 24, 2022
1 parent 9093dab commit 476cc6b
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

**docnet** aims to be a fast PDF editing and data extraction library. It is a `.NET Standard 2.0` wrapper for `PDFium C++` library that is used by `chromium`.

PDFium version: `4722`
PDFium version: `4955`

Supported platforms:

Expand Down
36 changes: 27 additions & 9 deletions src/Docnet.Core/Bindings/PdfiumWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Collections.Concurrent;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;

namespace Docnet.Core.Bindings
{
Expand Down Expand Up @@ -1745,7 +1746,7 @@ public partial struct __Internal
[DllImport("pdfium", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "FPDF_LoadDocument")]
internal static extern IntPtr FPDF_LoadDocument(
[MarshalAs(UnmanagedType.LPStr)] string file_path, [MarshalAs(UnmanagedType.LPStr)] string password);
IntPtr file_path, [MarshalAs(UnmanagedType.LPStr)] string password);

[SuppressUnmanagedCodeSecurity]
[DllImport("pdfium", CallingConvention = CallingConvention.Cdecl,
Expand Down Expand Up @@ -1975,16 +1976,33 @@ public static int FPDF_SetPrintMode(int mode)
return __ret;
}

private static IntPtr NativeUtf8FromString(string managedString) {
int len = Encoding.UTF8.GetByteCount(managedString);
byte[] buffer = new byte[len + 1];
Encoding.UTF8.GetBytes(managedString, 0, managedString.Length, buffer, 0);
IntPtr nativeUtf8 = Marshal.AllocHGlobal(buffer.Length);
Marshal.Copy(buffer, 0, nativeUtf8, buffer.Length);
return nativeUtf8;
}

public static FpdfDocumentT FPDF_LoadDocument(string file_path, string password)
{
var __ret = __Internal.FPDF_LoadDocument(file_path, password);
FpdfDocumentT __result0;
if (__ret == IntPtr.Zero) __result0 = null;
else if (FpdfDocumentT.NativeToManagedMap.ContainsKey(__ret))
__result0 = (FpdfDocumentT)FpdfDocumentT
.NativeToManagedMap[__ret];
else __result0 = FpdfDocumentT.__CreateInstance(__ret);
return __result0;
var ptr = NativeUtf8FromString(file_path);
try
{
var __ret = __Internal.FPDF_LoadDocument(ptr, password);
FpdfDocumentT __result0;
if (__ret == IntPtr.Zero) __result0 = null;
else if (FpdfDocumentT.NativeToManagedMap.ContainsKey(__ret))
__result0 = (FpdfDocumentT)FpdfDocumentT
.NativeToManagedMap[__ret];
else __result0 = FpdfDocumentT.__CreateInstance(__ret);
return __result0;
}
finally
{
Marshal.FreeHGlobal(ptr);
}
}

public static FpdfDocumentT FPDF_LoadMemDocument(IntPtr data_buf,
Expand Down
Binary file modified src/Docnet.Core/runtimes/linux-arm/native/pdfium.so
Binary file not shown.
Binary file modified src/Docnet.Core/runtimes/linux-arm64/native/pdfium.so
Binary file not shown.
Binary file modified src/Docnet.Core/runtimes/linux/native/pdfium.so
Binary file not shown.
Binary file modified src/Docnet.Core/runtimes/osx/native/pdfium.dylib
Binary file not shown.
Binary file modified src/Docnet.Core/runtimes/win-x64/native/pdfium.dll
Binary file not shown.
Binary file modified src/Docnet.Core/runtimes/win-x86/native/pdfium.dll
Binary file not shown.
1 change: 1 addition & 0 deletions src/Docnet.Tests.Integration/DocReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void GetDocReader_WhenCalledWithInvalidDimensions_ShouldThrow(Input type,
[InlineData(Input.FromBytes, "Docs/simple_3.pdf", null, 2)]
[InlineData(Input.FromFile, "Docs/protected_0.pdf", "password", 3)]
[InlineData(Input.FromBytes, "Docs/protected_0.pdf", "password", 3)]
[InlineData(Input.FromFile, "Docs/fancy_doc_∮.pdf", null, 2)]
public void GetPageCount_WhenCalled_ShouldReturnCorrectResults(Input type, string filePath, string password, int expectedCount)
{
using (var reader = _fixture.GetDocReader(type, filePath, password, 10, 10))
Expand Down
Binary file not shown.
16 changes: 8 additions & 8 deletions tools/get_pdfium.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash

wget https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F4722/pdfium-linux-x64.tgz
wget https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F4722/pdfium-linux-arm.tgz
wget https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F4722/pdfium-linux-arm64.tgz
wget https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F4722/pdfium-win-x64.tgz
wget https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F4722/pdfium-win-x86.tgz
wget https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F4722/pdfium-mac-x64.tgz
wget https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F4955/pdfium-linux-x64.tgz
wget https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F4955/pdfium-linux-arm.tgz
wget https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F4955/pdfium-linux-arm64.tgz
wget https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F4955/pdfium-win-x64.tgz
wget https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F4955/pdfium-win-x86.tgz
wget https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F4955/pdfium-mac-x64.tgz

mkdir linux
mkdir linux-arm
Expand Down Expand Up @@ -40,10 +40,10 @@ cp linux-arm64/LICENSE ../src/Docnet.Core/runtimes/linux-arm64/native/LICENSE
cp osx/lib/libpdfium.dylib ../src/Docnet.Core/runtimes/osx/native/pdfium.dylib
cp osx/LICENSE ../src/Docnet.Core/runtimes/osx/native/LICENSE

cp windows/x64/bin/pdfium.dll ../src/Docnet.Core/runtimes/win-x64/native/pdfium.dll
cp windows/bin/pdfium.dll ../src/Docnet.Core/runtimes/win-x64/native/pdfium.dll
cp windows/LICENSE ../src/Docnet.Core/runtimes/win-x64/native/LICENSE

cp windowsx86/x86/bin/pdfium.dll ../src/Docnet.Core/runtimes/win-x86/native/pdfium.dll
cp windowsx86/bin/pdfium.dll ../src/Docnet.Core/runtimes/win-x86/native/pdfium.dll
cp windowsx86/LICENSE ../src/Docnet.Core/runtimes/win-x86/native/LICENSE

rm pdfium-linux-x64.tgz pdfium-linux-arm.tgz pdfium-linux-arm64.tgz pdfium-win-x64.tgz pdfium-win-x86.tgz pdfium-mac-x64.tgz
Expand Down

0 comments on commit 476cc6b

Please sign in to comment.