-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabled ClipPaths option to filter letters. (#905)
* Enabled ClipPaths option to filter letters. * parsingOptions is not passed as an argument now.
- Loading branch information
Showing
8 changed files
with
83 additions
and
19 deletions.
There are no files selected for viewing
Binary file added
BIN
+835 KB
src/UglyToad.PdfPig.Tests/Integration/Documents/ClipPathLetterFilter-Test1.pdf
Binary file not shown.
Binary file added
BIN
+257 KB
src/UglyToad.PdfPig.Tests/Integration/Documents/ClipPathLetterFilter-Test2.pdf
Binary file not shown.
46 changes: 46 additions & 0 deletions
46
src/UglyToad.PdfPig.Tests/Integration/LetterFilterTests.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
namespace UglyToad.PdfPig.Tests.Integration | ||
{ | ||
using System.Linq; | ||
|
||
public class LetterFilterTests | ||
{ | ||
[Fact] | ||
public void CanFilterClippedLetters() | ||
{ | ||
var one = IntegrationHelpers.GetDocumentPath("ClipPathLetterFilter-Test1.pdf"); | ||
|
||
using (var doc1 = PdfDocument.Open(one, new ParsingOptions { ClipPaths = true })) | ||
using (var doc2 = PdfDocument.Open(one, new ParsingOptions { ClipPaths = false })) | ||
{ | ||
var allLetters = doc2.GetPage(5).Letters.Count; | ||
var filteredLetters = doc1.GetPage(5).Letters.Count; | ||
|
||
Assert.True(filteredLetters < allLetters, | ||
"Expected filtered letter count to be lower than non-filtered"); // Filtered: 3158 letters, Non-filtered: 3184 letters | ||
} | ||
} | ||
|
||
[Fact] | ||
public void CanFilterClippedLetters_CheckBleedInSpecificWord() | ||
{ | ||
var one = IntegrationHelpers.GetDocumentPath("ClipPathLetterFilter-Test2.pdf"); | ||
|
||
using (var doc1 = PdfDocument.Open(one, new ParsingOptions { ClipPaths = true })) | ||
using (var doc2 = PdfDocument.Open(one, new ParsingOptions { ClipPaths = false })) | ||
{ | ||
var allWords = doc2.GetPage(1).GetWords().ToList(); | ||
var filteredWords = doc1.GetPage(1).GetWords().ToList(); | ||
|
||
// The table has hidden columns at the left end. Letters from these columns get merged in words | ||
// which is incorrect. Filtering letters based on clip path should fix that... | ||
const string wordToSearchAfterWhichTheActualTableStarts = "ARISER"; | ||
|
||
var indexOfCheckedWordInAllWords = allWords.FindIndex(x => x.Text.Equals(wordToSearchAfterWhichTheActualTableStarts)) + 1; | ||
Assert.True(allWords[indexOfCheckedWordInAllWords].Text == "MLIA0U01CP00O0I3N6G2"); | ||
|
||
var indexOfCheckedWordInFilteredWords = filteredWords.FindIndex(x => x.Text.Equals(wordToSearchAfterWhichTheActualTableStarts)) + 1; | ||
Assert.True(filteredWords[indexOfCheckedWordInFilteredWords].Text == "ACOGUT"); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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