- Add MergePdfsAsync method to IPdfProcessor interface - Parameters: IReadOnlyList<Stream> pdfStreams, IReadOnlyList<string?>? pageRanges - Returns: Task<byte[]> (merged PDF) - Validates: Minimum 2 PDFs, stream Position = 0, page ranges count matches PDF count - Supports optional page ranges (e.g., '1-3,5' or null for all pages)
79 lines
3.8 KiB
C#
79 lines
3.8 KiB
C#
using DocumentOperator.Application.Common.DTOs;
|
|
|
|
namespace DocumentOperator.Application.Common.Interfaces;
|
|
|
|
public interface IPdfProcessor
|
|
{
|
|
/// <summary>
|
|
/// Validates a PDF and extracts metadata.
|
|
/// </summary>
|
|
/// <param name="pdfStream">
|
|
/// PDF document stream. Must be readable and positioned at the beginning (Position = 0).
|
|
/// Non-seekable streams are supported. Caller is responsible for disposal.
|
|
/// </param>
|
|
/// <returns>PDF metadata (page count, size, version, attachments)</returns>
|
|
/// <exception cref="Domain.Common.Exceptions.BadRequestException">
|
|
/// Thrown when stream is empty, invalid, or not positioned at the beginning
|
|
/// </exception>
|
|
Task<PdfMetadata> ValidateAsync(Stream pdfStream);
|
|
|
|
/// <summary>
|
|
/// Validates a PDF/A document and checks conformance level.
|
|
/// </summary>
|
|
/// <param name="pdfStream">
|
|
/// PDF document stream. Must be readable and positioned at the beginning (Position = 0).
|
|
/// Non-seekable streams are supported. Caller is responsible for disposal.
|
|
/// </param>
|
|
/// <returns>PDF/A metadata including conformance level and validation errors/warnings</returns>
|
|
/// <exception cref="Domain.Common.Exceptions.BadRequestException">
|
|
/// Thrown when stream is empty, invalid, or not positioned at the beginning
|
|
/// </exception>
|
|
Task<PdfAMetadata> ValidatePdfAAsync(Stream pdfStream);
|
|
|
|
/// <summary>
|
|
/// Checks for embedded files (attachments) in a PDF document and returns detailed metadata.
|
|
/// </summary>
|
|
/// <param name="pdfStream">
|
|
/// PDF document stream. Must be readable and positioned at the beginning (Position = 0).
|
|
/// Non-seekable streams are supported. Caller is responsible for disposal.
|
|
/// </param>
|
|
/// <returns>Attachment information (count, file names, MIME types, sizes)</returns>
|
|
/// <exception cref="Domain.Common.Exceptions.BadRequestException">
|
|
/// Thrown when stream is empty, invalid, or not positioned at the beginning
|
|
/// </exception>
|
|
Task<AttachmentInfo> CheckAttachmentsAsync(Stream pdfStream);
|
|
|
|
/// <summary>
|
|
/// Extracts all embedded files from a PDF document and returns them as a ZIP archive.
|
|
/// </summary>
|
|
/// <param name="pdfStream">
|
|
/// PDF document stream. Must be readable and positioned at the beginning (Position = 0).
|
|
/// Non-seekable streams are supported. Caller is responsible for disposal.
|
|
/// </param>
|
|
/// <returns>ZIP archive containing all extracted attachments as byte array</returns>
|
|
/// <exception cref="Domain.Common.Exceptions.BadRequestException">
|
|
/// Thrown when stream is empty, invalid, or not positioned at the beginning
|
|
/// </exception>
|
|
/// <exception cref="Domain.Common.Exceptions.NotFoundException">
|
|
/// Thrown when PDF contains no attachments
|
|
/// </exception>
|
|
Task<byte[]> ExtractAttachmentsAsync(Stream pdfStream);
|
|
|
|
/// <summary>
|
|
/// Merges multiple PDF documents into a single PDF.
|
|
/// </summary>
|
|
/// <param name="pdfStreams">
|
|
/// PDF streams to merge (minimum 2 required). Each stream must be readable and positioned
|
|
/// at the beginning (Position = 0). Caller is responsible for disposal.
|
|
/// </param>
|
|
/// <param name="pageRanges">
|
|
/// Optional page ranges per PDF (null = all pages). Format: "1-3,5" means pages 1, 2, 3, and 5.
|
|
/// If null or empty for a PDF, all pages are included. Array length must match pdfStreams length if provided.
|
|
/// </param>
|
|
/// <returns>Merged PDF as byte array</returns>
|
|
/// <exception cref="Domain.Common.Exceptions.BadRequestException">
|
|
/// Thrown when fewer than 2 PDFs provided, any stream is empty/invalid/not at Position=0,
|
|
/// or page range format is invalid
|
|
/// </exception>
|
|
Task<byte[]> MergePdfsAsync(IReadOnlyList<Stream> pdfStreams, IReadOnlyList<string?>? pageRanges = null);
|
|
} |