Do you own a Debenu Quick PDF Library 12/11/10/9/8/7? Upgrade to Debenu Quick PDF Library 13!

Foxit Quick PDF Library

Frequently Asked Question:

Return to FAQ Index

How do I get the width and height of text that’s already in a PDF?

Question

How do I get the width and height of text that's already in a PDF?

Answer

A few steps are required in order to be able to programatically find out the width and height of text that's in a PDF. The required steps and functions have been outlined below.

  1. Using the GetPageText function (with ExtractOptions parameter 2, 3 or 4) extract the font name, text size and text from the PDF.
  2. Analyze the output from the GetPageText function to find the relevant text and corresponding font name and text size.
  3. Now use the FindFonts, FontCount, GetFontID and SelectFont functions to select the font name found in step 2.
  4. Once the font has been selected use the SetTextSize function to setup the font.
  5. You can then use GetTextWidth and GetTextHeight to return the correct width and height.

That's it. You should now be able to determine the width and height of a piece of text from an existing PDF. If you wanted to take it a step further you could use the additional information that was retrieved by the GetPageText function such as the bounding area of the text to highlight the text or perfomr some other action.

Sidenote: Instead of the GetPageText function you could also have used the DAExtractPageText function or the ExtractFilePageText function.


© 2015 Debenu & Foxit. All rights reserved. AboutBuyContactBlogNewsletterSupportFAQProduct UpdatesForum