23 lines
831 B
C#
23 lines
831 B
C#
using DocumentOperator.Application.Common.Dto;
|
|
using DocumentOperator.Application.Common.Interfaces.Services;
|
|
using MediatR;
|
|
|
|
namespace DocumentOperator.Application.SignPdf;
|
|
|
|
public sealed record SignPdfCommand : IRequest<byte[]>
|
|
{
|
|
public required Stream InputPdf { get; init; }
|
|
public required PdfSignOptionsDto Options { get; init; }
|
|
public Stream? SignatureImage { get; init; }
|
|
}
|
|
|
|
public sealed class SignPdfCommandHandler(IPdfDigitalSignatureService signer) : IRequestHandler<SignPdfCommand, byte[]>
|
|
{
|
|
public async Task<byte[]> Handle(SignPdfCommand command, CancellationToken cancellationToken)
|
|
{
|
|
using var output = new MemoryStream();
|
|
await signer.SignPdfAsync(command.InputPdf, output, command.Options, command.SignatureImage, cancellationToken);
|
|
return output.ToArray();
|
|
}
|
|
}
|