Lyo.Pdf.Rendering
2.0.0
dotnet add package Lyo.Pdf.Rendering --version 2.0.0
NuGet\Install-Package Lyo.Pdf.Rendering -Version 2.0.0
<PackageReference Include="Lyo.Pdf.Rendering" Version="2.0.0" />
<PackageVersion Include="Lyo.Pdf.Rendering" Version="2.0.0" />
<PackageReference Include="Lyo.Pdf.Rendering" />
paket add Lyo.Pdf.Rendering --version 2.0.0
#r "nuget: Lyo.Pdf.Rendering, 2.0.0"
#:package Lyo.Pdf.Rendering@2.0.0
#addin nuget:?package=Lyo.Pdf.Rendering&version=2.0.0
#tool nuget:?package=Lyo.Pdf.Rendering&version=2.0.0
Lyo.Pdf.Rendering
Turns PDF pages into PNG through PDFtoImage (PDFium + Skia; bblanchon.PDFium native packages). Targets net10.0.
Examples
Render a cover page
services.AddPdfPageRasterizer();
public sealed class CoverRenderer(IPdfPageRasterizer rasterizer)
{
public async Task<byte[]> RenderAsync(ReadOnlyMemory<byte> pdf, CancellationToken ct)
=> (await rasterizer.RenderPageToPngAsync(pdf, pageNumber1Based: 1, dpi: 144, cancellationToken: ct))
.ValueOrThrow()
.PngBytes;
}
Rasterizer contract
public interface IPdfPageRasterizer
{
Task<Result<PdfRasterPage>> RenderPageToPngAsync(
ReadOnlyMemory<byte> pdfBytes,
int pageNumber1Based,
int dpi,
string? password = null,
CancellationToken cancellationToken = default);
}
public sealed record PdfRasterPage(byte[] PngBytes, int WidthPx, int HeightPx);
How the default rasterizer works
The default implementation is PdfToImagePageRasterizer. It sends the CPU-bound
PDFium call through Task.Run, reads bitmap size from the rendered bytes with ImageSharp,
and writes an elapsed-ms trace on success. Failures come back as
Result<PdfRasterPage>.Failure tagged with:
PdfRenderErrorCodes.PageOutOfRange("PDF_RENDER_PAGE_OUT_OF_RANGE") whenpageNumber1Based > pageCount.PdfRenderErrorCodes.RenderFailed("PDF_RENDER_FAILED") for invalid PDFs, missing/incorrect passwords, or any PDFium error.
Passwords and OCR
Protected PDFs need the document password argument. Pages are 1-based. Use Lyo.Pdf.Ocr when rasterization should run with IOcrEngine and bounding boxes should be projected back into PDF coordinates.
Dependencies
Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).
Lyo.Exceptions(direct, lyo)Lyo.Result(direct, lyo)Microsoft.Extensions.DependencyInjection.Abstractions10.0.5(direct, microsoft)Microsoft.Extensions.Logging.Abstractions10.0.5(direct, microsoft)PDFtoImage5.2.1(direct, third-party)SixLabors.ImageSharp3.1.12(direct, third-party)
| 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
- Lyo.Exceptions (>= 2.0.0)
- Lyo.Result (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
- PDFtoImage (>= 5.2.1)
- SixLabors.ImageSharp (>= 3.1.12)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Lyo.Pdf.Rendering:
| Package | Downloads |
|---|---|
|
Lyo.Pdf.Ocr
OCR pipeline for PDF pages: rasterize (PDFium), run IOcrEngine, map pixel boxes to PDF points. |
GitHub repositories
This package is not used by any popular GitHub repositories.