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!
Fit Text to a non regular shape |
Post Reply |
Author | |
rweetch
Senior Member Joined: 22 Feb 11 Status: Offline Points: 173 |
Post Options
Thanks(0)
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!
|
|
Rowan
Moderator Group Joined: 10 Jan 09 Status: Offline Points: 398 |
Post Options
Thanks(0)
|
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.
|
|
rweetch
Senior Member Joined: 22 Feb 11 Status: Offline Points: 173 |
Post Options
Thanks(0)
|
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?
|
|
Rowan
Moderator Group Joined: 10 Jan 09 Status: Offline Points: 398 |
Post Options
Thanks(0)
|
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.
|
|
rweetch
Senior Member Joined: 22 Feb 11 Status: Offline Points: 173 |
Post Options
Thanks(0)
|
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 |
|
rweetch
Senior Member Joined: 22 Feb 11 Status: Offline Points: 173 |
Post Options
Thanks(0)
|
Now just to work out how to that for HTML Text
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store