Agreed. In our reconstruction of the scientific content of technical documents from PDF (AMI2, http://www.bitbucket.org/petermr/ami2 ) we throw away all character groupings from the PDF - render each to SVG with its coordinates and other attributes (stroke, font-size, etc.) This is because there is no consistency in how PDF tools create character grouping - they are often split at kerning points rather than whitespace - and they may be boustrophedonic (http://dictionary.reference.com/browse/boustrophedonic ). The only reliable strategy is the extract the coordinates, font size and (hopefully) the width of the character. This allows phrases to be generated. Creating sentences and paragraphs, lists and tables is hard and discipline-dependent (think about hyphenation).
The positive side of doing this is that when you only have pixel information (about half the diagrams we see) then you have to reconstruct the characters by OCR. The result of this then merges with the character-based approach. BTW if anyone has a good pointer to an Open Pure Java OCR tool we'd be delighted as I'm hacking my own (there are ancillary reasons for this). Tesseract is not Pure Java, JavaOCR has become very complex and Lookup doesn't seem to provide fonts. Currently we are hacking this from a few high-quality sets of glyphs (such as Wikipedia entries). Maybe we should be using the outline glyphs? On Fri, Mar 7, 2014 at 4:55 AM, Maruan Sahyoun <[email protected]>wrote: > Hi, > > you could use PDFStreamEngine and overwrite > http://pdfbox.apache.org/docs/1.8.4/javadocs/org/apache/pdfbox/util/PDFStreamEngine.html#processTextPosition%28org.apache.pdfbox.util.TextPosition%29 > > this gives you the position of all characters. You would then need to > match/compare these to the string pattern you are looking for accumulating > the positions. After that you would have the area covered by the string > which you could use to e.g. overlay a button and/or link element. > > BR > Maruan Sahyoun > > Am 06.03.2014 um 21:30 schrieb Olaf Drümmer <[email protected]>: > > > You could use x and y position and rotation information to determine > whether two given characters - given their size - are relatively close to > each other or not and are on the same line. > > > > BT / ET is not at all guaranteed to give you strings as perceived by a > human. > > > > Olaf > > > > > > Am 6 Mar 2014 um 21:06 schrieb HQS <[email protected]>: > > > >> Well, thanks sirs for your reactivity. > >> > >> The PDFs are generated by Autodesk Inventor (even the latest version > produces that kind of output). > >> > >> It is for one of my clients who wants an automatic transformation > >> of some specific strings in the PDF into a clickable link. > >> > >> My problem is very simple : with such a structure I have no way to know > when the string ends. > >> > >> As a matter of fact all the references to be transformed are prefixed > >> with an 'I-' but there is no termination character, for instance : << > I-HOIST-042 >>. > >> Given that in the PDF I, -, H, O, (etc.), 2 are separated characters I > cannot rebuild the original string. > >> > >> I was hoping that there is a block of text (BT ... ET) but, as I > mentioned, each character is put in its own block... > >> > >> Regards, > >> > >> > >> Le 6 mars 2014 à 18:57, Maruan Sahyoun <[email protected]> a > écrit : > >> > >>> Hi Julien, > >>> > >>> for 1) that's possible and supported - how was the document generated? > DTP application? > >>> for 2) PDFBox doesn't enforce a PDF version. In general it supports > all PDF files but it doesn't have full coverage of all features defined > within certain PDF versions but it should have a reasonable coverage. There > is no documentation on coverage yet so I can't guarantee that a specific > feature is supported. Is there something special you are looking for? > >>> > >>> BR > >>> Maruan Sahyoun > >>> > >>> Am 06.03.2014 um 18:39 schrieb HQS <[email protected]>: > >>> > >>>> Hello all, > >>>> > >>>> 1. > >>>> Have you ever seen PDFs having this kind of (pseudo) structure : > >>>> > >>>> BT > >>>> <character> > >>>> Tj > >>>> ET > >>>> > >>>> ? > >>>> > >>>> Which means, the strings are split into characters and there is one > block of text per character ? > >>>> It seems to be ill-formed doesn't it ? > >>>> > >>>> 2. Reminder of my first mail, what is the library compliancy > regarding PDF standards ? 1.3 to 1.7 ? > >>>> > >>>> > >>>> Thanks and regards > >>>> > >>>> Julien > >>>> > >>> > >> > > > > -- Peter Murray-Rust Reader in Molecular Informatics Unilever Centre, Dep. Of Chemistry University of Cambridge CB2 1EW, UK +44-1223-763069

