Skip to content

cosmez/Qpdf.Native

Repository files navigation

Qpdf.Native

Low-level P/Invoke bindings for the QPDF library - a content-preserving PDF transformation library.

Features

  • 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

Installation

dotnet add package Qpdf.Native

Quick Start

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

Samples

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.pdf

See samples/Qpdf.Native.Samples/README.md for details.

API Structure

  • QpdfCoreInterop - Main QPDF functions (~125 functions)
  • QpdfJobInterop - Command-line like batch operations
  • QpdfLoggerInterop - Logging configuration

Native Libraries

This package includes pre-built native libraries (MSVC builds for Windows):

  • Windows x64: qpdf30.dll and MSVC runtime dependencies
  • Windows x86: qpdf30.dll and MSVC runtime dependencies
  • Linux x64: libqpdf.so.30 and dependencies

License

Apache-2.0 (same as QPDF)

Links

About

Low-level P/Invoke bindings for QPDF library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors