# sungaila/pdftoimage architecture

> Architecture diagram of the GitHub repository sungaila/pdftoimage, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sungaila/pdftoimage
- Repository: https://github.com/sungaila/pdftoimage

## Overview

##### Project type and purpose
- PDFtoImage is a cross-platform .NET library that renders PDF pages to images, built on native PDFium + SkiaSharp.
- It ships as a NuGet package and as a Unity package, and includes sample apps (FrameworkTests) and a Blazor WebConverter demo.

##### Decompose the file structure into high-level modules
- “Core Library” (src/PDFtoImage): public API, conversion entry points, options, code-signing and packaging targets.
- “Internals” (src/PDFtoImage/Internals): LibraryLoader, NativeMethods, PdfDocument/File/Library abstractions.
- “Platform-native binaries” (etc/UnityPackage/Plugins): PDFium & SkiaSharp .dll/.so/.dylib per platform.
- “PublicAPI” folder: shipped/unshipped surface for net462, net6.0, netstandard2.1, iOS, Android, etc.
- “Consumers & Samples”
- FrameworkTests (console, ASP.NET, ASP.NET Core, MAUI, Unity2D)
- WebConverter (Blazor-WASM client)
- “Tests” (src/Tests): unit + integration assets for Windows, Linux, macOS.
- CI/CD & Packaging (/.github/workflows, Dockerfiles in AotConsole, PDFtoImage.*.targets).

##### Sketch the layered architecture

[Presentation / Consumer Layer]
– FrameworkTests apps (AotConsole, ASP.NET, ASP.NET Core, MAUI, Unity2D)
– Blazor WebConverter UI

[Application / API Layer]
– PDFtoImage.Conversion static methods
– RenderOptions, PdfRotation, AntiAliasing, IRenderOptions

[Core Library Layer]
– Conversion.*.cs (SavePng, SaveJpeg, ToImage(s))
– Exception types

[Internal Abstraction Layer]
– LibraryLoader (decides which native lib to load)
– NativeMethods pinvoke bindings
– PdfLibrary / PdfDocument / StreamManager

[Native Engine Layer]
– PDFium (native renderer)
– SkiaSharp (drawing engine)

[Packaging & Delivery]
– NuGet packaging (.props/.targets, public API manifests)
– UnityPackage (etc/UnityPackage)
– Dockerfiles for AOT publish

[Test Harness]
– Unit tests (src/Tests)
– Platform-specific expected images and test PDFs

##### Relationships & data flows
- In sample apps, illustrate that each framework (MAUI, Unity, ASP.NET) references the same Conversion API.
- LibraryLoader selecting platform .dll via metadata from etc/UnityPackage/Plugins or native folder at runtime.

##### Architectural patterns & design principles
- Layered architecture (Presentation → API → Core → Internals → Native)
- Abstraction via interfaces (IRenderOptions) and P/Invoke wrappers.
- Multi-targeting/public API manifests to support many frameworks.
- Plugin-style native library loading.

##### Technologies & frameworks
– .NET 6/7/8, .NET Framework 4.6.2+
– PDFium (native)
– SkiaSharp (native)
– CI/CD: GitHub Actions (dotnet.yml), SonarCloud quality gate
– Container builds: Dockerfiles for AOT console
– Consumers: ASP.NET, ASP.NET Core, Blazor WASM, .NET MAUI, Unity, UWP, WinUI 3

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Consumers & Samples
    subgraph "Consumers & Samples" 
        direction TB
        AOT["AOT Console"]:::purple
        ASPNET["ASP.NET Framework"]:::purple
        ASPNETCORE["ASP.NET Core"]:::purple
        MAUI[".NET MAUI App"]:::purple
        UNITY["Unity2D Sample"]:::purple
        BLAZOR["Blazor WebConverter"]:::purple
    end

    %% Application / API Layer
    subgraph "Application / API Layer"
        direction TB
        Conversion["Conversion.cs / Base64 / ByteArray / Stream"]:::blue
        RenderOptions["RenderOptions.cs / PdfRotation.cs / PdfAntiAliasing.cs / IRenderOptions.cs"]:::blue
    end

    %% Core Library Layer
    subgraph "Core Library Layer"
        direction TB
        CoreProj["PDFtoImage.csproj"]:::blue
        PublicAPI["PublicAPI Manifests"]:::blue
        subgraph "Exception Types"
            direction TB
            Exceptions["PdfExceptions"]:::blue
        end
    end

    %% Internal Abstraction Layer
    subgraph "Internal Abstraction Layer"
        direction TB
        LibLoader["LibraryLoader.cs"]:::green
        NativeMethods["NativeMethods.cs"]:::green
        PdfAbstractions["PdfLibrary.cs / PdfDocument.cs / PdfFile.cs / StreamManager.cs"]:::green
    end

    %% Native Engine Layer
    subgraph "Native Engine Layer"
        direction TB
        PDFium["PDFium Binaries"]:::orange
        SkiaSharp["SkiaSharp Binaries"]:::orange
    end

    %% Packaging & Delivery
    subgraph "Packaging & Delivery"
        direction TB
        NuGet["NuGet Package (.props/.targets)"]:::grey
        UnityPkg["UnityPackage Plugins"]:::grey
        Docker["AOT Dockerfiles"]:::grey
        CI["GitHub Actions Workflows"]:::grey
    end

    %% Test Harness
    subgraph "Test Harness"
        direction TB
        Tests["Tests.csproj + Assets"]:::grey
    end

    %% Connections
    AOT -->|"calls"| Conversion
    ASPNET -->|"calls"| Conversion
    ASPNETCORE -->|"calls"| Conversion
    MAUI -->|"calls"| Conversion
    UNITY -->|"calls"| Conversion
    BLAZOR -->|"calls"| Conversion

    Conversion -->|uses| RenderOptions
    Conversion -->|calls| LibLoader
    Conversion -->|calls| PdfAbstractions
    LibLoader -->|"loads native dll"| PDFium
    NativeMethods -->|"PInvoke calls"| PDFium
    NativeMethods -->|"PInvoke calls"| SkiaSharp
    PdfAbstractions -->|invokes| NativeMethods
    Conversion -->|"returns SKBitmap / byte[] / stream"| AOT

    CoreProj -->|multi-targets| PublicAPI
    CoreProj -->|defines| Conversion
    CoreProj -->|defines| RenderOptions
    CoreProj -->|defines| Exceptions

    CoreProj -->|packages| NuGet
    CoreProj -->|packages| UnityPkg
    Docker -->|builds| AOT
    CI -->|build/test/publish| CoreProj
    CI -->|runs tests| Tests

    Tests -->|"uses assets"| PDFium

    %% Click Events
    click Conversion "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/Conversion.cs"
    click Conversion "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/Conversion.Base64.cs"
    click Conversion "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/Conversion.ByteArray.cs"
    click Conversion "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/Conversion.Stream.cs"
    click RenderOptions "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/RenderOptions.cs"
    click RenderOptions "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/PdfRotation.cs"
    click RenderOptions "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/PdfAntiAliasing.cs"
    click RenderOptions "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/IRenderOptions.cs"
    click CoreProj "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/PDFtoImage.csproj"
    click PublicAPI "https://github.com/sungaila/pdftoimage/tree/master/src/PDFtoImage/PublicAPI/"
    click LibLoader "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/Internals/LibraryLoader.cs"
    click NativeMethods "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/Internals/NativeMethods.cs"
    click PdfAbstractions "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/Internals/PdfLibrary.cs"
    click PdfAbstractions "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/Internals/PdfDocument.cs"
    click PdfAbstractions "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/Internals/PdfFile.cs"
    click PdfAbstractions "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/Internals/StreamManager.cs"
    click Exceptions "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/Exceptions/PdfCannotOpenFileException.cs"
    click UnityPkg "https://github.com/sungaila/pdftoimage/tree/master/etc/UnityPackage/Plugins/"
    click NuGet "https://github.com/sungaila/pdftoimage/blob/master/src/PDFtoImage/PDFtoImage.props"
    click Docker "https://github.com/sungaila/pdftoimage/tree/master/src/FrameworkTests/AotConsole/Dockerfiles/"
    click CI "https://github.com/sungaila/pdftoimage/blob/master/.github/workflows/dotnet.yml"

    %% Styles
    classDef blue fill:#cfe2f3,stroke:#2f75b5,color:#000
    classDef green fill:#d9ead3,stroke:#6aa84f,color:#000
    classDef orange fill:#fce5cd,stroke:#e69138,color:#000
    classDef purple fill:#ead1dc,stroke:#a64d79,color:#000
    classDef grey fill:#f2f2f2,stroke:#999,color:#000
```
