♻️ harmonize image and PDF extraction - #426
Open
ianardee wants to merge 4 commits into
Open
Conversation
ianardee
force-pushed
the
fix-file-operations
branch
9 times, most recently
from
August 7, 2026 15:26
9cbaefe to
22e0e92
Compare
sebastianMindee
approved these changes
Aug 10, 2026
ianardee
force-pushed
the
fix-file-operations
branch
from
August 11, 2026 13:34
22e0e92 to
fa86e07
Compare
ianardee
force-pushed
the
fix-file-operations
branch
from
September 2, 2026 14:35
907e674 to
a635a5b
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Several introduced regressions/inconsistencies (notably WriteToFile behavior vs docs, batch save directory handling, and disabled assertions in a unit test) should be corrected before merging.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR refactors the extraction/splitting utilities to harmonize image and PDF extraction flows, introducing shared collection types (ExtractedImages, ExtractedPdfs) and updating unit/integration tests to use the new APIs and filename conventions.
Changes:
- Replace V2
CropFiles/SplitFileswith sharedExtractedImages/ExtractedPdfsand update V2 operations to return the new types (ExtractMultipleCrops,ExtractMultipleSplits). - Standardize extracted artifact naming (e.g.,
*_pages-001-002.pdf,*_page-001-item-001.jpg) and adjust tests accordingly. - Update positioning/extraction plumbing with
IPositionDataField, and drop .NET 6 from the unit test workflow matrix.
File summaries
| File | Description |
|---|---|
| tests/Mindee.UnitTests/V2/FileOperations/SplitTest.cs | Updates V2 split unit tests for new API and filenames; adds output persistence. |
| tests/Mindee.UnitTests/V2/FileOperations/CropTest.cs | Updates V2 crop unit tests for new API and filenames; adds output persistence. |
| tests/Mindee.UnitTests/V1/Image/PdfExtractorTest.cs | Moves tests into V1 image namespace and updates assertions to PageCount + new naming. |
| tests/Mindee.UnitTests/V1/Image/ImageExtractorTest.cs | Writes extracted images to a created output directory; namespace alignment. |
| tests/Mindee.IntegrationTests/V2/FileOperations/SplitTest.cs | Updates integration split flow to new split API, naming, and disk persistence checks. |
| tests/Mindee.IntegrationTests/V2/FileOperations/CropTest.cs | Updates integration crop flow to new crop API, naming, and persistence expectations. |
| tests/Mindee.IntegrationTests/V1/InvoiceSplitterAutoExtractionTest.cs | Updates expected extracted PDF filenames to the new *_pages-* pattern. |
| src/Mindee/V2/Parsing/Inference/Field/FieldLocation.cs | Implements IPositionDataField so locations can be used by generic image extraction. |
| src/Mindee/V2/FileOperations/SplitFiles.cs | Removes V2-specific split collection helper in favor of shared ExtractedPdfs. |
| src/Mindee/V2/FileOperations/Split.cs | Renames/adjusts split API to ExtractMultipleSplits returning ExtractedPdfs. |
| src/Mindee/V2/FileOperations/CropFiles.cs | Removes V2-specific crop collection helper in favor of shared ExtractedImages. |
| src/Mindee/V2/FileOperations/Crop.cs | Renames/adjusts crop API to ExtractMultipleCrops returning ExtractedImages. |
| src/Mindee/V1/Parsing/Standard/PositionField.cs | Implements IPositionDataField to work with generic extraction methods. |
| src/Mindee/V1/Image/ImageExtractor.cs | Aligns constructor signature with base extractor changes (removes saveFormat arg). |
| src/Mindee/Pdf/ExtractedPdfs.cs | Adds shared PDF collection type with batch disk persistence helper. |
| src/Mindee/Pdf/ExtractedPdf.cs | Adds PageIndexes, shifts to PageCount property usage, tightens WriteToFile semantics. |
| src/Mindee/Image/ExtractedImages.cs | Adds shared image collection type with batch disk persistence helper. |
| src/Mindee/Image/ExtractedImage.cs | Makes ids readonly and simplifies WriteToFile signature/behavior. |
| src/Mindee/Geometry/IPositionDataField.cs | Introduces common interface for “positionable” fields (polygon). |
| src/Mindee/Extraction/PdfExtractor.cs | Centralizes extracted PDF naming via MakeFilename and attaches page metadata. |
| src/Mindee/Extraction/ImageExtractor.cs | Introduces generic extraction APIs working over IPositionDataField. |
| .github/workflows/_test-units.yml | Removes net6.0 from unit test matrix; keeps newer TFMs. |
Review details
- Files reviewed: 22/22 changed files
- Comments generated: 6
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
54
to
+63
| /// <summary> | ||
| /// Writes the image to a file. | ||
| /// If outputPath has an extension, it is treated as a full file path. | ||
| /// Otherwise, it is treated as a directory and uses the default filename. | ||
| /// </summary> | ||
| /// <param name="outputPath">The output directory (must exist) or full file path.</param> | ||
| /// <param name="quality">The quality of the image. Defaults to 100.</param> | ||
| /// <param name="fileFormat">The desired format. If null, inferred from extension or default.</param> | ||
| public void WriteToFile(string outputPath, int quality = 100, string fileFormat = null) | ||
| public void WriteToFile(string outputPath) | ||
| { | ||
| string imagePath; | ||
| var targetFormat = fileFormat ?? _saveFormat; | ||
|
|
||
| if (Path.HasExtension(outputPath)) | ||
| { | ||
| imagePath = outputPath; | ||
| if (string.IsNullOrWhiteSpace(fileFormat)) | ||
| { | ||
| var extension = Path.GetExtension(outputPath).TrimStart('.'); | ||
| if (!string.IsNullOrWhiteSpace(extension)) | ||
| { | ||
| targetFormat = extension.ToLower(); | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| var finalFilename = Filename; | ||
| if (!string.IsNullOrWhiteSpace(fileFormat)) | ||
| { | ||
| var nameWithoutExtension = Path.GetFileNameWithoutExtension(Filename); | ||
| finalFilename = $"{nameWithoutExtension}.{targetFormat.ToLower()}"; | ||
| } | ||
| imagePath = Path.Combine(outputPath, finalFilename); | ||
| } | ||
| if (!Directory.Exists(outputPath)) | ||
| throw new DirectoryNotFoundException($"Directory does not exist: {outputPath}"); |
Comment on lines
+29
to
+35
| public void SaveAllToDisk(string outputPath) | ||
| { | ||
| foreach (var extractedImage in this) | ||
| { | ||
| extractedImage.WriteToFile(outputPath); | ||
| } | ||
| } |
Comment on lines
+51
to
+53
| PageCount = pageIndexes.Count; | ||
| Filename = LocalInput.Filename; | ||
| PageIndexes = pageIndexes; |
Comment on lines
+25
to
+35
| /// <summary> | ||
| /// Save all extracted images to disk. | ||
| /// </summary> | ||
| /// <param name="outputPath"></param> | ||
| public void SaveAllToDisk(string outputPath) | ||
| { | ||
| foreach (var extractedPdf in this) | ||
| { | ||
| extractedPdf.WriteToFile(outputPath); | ||
| } | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Types of changes