[Python] Relating icons to the texts in PDF files

Discussão em 'Python' iniciado por Stack, Agosto 28, 2025.

  1. Stack

    Stack Membro Participativo

    I have large number of PDF files that are generated from a system. The PDF files are about Customer surveys and document the yes, no, may be kind of responses and assigns traffic light icons like Red, Green and Orange which indicates criticality based on the response itself. These responses are also grouped by so called Dimensions and each response has some weightage based on which traffic lights are calculated at the Dimension level as well.

    These traffic lights along with the respones are unfortunately not stored in any database table but only generated by an application and its logic calculates Red, Green or Orange based on some configurable tables. So basically the result of calculation is only stored in the PDF file. These PDF files are shared with the Customers as counter feedback and having explanations of implication of their response and recommendations.

    So now I am confronted with thousands of PDF files containing Customer surveys with Dimensions as Section Headers and Responses as subsections with both having Red, Green or Orange icon assigned to it towards the right of the response/dimension text.

    My challenge is to search for the Red, Green and Orange icons (these can be downloaded as PNG files and can be searched by their Height/Width, or by their Shape or Color hue) and then associate them with the line of text to their left side. So basically, input will be thousand of PDF files, the Red, Green and Orange icon PNG files and the Output is an Excel containing Red, Green, Orange mapped to texts that lie on the same line as the traffic light icons.

    I tried both PowerShell and Python libraries for PyMuPDF/Fitz, Pandas etc but the problem I am facing is that the images are placed by coordinates and the lines have their own placing mechanism (based on line/paragraph spacing). Even though it looks straight forward in the PDF, seeing a line of text and a traffic light icon to the right of it, internally both are placed in different ways and there is no correspondence between the both. I also tried trying to relate PDF page numbers with the Red, Green and Orange icon occurrences within each page, here also the Icon placement don't have correspondence with pages the way we see it in display. In fact each icon is stored only once in the pdf and its reference is related to a different mechanism of placement by coordinates that has no relation with pages. My idea was to relate the Texts and Icons both to Page numbers and then use some logic to relate them

    I also tried Grok, OpenAI and both hit stone walls, the scripts they are generating although match the icons files, they are not able to associate them with the line of text beside them

    Is there someway to achieve what I am trying to do here?

    Continue reading...

Compartilhe esta Página