transform pdf points to pixels, worked correctly: point-to-pixel = 1/72*300(DPI)
- getting each text chunk positions (X,Y) in PDF the Y is calculated from
bottom-to-top, not as in standard html or java Script. - to get the Y value from top-to-down , cause not accurate Y position as in
html style , or win Form style. how to get the correct Y top-to-down using any Page height, or rect mediaBox
or cropBox or rect textMarging finder ?the code I used is your example of :
public class LocationTextExtractionStrategyClass : LocationTextExtractionStrategy { //Hold each coordinate public List<RectAndText> myPoints = new List<RectAndText>(); /* //The string that we're searching for public String TextToSearchFor { get; set; } //How to compare strings public System.Globalization.CompareOptions CompareOptions { get; set; } public MyLocationTextExtractionStrategy(String textToSearchFor, System.Globalization.CompareOptions compareOptions = System.Globalization.CompareOptions.None) { this.TextToSearchFor = textToSearchFor; this.CompareOptions = compareOptions; } */ //Automatically called for each chunk of text in the PDF public override void RenderText(TextRenderInfo renderInfo) { base.RenderText(renderInfo); //See if the current chunk contains the text var startPosition = 0;// System.Globalization.CultureInfo.CurrentCulture.CompareInfo.IndexOf(renderInfo.GetText(), this.TextToSearchFor, this.CompareOptions); //If not found bail if (startPosition < 0) { return; } //Grab the individual characters var chars = renderInfo.GetCharacterRenderInfos().ToList();//.Skip(startPosition).Take(this.TextToSearchFor.Length) var charsText = renderInfo.GetText(); //Grab the first and last character var firstChar = chars.First(); var lastChar = chars.Last(); //Get the bounding box for the chunk of text var bottomLeft = firstChar.GetDescentLine().GetStartPoint(); var topRight = lastChar.GetAscentLine().GetEndPoint(); //Create a rectangle from it var rect = new iTextSharp.text.Rectangle( bottomLeft[Vector.I1], bottomLeft[Vector.I2], topRight[Vector.I1], topRight[Vector.I2] ); BaseColor curColor = new BaseColor(0f, 0f, 0f); if (renderInfo.GetFillColor() != null) curColor = renderInfo.GetFillColor(); //Add this to our main collection myPoints.Add(new RectAndText(rect, charsText, curColor));//this.TextToSearchFor)); } }//end-of-txtLocation-class//