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 - Fit Text to a non regular shape
  FAQ FAQ  Forum Search   Register Register  Login Login

Fit Text to a non regular shape

 Post Reply Post Reply
Author
Message
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 Topic: Fit Text to a non regular shape
    Posted: 30 Jun 11 at 6:02PM
I have an area on my pdf which is to be populated with text. This isn't a regular shape and the top and bottom rows are about 60% the width of the centre section so the text would need to be something like
 
            here is some
text that needs to
fit into a very strange
shape
 
and it needs to be filled from the middle out.
 
I thought of defining 3 areas. But how to decide what text to place in what area.....
 
Any ideas very gratefully received!
Back to Top
Rowan View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 10 Jan 09
Status: Offline
Points: 398
Post Options Post Options   Thanks (0) Thanks(0)   Quote Rowan Quote  Post ReplyReply Direct Link To This Post Posted: 30 Jun 11 at 8:49PM
Well that is kind of tricky. It might be that you have to make a call to DrawText for each line. I'm not sure how else you can do this, unless you were to use the DrawHTMLTextBox function and use the space HTML tag to indent the text, but this would require a bit of trial and error to get the indenting right, while matching the width and height of the text box and font size.
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: 01 Jul 11 at 11:18AM
Thansk Rowan. Thinking along similar path. My Idea is to use DrawTextBox to draw the text. General approach is:
 
1. Find Lines per Box (something like Box Height / Text Height)
2. Find out how many lines the text will take (GetTextWrappedLineCount)
3. If LineCount is Greater than LinesPerBox - 2 then
4. Calculate textWidth of a space character
5. Pack the fron of the text with the required number of spaces.
 
probably need to do some iterations.
 
Does that sound sane?
 
Back to Top
Rowan View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 10 Jan 09
Status: Offline
Points: 398
Post Options Post Options   Thanks (0) Thanks(0)   Quote Rowan Quote  Post ReplyReply Direct Link To This Post Posted: 01 Jul 11 at 11:48AM
Your approach sounds good but you may need to use the DrawHTMLTextBox function and explicitly insert the spaces because otherwise I believe they will automatically be removed. Much like in HTML where there is only ever one space between two words unless you explicitly insert a space tag.
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: 10 Aug 11 at 4:34PM
Out of interest the final solution for this was as follows. The area to be filled is specified by a formfield, but this is just a place holder and not used except to get height, width, font etc.
 
1. Find Lines available per box (Box Height / Text Height)
2. Break the text into lines using the GetWrappedText method
3. Calculate the width of the first line (60% of the box width)
4. Get the text width of the first line
5. if it is too wide for the first line then use GetWrappedText to find out how much will fit. Add the remaining text back to the rest of the text and run through GetWrappedText again to get the remaining lines.
6. write the text to the document using DrawTextBox for each line, setting alignment as necessary.
 
code if you are interested:
//uW := width of field
       ts := TStringlist.Create;
       try
         ts.Text := PDFLibrary.GetWrappedText(uW, #13#10, uText);  
         nW := uW * 0.6;
         if PDFLibrary.GetTextWidth(ts[0]) > nW then
         begin
           js := TStringList.Create;
           try
             js.Text := PDFLibrary.GetWrappedText(nW, #13#10, ts[0]);
             ts.Clear;
             ts.Text := PDFLibrary.GetWrappedText(nW, #13#10, copy(uText, length(js[0]) + 1, length(uText)));
             ts.Insert(0, js[0]);
           finally
             js.Free;
           end;
         end;


Edited by rweetch - 10 Aug 11 at 4:39PM
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: 10 Aug 11 at 4:35PM
Now just to work out how to that for HTML Text
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