Calculate the x & y coords, width and height of specific piece of text inside a PDF document
On my website, I display uploaded PDF files in a flash player for my users to read.
I already use various tools to extract the text and produce a serious of high quality images from the file and the system works well.
The last piece of the puzzle is to be able to highlight specific parts of the document to help users with accessibility issues.
However I cannot figure out how to calculate where the specific text is positioned on the page?
Notes:
- The documents uploade开发者_JAVA百科d to the system are from 3rd parties, so fonts may be embedded. Meaning that I cannot be sure of the width of specific letters.
- The text to be highlighted may not be unique, the same text may be repeated
How can I calculate the coordinates, height and width of a specific piece of text on a PDF, so that I can then draw a box around it?
I have used an SDK called QuickPDF from www.quickpdf.com for a recent project.
They have a function called ExtractFilePageText() that can return the text, font, bounding box coordinates.
The extraction options include :-
0 = Extract text in human readable format 2 = Return a CSV string including font, color, size and position of each piece of text on the page Using the more accurate text extraction algorithm: 3 = Return a CSV string for each piece of text on the page with the following format: Font Name, Text Color, Text Size, X1, Y1, X2, Y2, X3, Y3, X4, Y4, Text The co-ordinates are the four points bounding the text, measured in points (1/72 inch) with the bottom-left corner of the page as the origin 4 = Similar to option 3, but individual words are returned, making searching for words easier.
There is a Developer License required but no runtime royalties. It has many other useful features and works with many languages. The documentation is pretty good also.
精彩评论