Adding handling when pageWords count = 0 for IPageSegmenters

This commit is contained in:
BobLd
2019-09-04 22:14:08 +01:00
parent 68e04603c0
commit d36dee0e25
2 changed files with 6 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using UglyToad.PdfPig.Content; using UglyToad.PdfPig.Content;
using UglyToad.PdfPig.Geometry; using UglyToad.PdfPig.Geometry;
using UglyToad.PdfPig.Util;
namespace UglyToad.PdfPig.DocumentLayoutAnalysis namespace UglyToad.PdfPig.DocumentLayoutAnalysis
{ {
@@ -47,6 +48,8 @@ namespace UglyToad.PdfPig.DocumentLayoutAnalysis
public IReadOnlyList<TextBlock> GetBlocks(IEnumerable<Word> pageWords, double wlAngleLB, double wlAngleUB, public IReadOnlyList<TextBlock> GetBlocks(IEnumerable<Word> pageWords, double wlAngleLB, double wlAngleUB,
double blAngleLB, double blAngleUB, double blMultiplier) double blAngleLB, double blAngleUB, double blMultiplier)
{ {
if (pageWords.Count() == 0) return EmptyArray<TextBlock>.Instance;
var pageWordsArr = pageWords.Where(w => !string.IsNullOrWhiteSpace(w.Text)).ToArray(); // remove white spaces var pageWordsArr = pageWords.Where(w => !string.IsNullOrWhiteSpace(w.Text)).ToArray(); // remove white spaces
var withinLineDistList = new ConcurrentBag<double[]>(); var withinLineDistList = new ConcurrentBag<double[]>();

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UglyToad.PdfPig.Content; using UglyToad.PdfPig.Content;
using UglyToad.PdfPig.Util;
namespace UglyToad.PdfPig.DocumentLayoutAnalysis namespace UglyToad.PdfPig.DocumentLayoutAnalysis
{ {
@@ -64,6 +65,8 @@ namespace UglyToad.PdfPig.DocumentLayoutAnalysis
Func<IEnumerable<decimal>, decimal> dominantFontWidthFunc, Func<IEnumerable<decimal>, decimal> dominantFontWidthFunc,
Func<IEnumerable<decimal>, decimal> dominantFontHeightFunc) Func<IEnumerable<decimal>, decimal> dominantFontHeightFunc)
{ {
if (pageWords.Count() == 0) return EmptyArray<TextBlock>.Instance;
XYLeaf root = new XYLeaf(pageWords); // Create a root node. XYLeaf root = new XYLeaf(pageWords); // Create a root node.
XYNode node = VerticalCut(root, minimumWidth, dominantFontWidthFunc, dominantFontHeightFunc); XYNode node = VerticalCut(root, minimumWidth, dominantFontWidthFunc, dominantFontHeightFunc);