diff --git a/DocumentService.API/Controllers/SwissQrCodeController.cs b/DocumentService.API/Controllers/SwissQrCodeController.cs index f8e9a77..7feeb08 100644 --- a/DocumentService.API/Controllers/SwissQrCodeController.cs +++ b/DocumentService.API/Controllers/SwissQrCodeController.cs @@ -55,7 +55,7 @@ public class SwissQrCodeController(IMediator Mediator) : ControllerBase }; var result = await Mediator.Send(query, cancellationToken); - return Ok(raw ? result.RawLines : result.Bill); + return Ok(result); } /// @@ -97,7 +97,7 @@ public class SwissQrCodeController(IMediator Mediator) : ControllerBase var query = new ExtractSwissQrCodeQuery { PdfStream = pdfStream }; var result = await Mediator.Send(query, cancellationToken); - return Ok(raw ? result.RawLines : result.Bill); + return Ok(result); } } diff --git a/DocumentService.Infrastructure/Services/PdfProcessing/DevExpressPdfProcessor.cs b/DocumentService.Infrastructure/Services/PdfProcessing/DevExpressPdfProcessor.cs index 0b296f6..fc0f4af 100644 --- a/DocumentService.Infrastructure/Services/PdfProcessing/DevExpressPdfProcessor.cs +++ b/DocumentService.Infrastructure/Services/PdfProcessing/DevExpressPdfProcessor.cs @@ -123,23 +123,7 @@ public class DevExpressPdfProcessor : IPdfProcessor pdfBytes = memoryStream.ToArray(); } - // 3. Load PDF with DevExpress Document API - // Reset position for DevExpress (seekable streams only) - if (pdfStream.CanSeek) - { - pdfStream.Position = 0; - } - - using var processor = new PdfDocumentProcessor(); - processor.LoadDocument(pdfStream); - - var document = processor.Document; - - // 4. Extract basic metadata - int pageCount = document.Pages.Count; - string pdfVersion = document.Version.ToString(); - - // 5. Check encryption (scan PDF raw data for /Encrypt keyword) + // 3. Check encryption (scan PDF raw data for /Encrypt keyword) bool encrypted = DetectEncryption(pdfBytes); // 6. Check PDF/A conformance (scan PDF raw data for PDF/A identifier) @@ -149,13 +133,42 @@ public class DevExpressPdfProcessor : IPdfProcessor var errors = new List(); var warnings = new List(); - // If encrypted, PDF/A compliance is not possible - if (encrypted && isPdfACompliant) + int pageCount = 0; + string pdfVersion = string.Empty; + + // If encrypted, skip DevExpress loading (it will throw) and return early + if (encrypted) { - errors.Add("PDF/A documents cannot be encrypted"); isPdfACompliant = false; + errors.Add("PDF/A documents cannot be encrypted"); + + return new PdfAValidationResult + { + IsValid = false, + PdfVersion = pdfVersion, + PageCount = pageCount, + FileSize = pdfBytes.Length, + Encrypted = true, + PdfAVersion = null, + PdfACompliant = false, + Errors = errors, + Warnings = warnings + }; } + // Load PDF with DevExpress Document API (only for non-encrypted PDFs) + if (pdfStream.CanSeek) + pdfStream.Position = 0; + + using var processor = new PdfDocumentProcessor(); + processor.LoadDocument(pdfStream); + + var document = processor.Document; + + // 4. Extract basic metadata + pageCount = document.Pages.Count; + pdfVersion = document.Version.ToString(); + // Basic PDF/A validation checks if (isPdfACompliant) { diff --git a/opencode.jsonc b/opencode.jsonc new file mode 100644 index 0000000..298d368 --- /dev/null +++ b/opencode.jsonc @@ -0,0 +1,10 @@ +{ + "$schema": "https://opencode.ai/config.json", + "skills": { + "paths": [ + "~/.config/opencode/skills/external/andrej-karpathy-skills/skills", + "~/.config/opencode/skills/external/ponytail/skills", + "~/.config/opencode/skills/external/i-have-adhd/skills" + ] + } +}