Zymergi.Pdf.Docnet 11.4.0-alpha

This is a prerelease version of Zymergi.Pdf.Docnet.
dotnet add package Zymergi.Pdf.Docnet --version 11.4.0-alpha
                    
NuGet\Install-Package Zymergi.Pdf.Docnet -Version 11.4.0-alpha
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Zymergi.Pdf.Docnet" Version="11.4.0-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zymergi.Pdf.Docnet" Version="11.4.0-alpha" />
                    
Directory.Packages.props
<PackageReference Include="Zymergi.Pdf.Docnet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zymergi.Pdf.Docnet --version 11.4.0-alpha
                    
#r "nuget: Zymergi.Pdf.Docnet, 11.4.0-alpha"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Zymergi.Pdf.Docnet@11.4.0-alpha
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zymergi.Pdf.Docnet&version=11.4.0-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Zymergi.Pdf.Docnet&version=11.4.0-alpha&prerelease
                    
Install as a Cake Tool

Zymergi.Pdf.Docnet

Docnet (PDFium) implementation of IPdfRasterDocument and IPdfRasterPage from Zymergi.Core. It renders PDF pages to PNG, JPEG, WebP, or GIF bytes, with transparent pixels put on white.

Targets .NET 10. Depends on Zymergi.Core. References Docnet.Core and Magick.NET-Q16-AnyCPU directly (not Zymergi.Imaging.Magick).

Install

dotnet add package Zymergi.Pdf.Docnet

Register in Program.cs

Nothing to register. Create a PdfRasterDocument per document and dispose it. To inject it, register a small factory of your own:

builder.Services.AddSingleton<Func<byte[], IPdfRasterDocument>>(_ => bytes => new PdfRasterDocument(bytes));

Use it

using Zymergi.Core.Interfaces;
using Zymergi.Pdf.Docnet;

public sealed class PdfPreviewService(Func<byte[], IPdfRasterDocument> open)
{
    public byte[] FirstPagePng(byte[] pdf)
    {
        using IPdfRasterDocument doc = open(pdf);
        if (doc.Count() == 0) throw new InvalidOperationException("PDF has no pages");
        using IPdfRasterPage page = doc[0];
        return page.ToByteArray("image/png");
    }
}

app.MapPost("/pdf/preview", async (IFormFile file, PdfPreviewService previews, CancellationToken ct) =>
{
    using var ms = new MemoryStream();
    await file.CopyToAsync(ms, ct);
    return Results.File(previews.FirstPagePng(ms.ToArray()), "image/png");
}).DisableAntiforgery().RequireAuthorization();

You can also open a file path (new PdfRasterDocument("manual.pdf")) or an ISimpleObject from storage.

Best practices

  • Dispose the document and each page. They hold native PDFium readers.
  • Rendering is synchronous and CPU-heavy. Limit upload size and concurrency, and render large documents in a background job; store the images instead of rendering per request.
  • Treat uploaded PDFs as untrusted. Keep Docnet and Magick.NET up to date.

Testing

Keep a small PDF fixture in the test project. Assert the page count and that ToByteArray returns an image of the expected size.

Gotchas

  • Pages render into a 1080 × 1920 box (Docnet PageDimensions). There is no option to change the resolution.
  • The whole PDF is read into memory.
  • Page index is zero-based (doc[0] is page 1).
  • There are no async APIs.

Version notes

11.4.0-alpha: no API change.

Source: bitbucket.org/zymergy/zymergi.saas

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.4.0-alpha 84 11/16/2026
11.3.0-alpha 72 11/12/2026
11.2.0-alpha 63 11/2/2026
11.1.1-alpha 83 10/4/2026
11.1.0-alpha 111 10/1/2026
11.0.6-alpha 122 7/10/2026
11.0.5-alpha 85 7/9/2026
11.0.4-alpha 84 7/6/2026
11.0.3-alpha 79 7/6/2026
11.0.2-alpha 83 6/30/2026
11.0.1-alpha 84 6/30/2026
11.0.0-alpha 86 6/30/2026