Skip to main content
Participant
Mar 10, 2018 5:54 PM UTC
Answered

How can I detect the fontsize of a character in a pdf document using javascript

I would like to automatically identify and edit the headlines of pdf text documents (newspaper articles). As the fontsize of headlines use to be larger than the text body, I could identify the beginning and the end of a headline by screening the fontsize changes of characters. Unfortunatelly I have not yet found a javascript method of dectecting fontsizes, while this information is provided in the UI - even for proprietary fonts. Can anybody help?

This topic is closed to new replies. Start a new post to keep the conversation going.
Thom Parker
Thom ParkerCorrect answer
Community Expert
Mar 10, 2018 6:11 PM UTC

Use the "doc.getPageNthWordQuads()" function.  It returns 4 points, one for each corner of the bounding box of a word on the page. The height of this box is the font size.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often

3 replies

try67
Community Expert
Community Expert
Mar 10, 2018 8:47 PM UTC

You can't edit static text using a script, though. Not directly, anyway.

Translate
Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
Mar 10, 2018 6:11 PM UTC

Use the "doc.getPageNthWordQuads()" function.  It returns 4 points, one for each corner of the bounding box of a word on the page. The height of this box is the font size.

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
Mar 11, 2018 1:03 AM UTC

Many thanks for this advice. It works perfectly.

Translate