Dynamic sized multi line TextBox field in a PDF - c#

I have created a document in an open office with a multi-line form field:
The issue I am having is when the dynamic content exceeds the initial size of the multi-line text box:
Sure I can re-size the Text Box in the original template but the dynamic content may be from 1 to 50 lines and I want the text after the Text Box to be close to the last line of dynamic content.
Can someone suggest a way to solve this?

I have once coded a solution to set the width and height of a textbox programmatically based on the characters supplied. I think this was a school assignment a long time ago.
This can be done with both VBA in a code behind or probably with a macro even. Or with VB.net.
I don't have the code I used way back when, but basically determine the maximum width you are able to provide in character width, the preferred width. Determine the pixel requirement per character for that width. This becomes the textbox width.
Divide your total string character count by your preferred width character count. Round up, calculate the pixel height per character. And use this value times the rounded result for the textbox height. Dirty but it should work.
Any chance you can change to a label and set AutoSize to True? You can fix the width and let the height auto adjust. This should be done before converting to a pdf. In fact all of the sizing should be resovled before pdf conversion.
Another Down voter without a comment, should not be allowed.

Related

How to maintain long text inside RDLC report column ?

I have tried a lot to maintain long text inside RDLC report's columns but it doesn't seem to be adjustable. When some long text appears inside any column then it disturbs the whole report. How to control it, so the text keeps extending downwards in proper and good manner.
Try and put a fixed Column Width and set CanGrow to False and make sure that the Row has it set on True.
If that doesn't work you'll have to edit your datasource before giving it to the reporter. You must break the value into multiple lines based on the length of the string. You can achieve this by inserting System.Environment.NewLine every time it exceeds the size. The exact length at which you need to insert the line breaks depends on your maximum column width and you'll have to calculate this yourself by trial and error until you find the perfect fit.
Edit: Including step by step process for adding break lines based on text size.
Calculate the length of the string and add Environment.NewLine where needed to force the text to break to a new line.
Use Graphics.MeasureString to calculate the size of your text in pixels.
Check if the width exceeds the maximum length of your TextBox.
If the string fits, add it to the final string and continue to step 4.
If the string doesn't fit, continue to step 3.
Remove a character of the string, insert that character to the front of a new (second) sting and repeat step 1. again until the
first string fits.
Check if the second string is empty.
If the second string is empty, we're finished. (The final string can be added to the TextBox / new datasource).
If the second string isn't empty, add an Environment.NewLine at the end of the final string and replace the first string with the
second one and make the second string empty again, repeat the whole
process.
There might be ways of improving this process. For example by breaking the text in fixed predefined intervals and refining it afterwards. Or if there are actual words divided by spaces you could add and remove words instead of characters.
Cut the long-length textbox.
Drag and drop a rectangle there.
Paste the textbox inside the rectangle.
Set rectangle's borders
as the textbox was.
Note: your textbox must be Cangrow:true

How do you calculate pixel size of string?

I have a string. I know the font family and the font size it is going to be displayed in. I need to know how many pixels the text will take up in the ui. So that I can determine whether to show another element. How would I do that?
I found a couple of things, but none of them were available in my Windows universal project. For example:
Graphics.MeasureString
TextRenderer.MeasureText
Edit:
This is not a web project.
I want to calculate the size it will take in the ui before it is in the ui.
I think you need to create a textblock in code and assign the desired text to it. Then you can get the actual height and width from it. See the below code
TextBlock txt=new TextBlock();
//set additional properties of textblock here . Such as font size,font family, width etc.
txt.Text = "your text here";
var height = txt.ActualHeight;
var width = txt.ActualWidth;
You can do further operations based on this height and width
I am not saying this is the optimized solution .But this will work for you
Try checking the values of the Width and Height properties of the control you use to display your text (eg. your TextBox), after setting your string as text/content, to decide whether to show another element.

Get rid of ugly CustomEditor spacing

I've been making my own event management system because I don't want to pay money for Playmaker:
I'm getting this really terrible spacing between labels and their components (for example, in the picture above, between Nickname and it's text field)
The script can be found here (keep in mind, its a work in progress. I haven't had time to clean it all up):
http://pastebin.com/w2cLWBvh
It looks like that layout system you've been using aims to give both the nickname label and text input field nearly the same amount of space within their combined area.
Without knowing an awful lot about what layout options Unity's GUI system has, you can probably do with setting the length of the label and textbox arbitrarily.
Here's how you can get the size of a label given a specific string:
GUI.skin.GetStyle("Label").CalcSize(new GUIContent(widestIdString));
So say you have a new BeginArea containing your label and textbox combo. You'd set the label length to this newly calculated width, and the textbox width to the difference of the Area's width and the label's width, plus an arbitrary distance to seperate them, such as 23f;

Limit text to width of TextBox

I'm using a TextBox to create an editable title on something that looks like a post-it note. I changed to a TextBox from a RichEditBox to see if that could solve my problem, which it didn't, so I'm willing to change back if that helps.
My problem is that I don't want the user to be able to enter more characters than fit in the set width of the TextBox, because I want the whole title to be visible. Setting a fixed limit to the amount of characters that can be entered doesn't really work since for example 10 large M's would fill the width of my TextBox, but other characters will only fill half of it. So I would like to compare the width of the text to the width of the TextBox, so I can restrict input beyond that point.
Edit: I'm using the Segoe UI font, and I don't really consider changing the font to one with characters of equal width as a solution.
Set the TextBox Font to a Courier Font, then all characters are equal width and calculating max becomes trivial.
I am suck in programming world. i m try help you..

How to make the grid content to be viewed with out varying the size

Hi all i am having a text file which consists of some data and each and every line in that particular is fixed to 94. Now when the user opened the particular text file and if my condition satisfies i will show it to datagridview. But when displaying to datagridview even the length of each and every line is 94 the content displaying in grid varies why it is happening . How to make sure that each and every row in datagridview should be displayed in a constant way
Any idea please
You're using a non-proportional font in the grid, which means that not all characters have the same size. F.e. spaces are way shorter then the 0. Use a proportional font, and the lines will be the same length.
Edit: Let's have a look at an example:
This is a non-proportional font,
the line will have different lengths,
though they are 10 characters long:
1234567890
adilngvzus
Now let's look at a proportional font:
1234567890
adilngvzus
As you can see, in a proportional font (like your IDE is most likely using) every characters has the same width. In a non-proportional font (like your text-processor is most likely using by default) the characters are varying in width, making the i one of the 'thinest' and the O one of the 'widest' characters.

Categories

Resources