Get text occurrences contained in a specified area with iTextSharp

前端 未结 2 1485
小鲜肉
小鲜肉 2021-02-10 00:12

Is it possible, using iTextSharp, get all text occurrences contained in a specified area of ​​a pdf document?

2条回答
  •  借酒劲吻你
    2021-02-10 00:40

    First you need the actual coordinates of the rectangle you marked in Red. On sight, I'd say the x value 144 (2 inches) is probably about right, but it would surprise me if the y value is 76, so you'll have to double check.

    Once you have the exact coordinates of the rectangle, you can use iText's text extraction functionality using a LocationTextExtractionStrategy as is done in the ExtractPageContentArea example.

    For the iTextSharp version of this example, see the C# port of the examples of chapter 15.

    System.util.RectangleJ rect = new System.util.RectangleJ(70, 80, 420, 500);
    RenderFilter[] filter = {new RegionTextRenderFilter(rect)};
    ITextExtractionStrategy strategy = new FilteredTextRenderListener(
            new LocationTextExtractionStrategy(), filter);
    text = PdfTextExtractor.GetTextFromPage(reader, 1, strategy);
    

提交回复
热议问题