Question
How to extract data that could be located on the different lines between two keywords?
Answer
In such scenarios, necessary data could be extracted using the FlexiLayout language and Advanced pre-search relations feature.
Create the Static Text elements for keywords to the left and right of the data, these keywords will be used as reference elements to specify the search area for the Region element that will extract the data:
Then create the Region element, and define the search area with the following code in the Advanced pre‑search relations:
if kwRight.Top > kwLeft.Bottom then
{
RectArray RA = RectArray();
RA.Add(Rect(kwLeft.Right.Start, kwLeft.Top.Start - 10dt, PageRect.Right, (kwLeft.Bottom.Start + kwRight.Top.Start)/2));
RA.Add(Rect(PageRect.Left, (kwLeft.Bottom.Start + kwRight.Top.Start)/2, kwRight.Left.Start, kwRight.Bottom.Start + 10dt));
RSA: RA.Region;
}
else
{
RSA: Rect(kwLeft.Right.Start, kwLeft.Top.Start - 10dt,kwRight.Left.Start ,kwRight.Bottom.Start + 10dt);
}
The following condition is comparing the bottom of the "Sr(a)" keyword and the top of the "R.U.T" keyword.
if kwRight.Top > kwLeft.Bottom then
The (0,0) origin is located in the top left‑hand corner of the image. X‑coordinates increase left to right, Y‑coordinates increase top to bottom. According to this if the search text is wrapped into the next line, the top of the "R.U.T" keyword is located "higher" on the Y‑axis than the bottom of "Sr(a)", therefore its coordinates is "bigger" than the coordinates of the bottom of "Sr(a)".
If the condition is true, we need to search text on different lines.
It can be done by using RectArray, this function defines the search area as an array of rectangles.
This line is used to create an empty array of rectangles with the name "RA".
RectArray RA = RectArray();
"Rects" are used to specify the boundaries of rectangles for each text line. This function defines a rectangle from specified coordinates:
Rect Rect( XCoordinate left, YCoordinate top, XCoordinate right, YCoordinate bottom )
The rectangle for the text line with left keyword:
1. kwLeft.Right.Start -"Sr(a)" keyword's right boundary coordinates are used to define the left rectangle boundary.
2. kwLeft.Top.Start - 10dt - "Sr(a)" keyword's top boundary coordinates with 10 dots indent are used to define top rectangle boundary.
3. PageRect.Right - the coordinates of the page right boundary are used to define the right rectangle boundary.
4. (kwLeft.Bottom.Start + kwRight.Top.Start)/2) - the coordinates of the middle between the text lines are used to define the bottom rectangle boundary.
The rectangle for the text line with the right keyword:
1. PageRect.Left - the coordinates of the page left boundary are used to define the left rectangle boundary.
2. (kwLeft.Bottom.Start + kwRight.Top.Start)/2 - the coordinates of the middle between the text lines are used to define the top rectangle boundary.
3. kwRight.Left.Start - "R.U.T" keyword's left boundary coordinates are used to define the left rectangle boundary.
4. kwRight.Bottom.Start + 10dt - "R.U.T" keyword's bottom boundary coordinates with 10 dots indent are used to define top rectangle boundary.
The RestrictSearchArea function is used to specify the boundaries of the search area of the current element.
RSA: RA.Region;
In our case, these are the boundaries of the created above rectangles from the "RA" variable.
If the necessary data is located only on a single text line the following rectangle is used to specify the search area:
RSA: Rect(kwLeft.Right.Start, kwLeft.Top.Start - 10dt,kwRight.Left.Start ,kwRight.Bottom.Start + 10dt);
The example of getting necessary text in FlexiLayout:
Comments
0 comments
Please sign in to leave a comment.