Zymergi.Pdf.Docnet
11.4.0-alpha
dotnet add package Zymergi.Pdf.Docnet --version 11.4.0-alpha
NuGet\Install-Package Zymergi.Pdf.Docnet -Version 11.4.0-alpha
<PackageReference Include="Zymergi.Pdf.Docnet" Version="11.4.0-alpha" />
<PackageVersion Include="Zymergi.Pdf.Docnet" Version="11.4.0-alpha" />
<PackageReference Include="Zymergi.Pdf.Docnet" />
paket add Zymergi.Pdf.Docnet --version 11.4.0-alpha
#r "nuget: Zymergi.Pdf.Docnet, 11.4.0-alpha"
#:package Zymergi.Pdf.Docnet@11.4.0-alpha
#addin nuget:?package=Zymergi.Pdf.Docnet&version=11.4.0-alpha&prerelease
#tool nuget:?package=Zymergi.Pdf.Docnet&version=11.4.0-alpha&prerelease
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.
| Product | Versions 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. |
-
net10.0
- Docnet.Core (>= 2.6.0)
- Magick.NET-Q16-AnyCPU (>= 14.17.2)
- Zymergi.Core (>= 11.4.0-alpha)
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 |