Class PdfPrintService
- Namespace
- combit.Reporting.Printing.Pdf
- Assembly
- combit.ListLabel31.CrossPlatform.Printing.Pdf.dll
Default implementation of IPdfPrintService that orchestrates the full
print pipeline: input validation, printer capability probing, PDF passthrough,
and rasterized fallback printing.
using combit.Reporting.Printing.Pdf;
var printerName = "My Printer";
var pdfPath = "document.pdf";
using var printService = new PdfPrintService();
PrintResult result = await printService.PrintAsync(
pdfPath,
printerName,
options: new PrintJobOptions { PreferPdfPassthrough = true },
cancellationToken: CancellationToken.None);
if (!result.Success)
{
Console.WriteLine(result.ErrorMessage);
Console.WriteLine(result.Diagnostics);
}
using combit.Reporting.Printing.Pdf;
var printerName = "My Printer";
await using FileStream pdfStream = File.OpenRead("document.pdf");
using var printService = new PdfPrintService();
PrintResult result = await printService.PrintAsync(
pdfStream,
printerName,
options: new PrintJobOptions { RasterDpi = 300 },
cancellationToken: CancellationToken.None);
public sealed class PdfPrintService : IPdfPrintService, IDisposable
- Inheritance
-
PdfPrintService
- Implements
- Inherited Members
Constructors
PdfPrintService()
Initializes a new instance of the PdfPrintService class using the platform-default backend and rasterizer with logging disabled.
public PdfPrintService()
PdfPrintService(ILogger?)
Initializes a new instance of the PdfPrintService class using the platform-default backend and rasterizer.
public PdfPrintService(ILogger? logger)
Parameters
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
PrintAsync(Stream, string, PrintJobOptions?, CancellationToken)
Prints a PDF document from a stream to the specified printer. The stream contents are read into memory and passed directly to the print backend; no temporary file is created on disk.
public Task<PrintResult> PrintAsync(Stream pdfStream, string printerName, PrintJobOptions? options = null, CancellationToken cancellationToken = default)
Parameters
pdfStreamStreamA readable stream containing the PDF document.
printerNamestringThe system name of the target printer.
optionsPrintJobOptionsOptional print job settings. When null, default options are used.
cancellationTokenCancellationTokenToken used to observe cancellation requests.
Returns
- Task<PrintResult>
A PrintResult describing whether the print operation succeeded, the method used, and any error or diagnostic information.
Exceptions
- ArgumentNullException
Thrown when
pdfStreamorprinterNameis null.- ArgumentException
Thrown when
printerNameis empty or whitespace, or whenpdfStreamis not readable.
PrintAsync(string, string, PrintJobOptions?, CancellationToken)
Prints a PDF document from a file path to the specified printer.
public Task<PrintResult> PrintAsync(string pdfFilePath, string printerName, PrintJobOptions? options = null, CancellationToken cancellationToken = default)
Parameters
pdfFilePathstringThe absolute path to the PDF file to print.
printerNamestringThe system name of the target printer.
optionsPrintJobOptionsOptional print job settings. When null, default options are used.
cancellationTokenCancellationTokenToken used to observe cancellation requests.
Returns
- Task<PrintResult>
A PrintResult describing whether the print operation succeeded, the method used, and any error or diagnostic information.
Exceptions
- ArgumentNullException
Thrown when
pdfFilePathorprinterNameis null.- ArgumentException
Thrown when
pdfFilePathorprinterNameis empty or whitespace.- FileNotFoundException
Thrown when the file specified by
pdfFilePathdoes not exist.