I have a pdf documentation where hundreds of CNC patameters are explained. I have a C# code
where I
-
find the related parameter definition word and the correct page number
-
call a method with this two parameters and get the X,Y positions
-
add then the named destinations according to these positions.
In general it works fine. But my problem is the part 2). With my current knowledge I can just pass the page number and the parameter name for searching the X and Y Position. But when in the related page there is another line with the same word, then my code finds always the first one and gets the X,Y positions of this one. How can I improve my code by getting the position of the parameter name just in a specific line?
My current code is:
public void get_position_of_string_in_PDF(string sys_var_definition ,Int32 page_no , out float X_Pos, out float Y_Pos )
{
using (var reader = new PdfReader(@"C:inetpubwmi_aspwwwrootfilesMTXMacodaV14.pdf"))
{
var parser = new PdfReaderContentParser(reader);
var strategy = parser.ProcessContent(page_no, new LocationTextExtractionStrategyWithPosition());
var res = strategy.GetLocations();
reader.Close();
var searchResult = res.Where(p => p.Text.Contains(sys_var_definition)).OrderBy(p => p.Y).Reverse().ToList();
X_Pos = searchResult[0].X;
Y_Pos = searchResult[0].Y+50;
Sys_VAR_dest_name_Pos_X_array.Add(X_Pos);
Sys_VAR_dest_name_Pos_Y_array.Add(Y_Pos);
}
}
I want to extend the method with “line no”. So the method definition would be:
public void get_position_of_string_in_PDF(string sys_var_definition ,Int32 page_no , int line_no, out float X_Pos, out float Y_Pos )
I know that itextsharp is alittle bit outdated but currently I am using it on many places in my project, so that I cannot change it immediatly.