Class PdfRenderer
Production-grade renderer for PDF pages. Covers every output format ImageBuffer can write, plus the packed multi-page TIFF combo, and exposes async + CancellationToken + progress on every multi-page operation. Accepts PDFs as file paths, streams, or byte arrays, and writes single-page output to files, streams, or byte arrays.
public static class PdfRenderer
- Inheritance
-
PdfRenderer
- Inherited Members
Remarks
How this differs from PdfToImage.
PdfToImage is the quick-start convenience entry point: simple
signatures, PNG / JPEG / BMP only, synchronous, no progress, no
cancellation. PdfRenderer is the production surface used when
you need full format coverage (PNG, JPEG, WebP, BMP, TIFF, TGA, PNM,
plus packed multi-page TIFF), CancellationToken
support on every method, async variants throughout, progress
reporting via IProgress<T> of
PdfRenderProgressEventArgs, password-protected PDF
support, and Stream / byte-array input/output.
Input sources. Every public method comes in three flavors:
file path (string), Stream, and
byte array. Use the path form when reading from disk,
the stream form when piping (HTTP request bodies, blob storage),
and the bytes form when the PDF is already in memory.
Output destinations. Single-page save methods come in three
forms: to a file path (SavePageAs* with string outputPath),
to a Stream (SavePageAs* with
Stream outputStream), or returned as a byte array
(RenderPageAs*Bytes). Multi-page-to-files (SavePagesAs*s)
only write to a directory because there is no other natural target
for "many files." Multi-page-to-one-TIFF supports file, stream, and
bytes outputs.
Per-format encoder knobs (PNG compression level, JPEG / WebP quality, BMP / TGA RLE) are passed directly to the relevant method; they are not stored on PdfRenderOptions.
Memory profile. The streaming methods
(RenderPages(string, PdfRenderOptions, CancellationToken),
RenderPagesAsync(string, PdfRenderOptions, CancellationToken),
and every SavePagesAs*s method that writes one file per page)
hold at most one rendered page in memory at a time. The packed
SavePagesAsMultipageTiff(string, string, PdfRenderOptions, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
method must hold every page because the underlying native TIFF writer
takes a single shared header. For very large PDFs prefer
SavePagesAsTiffs(string, string, PdfRenderOptions, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
(one file per page).
Password support. Set Password to open encrypted PDFs. The same options object opens any input source uniformly.
Page range syntax. PageRange is
parsed by GetPageIndexes(string, int):
"1-5, 7, 9-12", "*", or null = all pages.
Methods
- GetPageCount(byte[], string)
Returns the number of pages in the PDF.
- GetPageCount(Stream, string, bool)
Returns the number of pages in the PDF.
- GetPageCount(string, string)
Returns the number of pages in the PDF.
- GetRenderedPageSize(byte[], int, PdfRenderOptions)
Returns the pixel dimensions the renderer would produce for the given page and options, without actually rendering.
- GetRenderedPageSize(Stream, int, PdfRenderOptions, bool)
Returns the pixel dimensions the renderer would produce for the given page and options, without actually rendering.
- GetRenderedPageSize(string, int, PdfRenderOptions)
Returns the pixel dimensions the renderer would produce for the given page and options, without actually rendering.
- RenderPage(byte[], int, PdfRenderOptions, CancellationToken)
Renders a single PDF page as an ImageBuffer.
- RenderPage(Stream, int, PdfRenderOptions, bool, CancellationToken)
Renders a single PDF page as an ImageBuffer.
- RenderPage(string, int, PdfRenderOptions, CancellationToken)
Renders a single PDF page as an ImageBuffer.
- RenderPageAsBmpBytes(string, int, PdfRenderOptions, bool, CancellationToken)
Renders one page and returns it as a BMP-encoded byte array.
- RenderPageAsBmpBytesAsync(string, int, PdfRenderOptions, bool, CancellationToken)
Renders one page and returns it as a BMP-encoded byte array.
- RenderPageAsJpegBytes(string, int, PdfRenderOptions, int, CancellationToken)
Renders one page and returns it as a JPEG-encoded byte array.
- RenderPageAsJpegBytesAsync(string, int, PdfRenderOptions, int, CancellationToken)
Renders one page and returns it as a JPEG-encoded byte array.
- RenderPageAsPngBytes(string, int, PdfRenderOptions, int, CancellationToken)
Renders one page and returns it as a PNG-encoded byte array.
- RenderPageAsPngBytesAsync(string, int, PdfRenderOptions, int, CancellationToken)
Renders one page and returns it as a PNG-encoded byte array.
- RenderPageAsPnmBytes(string, int, PdfRenderOptions, CancellationToken)
Renders one page and returns it as a PNM-encoded byte array.
- RenderPageAsPnmBytesAsync(string, int, PdfRenderOptions, CancellationToken)
Renders one page and returns it as a PNM-encoded byte array.
- RenderPageAsTgaBytes(string, int, PdfRenderOptions, bool, CancellationToken)
Renders one page and returns it as a TGA-encoded byte array.
- RenderPageAsTgaBytesAsync(string, int, PdfRenderOptions, bool, CancellationToken)
Renders one page and returns it as a TGA-encoded byte array.
- RenderPageAsTiffBytes(string, int, PdfRenderOptions, CancellationToken)
Renders one page and returns it as a single-page TIFF-encoded byte array.
- RenderPageAsTiffBytesAsync(string, int, PdfRenderOptions, CancellationToken)
Renders one page and returns it as a single-page TIFF-encoded byte array.
- RenderPageAsWebpBytes(string, int, PdfRenderOptions, int, CancellationToken)
Renders one page and returns it as a WebP-encoded byte array.
- RenderPageAsWebpBytesAsync(string, int, PdfRenderOptions, int, CancellationToken)
Renders one page and returns it as a WebP-encoded byte array.
- RenderPageAsync(byte[], int, PdfRenderOptions, CancellationToken)
Renders a single PDF page as an ImageBuffer.
- RenderPageAsync(Stream, int, PdfRenderOptions, bool, CancellationToken)
Renders a single PDF page as an ImageBuffer.
- RenderPageAsync(string, int, PdfRenderOptions, CancellationToken)
Renders a single PDF page as an ImageBuffer.
- RenderPages(byte[], PdfRenderOptions, CancellationToken)
Lazily renders the pages selected by PageRange from a PDF byte array. Yields one
(pageIndex, image)tuple at a time so the caller can dispose the buffer between iterations and keep memory flat.
- RenderPages(Stream, PdfRenderOptions, bool, CancellationToken)
Lazily renders the pages selected by PageRange from a PDF stream. Yields one
(pageIndex, image)tuple at a time so the caller can dispose the buffer between iterations and keep memory flat.
- RenderPages(string, PdfRenderOptions, CancellationToken)
Lazily renders the pages selected by PageRange. Yields one
(pageIndex, image)tuple at a time so the caller can dispose the buffer between iterations and keep memory flat.
- RenderPagesAsync(byte[], PdfRenderOptions, CancellationToken)
Lazily renders the pages selected by PageRange from a PDF byte array. Yields one
(pageIndex, image)tuple at a time so the caller can dispose the buffer between iterations and keep memory flat.
- RenderPagesAsync(Stream, PdfRenderOptions, bool, CancellationToken)
Lazily renders the pages selected by PageRange from a PDF stream. Yields one
(pageIndex, image)tuple at a time so the caller can dispose the buffer between iterations and keep memory flat.
- RenderPagesAsync(string, PdfRenderOptions, CancellationToken)
Lazily renders the pages selected by PageRange. Yields one
(pageIndex, image)tuple at a time so the caller can dispose the buffer between iterations and keep memory flat.
- SavePageAsBmp(string, int, Stream, PdfRenderOptions, bool, CancellationToken)
Renders one page and writes it as BMP to a writable stream.
- SavePageAsBmp(string, int, string, PdfRenderOptions, bool, CancellationToken)
Renders one page and writes it as BMP to a file.
- SavePageAsBmpAsync(string, int, Stream, PdfRenderOptions, bool, CancellationToken)
Renders one page and writes it as BMP to a writable stream.
- SavePageAsBmpAsync(string, int, string, PdfRenderOptions, bool, CancellationToken)
Renders one page and writes it as BMP to a file.
- SavePageAsJpeg(string, int, Stream, PdfRenderOptions, int, CancellationToken)
Renders one page and writes it as JPEG to a writable stream.
- SavePageAsJpeg(string, int, string, PdfRenderOptions, int, CancellationToken)
Renders one page and writes it as JPEG to a file.
- SavePageAsJpegAsync(string, int, Stream, PdfRenderOptions, int, CancellationToken)
Renders one page and writes it as JPEG to a writable stream.
- SavePageAsJpegAsync(string, int, string, PdfRenderOptions, int, CancellationToken)
Renders one page and writes it as JPEG to a file.
- SavePageAsPng(string, int, Stream, PdfRenderOptions, int, CancellationToken)
Renders one page and writes it as PNG to a writable stream.
- SavePageAsPng(string, int, string, PdfRenderOptions, int, CancellationToken)
Renders one page and writes it as PNG to a file.
- SavePageAsPngAsync(string, int, Stream, PdfRenderOptions, int, CancellationToken)
Renders one page and writes it as PNG to a writable stream.
- SavePageAsPngAsync(string, int, string, PdfRenderOptions, int, CancellationToken)
Renders one page and writes it as PNG to a file.
- SavePageAsPnm(string, int, Stream, PdfRenderOptions, CancellationToken)
Renders one page and writes it as PNM (Netpbm) to a writable stream.
- SavePageAsPnm(string, int, string, PdfRenderOptions, CancellationToken)
Renders one page and writes it as PNM (Netpbm) to a file.
- SavePageAsPnmAsync(string, int, Stream, PdfRenderOptions, CancellationToken)
Renders one page and writes it as PNM (Netpbm) to a writable stream.
- SavePageAsPnmAsync(string, int, string, PdfRenderOptions, CancellationToken)
Renders one page and writes it as PNM (Netpbm) to a file.
- SavePageAsTga(string, int, Stream, PdfRenderOptions, bool, CancellationToken)
Renders one page and writes it as TGA to a writable stream.
- SavePageAsTga(string, int, string, PdfRenderOptions, bool, CancellationToken)
Renders one page and writes it as TGA to a file.
- SavePageAsTgaAsync(string, int, Stream, PdfRenderOptions, bool, CancellationToken)
Renders one page and writes it as TGA to a writable stream.
- SavePageAsTgaAsync(string, int, string, PdfRenderOptions, bool, CancellationToken)
Renders one page and writes it as TGA to a file.
- SavePageAsTiff(string, int, Stream, PdfRenderOptions, CancellationToken)
Renders one page and writes it as single-page TIFF to a writable stream.
- SavePageAsTiff(string, int, string, PdfRenderOptions, CancellationToken)
Renders one page and writes it as a single-page TIFF to a file.
- SavePageAsTiffAsync(string, int, Stream, PdfRenderOptions, CancellationToken)
Renders one page and writes it as single-page TIFF to a writable stream.
- SavePageAsTiffAsync(string, int, string, PdfRenderOptions, CancellationToken)
Renders one page and writes it as a single-page TIFF to a file.
- SavePageAsWebp(string, int, Stream, PdfRenderOptions, int, CancellationToken)
Renders one page and writes it as WebP to a writable stream.
- SavePageAsWebp(string, int, string, PdfRenderOptions, int, CancellationToken)
Renders one page and writes it as WebP to a file.
- SavePageAsWebpAsync(string, int, Stream, PdfRenderOptions, int, CancellationToken)
Renders one page and writes it as WebP to a writable stream.
- SavePageAsWebpAsync(string, int, string, PdfRenderOptions, int, CancellationToken)
Renders one page and writes it as WebP to a file.
- SavePagesAsBmps(string, string, PdfRenderOptions, bool, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and writes one BMP per page.
- SavePagesAsBmpsAsync(string, string, PdfRenderOptions, bool, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and writes one BMP per page.
- SavePagesAsJpegs(string, string, PdfRenderOptions, int, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and writes one JPEG per page.
- SavePagesAsJpegsAsync(string, string, PdfRenderOptions, int, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and writes one JPEG per page.
- SavePagesAsMultipageTiff(string, Stream, PdfRenderOptions, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages, packs them into a multi-page TIFF, and writes it to a stream.
- SavePagesAsMultipageTiff(string, string, PdfRenderOptions, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and packs them into a single multi-page TIFF file.
- SavePagesAsMultipageTiffAsync(string, Stream, PdfRenderOptions, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages, packs them into a multi-page TIFF, and writes it to a stream.
- SavePagesAsMultipageTiffAsync(string, string, PdfRenderOptions, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and packs them into a single multi-page TIFF file.
- SavePagesAsMultipageTiffBytes(string, PdfRenderOptions, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and returns them as a multi-page TIFF byte array.
- SavePagesAsMultipageTiffBytesAsync(string, PdfRenderOptions, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and returns them as a multi-page TIFF byte array.
- SavePagesAsPngs(string, string, PdfRenderOptions, int, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and writes one PNG per page.
- SavePagesAsPngsAsync(string, string, PdfRenderOptions, int, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and writes one PNG per page.
- SavePagesAsPnms(string, string, PdfRenderOptions, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and writes one PNM per page.
- SavePagesAsPnmsAsync(string, string, PdfRenderOptions, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and writes one PNM per page.
- SavePagesAsTgas(string, string, PdfRenderOptions, bool, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and writes one TGA per page.
- SavePagesAsTgasAsync(string, string, PdfRenderOptions, bool, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and writes one TGA per page.
- SavePagesAsTiffs(string, string, PdfRenderOptions, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and writes one single-page TIFF per page.
- SavePagesAsTiffsAsync(string, string, PdfRenderOptions, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and writes one single-page TIFF per page.
- SavePagesAsWebps(string, string, PdfRenderOptions, int, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and writes one WebP per page.
- SavePagesAsWebpsAsync(string, string, PdfRenderOptions, int, string, IProgress<PdfRenderProgressEventArgs>, CancellationToken)
Renders the selected pages and writes one WebP per page.