Commit Graph

21 Commits

Author SHA1 Message Date
a6694bfce7 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.
2026-07-30 13:43:55 +02:00
c4ec0c2b48 feat(annotation): Implement coordinate system conversion in DevExpressPdfProcessor
- Add Y-axis conversion for TopLeft origin (bottomLeftY = pageHeight - topLeftY)
- Origin parameter support in AddAnnotationAsync
- Preserves existing BottomLeft behavior as default
2026-07-21 14:38:08 +02:00
41f97ce533 feat(infrastructure): Implement DevExpressPdfProcessor.AddAnnotationAsync
- Implement AddAnnotationAsync using DevExpress PdfDocumentProcessor
- Add 5 private helper methods (one per annotation type)
- Add ParseColor helper (hex string to PdfRGBColor)
- Validation: content required for FreeText/StickyNote, style for TextMarkup
- Default colors: Yellow for TextMarkup, Red for others
- Handle DevExpress API quirks (TextMarkupStyle.StrikeOut capitalization)
2026-07-21 12:28:05 +02:00
3598c5f9c6 feat: Implement DevExpressPdfProcessor.MergePdfsAsync with page range support
- Implement MergePdfsAsync: merges multiple PDFs with optional page ranges
- Add ParsePageRange helper: parses '1-3,5' format, validates page numbers
- Stream-based pipeline (no byte[] buffering)
- Validates: Position = 0, minimum 2 PDFs, page ranges count
- Uses DevExpress PdfDocumentProcessor for actual merge operation
- Returns merged PDF as byte array
2026-07-21 10:20:35 +02:00
26458a4017 feat: Implement DevExpressPdfProcessor.ExtractAttachmentsAsync with ZIP packaging 2026-07-21 09:26:18 +02:00
1af158840e refactor(infrastructure): implement Stream-based PDF processing
DevExpressPdfProcessor:
- ValidateAsync, ValidatePdfAAsync, CheckAttachmentsAsync: Stream parameters
- Defensive Position=0 validation (BadRequestException for seekable streams not at beginning)
- Remove unsafe Position reset (non-seekable stream compatibility)
- Remove PdfProcessingException wrapping (let DevExpress exceptions propagate naturally)

DevExpressSwissQrCodeProcessor:
- ExtractSwissQrCodeAsync: Stream parameter
- Defensive Position=0 validation
- Remove unsafe Position reset

Memory optimization: MemoryStream.TryGetBuffer fast path for byte[] extraction
2026-07-20 16:31:47 +02:00
1de781748b refactor: Update DevExpressPdfProcessor to use Stream parameters
- All 3 methods (ValidateAsync, ValidatePdfAAsync, CheckAttachmentsAsync) now accept Stream
- Add ArgumentNullException.ThrowIfNull() checks for null streams
- Implement fast-path optimization: reuse MemoryStream buffer when possible
- Implement slow-path fallback: copy stream to byte[] for DevExpress API compatibility
- Fix namespace collision: use fully qualified Application.Common.DTOs.PdfMetadata
2026-07-20 11:55:17 +02:00
88984c8887 Refactor and streamline codebase
- Removed `<Folder>` elements in `DocumentOperator.Domain.csproj`
  and replaced them with `<Compile Remove>`, `<EmbeddedResource Remove>`,
  and `<None Remove>` to exclude specific directories.
- Removed unused `using DocumentOperator.Domain.Exceptions;` directive.
- Simplified `Split` method syntax for delimiter specification.
- Updated `return` statements to use concise parameter syntax.
- Removed page number validation logic in `DevExpressSwissQrCodeProcessor`.
- Replaced default page scanning logic with modern range expression.
- Overall, improved code clarity, reduced redundancy, and modernized syntax.
2026-07-20 09:46:44 +02:00
88bde13422 refactor: Refactor DevExpressSwissQrCodeProcessor to use Codecrete QRBill parser
- Change return type to tuple (Bill, string[])
- Remove custom parsing methods (ParseSwissQrBillContent, MapAddress, DetermineReferenceType)
- Use Codecrete QRBill.DecodeQrCodeText() for parsing
- Add SkiaSharp.QrCode v1.0.0 for QR decoding
- Remove obsolete ZXing and System.Drawing dependencies
- Add StringExtensions for QR code detection
- Raw lines properly split and trimmed from QR text
2026-07-16 15:47:33 +02:00
cd50d45bd5 feat: Add PDF/A validation endpoint (Feature 3)
Domain layer:

  - PdfAMetadata value object (isValid, pdfVersion, pageCount, encrypted, pdfaVersion, pdfaCompliant, errors, warnings)

Infrastructure layer:

  - IPdfProcessor.ValidatePdfAAsync() interface method

  - DevExpressPdfProcessor.ValidatePdfAAsync() implementation

  - DetectEncryption() - scans PDF raw data for /Encrypt keyword

  - DetectPdfAConformance() - parses XMP metadata (pdfaid:part, pdfaid:conformance)

  - Validation: encrypted PDF cannot be PDF/A compliant

Application layer:

  - ValidatePdfAQuery + ValidatePdfAQueryHandler (co-located)

  - ValidatePdfAQueryValidator (FluentValidation: PdfBytes XOR Base64Pdf)

  - PdfAValidationResult DTO

  - AutoMapper: PdfAMetadata -> PdfAValidationResult

API layer:

  - PdfValidationController.ValidatePdfAFromFile() (multipart/form-data)

  - PdfValidationController.ValidatePdfAFromBase64() (application/json)

  - XML documentation with response codes

Result:

  - POST /api/pdf/validation/validate-pdfa (both multipart and JSON)

  - Returns: conformance level, errors, warnings

  - Build: 0 errors, 4 warnings (DevExpress eval)

  - Tests: 20/20 passing

Next: Integration tests + Swagger test case
2026-07-09 12:59:24 +02:00
8b154e7378 fix: Replace CreateBitmap with CreateDXBitmap for cross-platform compatibility
- Replace System.Drawing.Bitmap with DevExpress.Drawing.DXBitmap

- Fix CA1416 warnings (Windows-specific API usage)

- Fix CS0618 warning (TryInverted property moved to Options.TryInverted)

- Add [SupportedOSPlatform(windows)] attribute to DecodeQrCodeFromImage()

- Add Swiss QR Bill backward compatibility documentation

- Suppress CS0618 for AddressLine1/AddressLine2 (deprecated since Nov 2025)

- Use modern C# 12 collection expression syntax

Technical changes:

  - CreateBitmap() to CreateDXBitmap() (returns DXBitmap)

  - Convert DXBitmap to PNG stream to System.Drawing.Bitmap for ZXing

  - Add using DevExpress.Drawing and System.Runtime.Versioning

Result: 0 CA1416 warnings, 0 CS0618 warnings in DevExpressSwissQrCodeProcessor
2026-07-07 18:56:09 +02:00
OlgunR
47cba50d0f Add ExtractSwissQrCode feature and update feature order
Updated PHASENPLAN.md and ROADMAP.md to reflect the new
feature order, making "ExtractSwissQrCode" Feature 2 and
renumbering previous Features 2-5 to 3-6. Added detailed
steps, endpoints, and acceptance criteria for the new
feature.

Implemented `ISwissQrCodeProcessor` interface with
`DevExpressSwissQrCodeProcessor` for extracting and parsing
Swiss QR Codes using DevExpress and Codecrete libraries.
Registered the new service in DependencyInjection.cs.

Introduced `SwissQrCodeData` value object and
`SwissQrCodeNotFoundException` for domain modeling and
error handling. Updated project dependencies to include
libraries for QR code processing.

Adjusted existing feature descriptions and steps to align
with the new feature order.
2026-06-26 08:39:44 +02:00
OlgunR
18e956c2cf Enhance PDF attachment detection and counting
Refactored `DevExpressPdfProcessor` to improve attachment detection:
- Changed `DetectEmbeddedFiles` return type to a tuple for better
  handling of attachment presence and count.
- Enhanced logic to parse `/Names` arrays and count object references
  for accurate attachment detection.
- Implemented robust search for `/EmbeddedFiles` to handle multiple
  occurrences and ensure proper context validation.

Updated PHASENPLAN.md and ROADMAP.md to reflect these changes, including
the addition of fixes for attachment detection and counting logic.

Added new tests in `DevExpressPdfProcessorTests`:
- Verified detection of multiple attachments and accurate counts.
- Ensured no crashes when processing PDFs with `/EmbeddedFiles`.

Included a new test resource (`pdfWithMoreThanOneAttachment.pdf`) for
validating multiple attachment scenarios.
2026-06-25 17:17:32 +02:00
OlgunR
1b38d5a729 Implement attachment detection in ValidatePDF
Updated PHASENPLAN.md and ROADMAP.md to reflect a complete restructuring of the development plan and added a "Bugfix: Attachment Detection" entry.

Implemented attachment detection in DevExpressPdfProcessor.cs using the new `DetectEmbeddedFiles` method, which scans raw PDF data for the `/EmbeddedFiles` keyword. Updated the `hasAttachments` property to use this method and set `attachmentCount` to `-1` when attachments are detected.

Added a new test, `ValidateAsync_PdfWithoutAttachments_ReturnsNoAttachments`, in DevExpressPdfProcessorTests.cs to verify that PDFs without attachments are correctly identified. Included a note about future testing for PDFs with attachments using ZUGFeRD files.

All related tests are passing (12/12 green).
2026-06-25 16:25:16 +02:00
OlgunR
930b76ecb5 Add ValidatePDF feature with API, Swagger, and tests
Implemented the ValidatePDF feature end-to-end:
- Added `/api/v1/documents/validate` Minimal API endpoint.
- Introduced centralized ExceptionHandlingMiddleware.
- Configured Swagger with `AddSwaggerDocumentation` extension.
- Enabled XML comments in `DocumentOperator.API.csproj`.
- Updated DTOs with XML comments and added `FileSizeMB`.
- Added integration tests for the ValidatePDF endpoint (3 tests).
- Registered infrastructure services (e.g., `IPdfProcessor`).
- Refactored `Program.cs` to include middleware and endpoints.
- Updated PHASENPLAN.md and ROADMAP.md to reflect progress.
- Cleaned up code and made `Program` accessible for tests.
2026-06-25 16:01:33 +02:00
OlgunR
5ac0777e5b Remove duplicate using directive in DevExpressPdfProcessor.cs
Eliminated a redundant `using DevExpress.Pdf;` statement to improve code readability and maintain cleaner imports. This change has no functional impact but enhances code clarity.
2026-06-23 13:09:58 +02:00
OlgunR
b1d48418cf Migrate to DevExpress.Document.Processor library
Replaced `DevExpress.Pdf.Core` with `DevExpress.Document.Processor` in `DocumentOperator.Infrastructure.csproj` to adopt a newer library for PDF processing. Removed the `Services\PdfProcessing\` folder reference.

Updated `DevExpressPdfProcessorTests` to reflect changes in the `ValidateAsync` method's behavior.

Introduced the `DevExpressPdfProcessor` class, implementing the `IPdfProcessor` interface. This class validates PDF documents and extracts metadata using the `DevExpress.Pdf` library. Added defensive input validation, metadata extraction, and exception handling for domain consistency.
2026-06-23 10:33:43 +02:00
OlgunR
d8f3143c8a Integrate Serilog and add configuration classes
Enhanced logging with Serilog, including request logging and
structured exception handling during startup. Added support
for the Options Pattern with new configuration classes:
`DocumentOperatorSettings`, `RedisSettings`, and
`ApiKeySettings`. Introduced `TenantInfo` class for tenant
management. Updated project files to include new dependencies
and removed unused `Configuration` folder reference.
2026-06-16 11:21:03 +02:00
OlgunR
297f760e7f Refactor project structure and add new features
Restructured project files across all layers:
- Removed `Controllers` folder reference from `DocumentOperator.API.csproj`.
- Added folder structure to `DocumentOperator.Application`, `DocumentOperator.Domain`, and `DocumentOperator.Infrastructure` projects for better organization.

Introduced new API configurations and middleware:
- Added `SerilogConfiguration` and `SwaggerConfiguration` classes.
- Added `ExceptionHandlingMiddleware`, `RequestLoggingMiddleware`, and `TenantResolutionMiddleware`.

Implemented new document processing feature:
- Added `ProcessDocumentCommand`, `ProcessDocumentHandler`, and `ProcessDocumentValidator` classes in the application layer.
2026-06-15 16:21:43 +02:00
OlgunR
b25d593771 Add dependencies for API, Application, and Infrastructure
Added `Asp.Versioning.Http`, `Microsoft.Extensions.Caching.StackExchangeRedis`, and `Serilog.AspNetCore` to `DocumentOperator.API` for API versioning, Redis caching, and structured logging.

Added `Ardalis.Result`, `FluentValidation`, `FluentValidation.DependencyInjectionExtensions`, and `MediatR` to `DocumentOperator.Application` for result handling, validation, and mediator pattern support.

Added `DevExpress.Pdf.Core` and `Microsoft.Extensions.Options.ConfigurationExtensions` to `DocumentOperator.Infrastructure` for PDF processing and configuration management.
2026-06-15 11:00:22 +02:00
OlgunR
4d427c10fe Add project files. 2026-06-12 13:38:48 +02:00