IN THIS FOLLOWING CODE WHEN, CONDITION IS TRUE ITS DELETING THE SPECIFIC BLOCK BUT WHEN CONDITION IS FALSE IT SHOWS "IArguments check failed. Expected: index >= 0 && index < getCount() " ERROR
for(int i=0;i<frPages.getCount();i++)
{
ILayout layout=frPages.Item(i).getLayout();
for(int j=0;j<layout.getBlocks().getCount();j++)
{
IBlock block=layout.getBlocks().Item(j);
if(block.getType()==BlockTypeEnum.BT_Text)
{
ITextBlock tblock=block.GetAsTextBlock();
IParagraphs paras=tblock.getText().getParagraphs();
for(int k=0;k<paras.getCount();k++)
{
IParagraph para=paras.Item(k);
for(int l=0;l<para.getWords().getCount();l++)
{
IWord word=para.getWords().Item(l);
String wd=word.getText();
boolean b=wd.contains("LEGAL");
if(b==false)
{
layout.getBlocks().DeleteAt(j);
}
}
}
}
}
}
コメント
1件のコメント
It is not clear what you want to delete and what you would like to get as result. Could you please to describe your scenario in details?
At the moment you get the error "IArguments check failed. Expected: index >= 0 && index < getCount() ", because when you delete a block you do not change the count of the blocks, and in some moment the program try to access to an inexistent block.
If you want to delete the blocks that do not contain the "LEGAL" word, the code in C# may look in the following way:
...
// Recognize document
displayMessage( "Recognizing..." );
document.Analyze ( null );
document.Recognize ( null );
FREngine.IFRPages frPages = document.Pages;
for (int i = 0; i < frPages.Count; i++)
{
FREngine.ILayout layout = frPages.Item(i).Layout;
int blocksCount = layout.Blocks.Count;
for (int j = 0; j < blocksCount; j++)
{
FREngine.IBlock block = layout.Blocks.Item(j);
bool b = true;
if (block.Type == FREngine.BlockTypeEnum.BT_Text)
{
FREngine.ITextBlock tblock = block.GetAsTextBlock();
FREngine.IParagraphs paras = tblock.Text.Paragraphs;
for (int k = 0; k < paras.Count; k++)
{
FREngine.IParagraph para = paras.Item(k);
for (int l = 0; l < para.Words.Count; l++)
{
FREngine.IWord word = para.Words.Item(l);
String wd = word.Text;
b = wd.Contains("LEGAL");
if (b) break;
}
}
}
if (b == false)
{
layout.Blocks.DeleteAt(j);
blocksCount--;
}
}
}
document.Synthesize ( null );
...
サインインしてコメントを残してください。