Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - How to determine if text will fit in memo
  FAQ FAQ  Forum Search   Register Register  Login Login

How to determine if text will fit in memo

 Post Reply Post Reply
Author
Message
waynefulcher View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Jun 08
Location: United States
Status: Offline
Points: 99
Post Options Post Options   Thanks (0) Thanks(0)   Quote waynefulcher Quote  Post ReplyReply Direct Link To This Post Topic: How to determine if text will fit in memo
    Posted: 18 May 18 at 2:34AM
I have a memo field on a prebuilt PDF form. I want to determine if some text will fit in the memo when being printed.
Is there an easy way to do this? if not is there a long drawn out way to do this?
From my searching and writing test code there is no way to know if the text will all fit in a memo field.
My long drawn out way always comes up short due to a lack of information that I can't seem to get using QPDF library.

I perform the following steps:
1. Open the PDF file with the memo field.
2. Get the memo field's font, text size, width and height.
3. Call the SelectFont() method for the font ID used by memo 
4. SetTextSize to the TextSize used by memo field.
4. I then loop through text one word at a time calling GetTextWidth().
5. Once words no longer fit I add 1 to my line count and start over with the last word that didn't fit.
6. Once I am done I try to determine if the combined height of all lines would fit within the height of the memo.

There are several problems with trying to do this manually but to keep this post focused on a single issue I will only list the main problem.
There is no way to get the vertical line space a memo uses "between lines" so all I know that I can do to compute the height of all lines of text would be to do:
    totalHeight := (PDF.GetTextHeight * LineCount) ;
This results in a smaller number than it would if you added in line spacing.
I searched and there is no way to get this line spacing value as far as I can find.

Any help would be greatly appreciated.

Thanks
Wayne







Back to Top
rweetch View Drop Down
Senior Member
Senior Member


Joined: 22 Feb 11
Status: Offline
Points: 173
Post Options Post Options   Thanks (1) Thanks(1)   Quote rweetch Quote  Post ReplyReply Direct Link To This Post Posted: 18 May 18 at 8:49AM
would an approach like this help?

procedure TsmDebenuPDFLibraryHelper.DrawDownScaledText(const aText: string; const X, Y aWidth, aHeight: Double);
var lTextSize, lStartSize: Double;
begin

  lStartSize := GetTextSize;
  lTextSize := lStartSize;

  if GetWrappedTextHeight(aWidth, aText) > aHeight then
  begin
    
     lTextSize := lStartSize;

    repeat

       lTextSize := lTextSize * 0.95;

       SetTextSize(lTextSize);

       until (GetWrappedTextHeight(aWidth, aText) <= aHeight);

  end;

  DrawWrappedText(X, Y, aWidth, aText);

   if lTextSize < lStartSize then
      SetTextSize(lStartSize);

end;


Back to Top
waynefulcher View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Jun 08
Location: United States
Status: Offline
Points: 99
Post Options Post Options   Thanks (0) Thanks(0)   Quote waynefulcher Quote  Post ReplyReply Direct Link To This Post Posted: 18 May 18 at 2:26PM
WOW, I must have spent 8 hours working on this problem yesterday and thought I read every method from the docs like 3 times..... Somehow I never saw the method GetWrappedTextHeight().
Dang that was easy, thanks for the pointer.


Back to Top
rweetch View Drop Down
Senior Member
Senior Member


Joined: 22 Feb 11
Status: Offline
Points: 173
Post Options Post Options   Thanks (0) Thanks(0)   Quote rweetch Quote  Post ReplyReply Direct Link To This Post Posted: 18 May 18 at 3:21PM
there's just so much in there it's easy to miss the wood for the trees.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store