Skip to content

♻️ harmonize image and PDF extraction - #426

Open
ianardee wants to merge 4 commits into
mainfrom
fix-file-operations
Open

♻️ harmonize image and PDF extraction#426
ianardee wants to merge 4 commits into
mainfrom
fix-file-operations

Conversation

@ianardee

@ianardee ianardee commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Description

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Requires a change to the official Guide documentation.

@ianardee ianardee changed the title Fix file operations ♻️ harmonize image and PDF extraction Aug 7, 2026
@ianardee
ianardee force-pushed the fix-file-operations branch 9 times, most recently from 9cbaefe to 22e0e92 Compare August 7, 2026 15:26
@ianardee
ianardee force-pushed the fix-file-operations branch from 22e0e92 to fa86e07 Compare August 11, 2026 13:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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/SplitFiles with shared ExtractedImages/ExtractedPdfs and 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);
}
}
Comment thread tests/Mindee.UnitTests/V2/FileOperations/CropTest.cs
Comment thread tests/Mindee.UnitTests/V2/FileOperations/SplitTest.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants