Add PDF attachment and PDF/A conversion features

Introduced endpoints for embedding attachments in PDFs and converting
between standard PDFs and PDF/A formats. Added `PdfAttachmentController`
and `PdfConversionController` with multipart/form-data and Base64-based
support. Implemented commands, handlers, and validators for these
operations.

Extended `IPdfProcessor` with methods for adding attachments and
PDF/A conversion. Partially implemented functionality in
`DevExpressPdfProcessor`, including `ConvertFromPdfAAsync`.

Added `attachment.xml` and `withoutAttachment.pdf` as resources for
testing. Marked endpoints as `[Obsolete]` to indicate incomplete
implementation. Improved validation and error handling for commands.
This commit is contained in:
2026-07-30 13:43:55 +02:00
parent a242458d2f
commit a6694bfce7
9 changed files with 876 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
using DocumentOperator.Application.Common.Interfaces;
using FluentValidation;
using MediatR;
namespace DocumentOperator.Application.ConvertFromPdfA;
/// <summary>
/// Command to convert a PDF/A document to a standard PDF (removes PDF/A restrictions)
/// </summary>
public record ConvertFromPdfACommand : IRequest<byte[]>
{
/// <summary>
/// PDF/A document stream. Must be positioned at the beginning (Position = 0).
/// </summary>
public required Stream PdfStream { get; init; }
}
/// <summary>
/// Handler for ConvertFromPdfACommand
/// </summary>
public class ConvertFromPdfACommandHandler(IPdfProcessor pdfProcessor)
: IRequestHandler<ConvertFromPdfACommand, byte[]>
{
public async Task<byte[]> Handle(ConvertFromPdfACommand request, CancellationToken cancellationToken)
{
return await pdfProcessor.ConvertFromPdfAAsync(request.PdfStream);
}
}
/// <summary>
/// Validator for ConvertFromPdfACommand
/// </summary>
public class ConvertFromPdfACommandValidator : AbstractValidator<ConvertFromPdfACommand>
{
public ConvertFromPdfACommandValidator()
{
RuleFor(x => x.PdfStream)
.NotNull()
.WithMessage("PDF stream is required");
}
}