Low-level P/Invoke bindings for the QPDF library - a content-preserving PDF transformation library.
- Complete C API bindings for QPDF 12.3.1
- SafeHandle wrappers for automatic native resource cleanup
- Cross-platform support (Windows x64, Windows x86, Linux x64)
- Native libraries included for easy deployment
dotnet add package Qpdf.Nativeusing System.Runtime.InteropServices;
using Qpdf.Native.Handles;
using Qpdf.Native.Interop;
// Get QPDF version
IntPtr versionPtr = QpdfCoreInterop.qpdf_get_qpdf_version();
string version = Marshal.PtrToStringUTF8(versionPtr);
Console.WriteLine($"QPDF Version: {version}");
// Create an empty PDF
IntPtr handlePtr = QpdfCoreInterop.qpdf_init();
try
{
using var handle = new QpdfDataHandle(handlePtr, ownsHandle: false);
QpdfCoreInterop.qpdf_empty_pdf(handle);
int pageCount = QpdfCoreInterop.qpdf_get_num_pages(handle);
Console.WriteLine($"Page count: {pageCount}");
}
finally
{
QpdfCoreInterop.qpdf_cleanup(ref handlePtr);
}Sample programs demonstrating the bindings are available in samples/Qpdf.Native.Samples/:
cd samples/Qpdf.Native.Samples
dotnet run -- pdf-c-objects input.pdf "" output.pdfSee samples/Qpdf.Native.Samples/README.md for details.
- QpdfCoreInterop - Main QPDF functions (~125 functions)
- QpdfJobInterop - Command-line like batch operations
- QpdfLoggerInterop - Logging configuration
This package includes pre-built native libraries (MSVC builds for Windows):
- Windows x64:
qpdf30.dlland MSVC runtime dependencies - Windows x86:
qpdf30.dlland MSVC runtime dependencies - Linux x64:
libqpdf.so.30and dependencies
Apache-2.0 (same as QPDF)