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
Related
I recently started a project using PDF sharp + Migra Doc and I encounter a problem which I have seen in other posts, there is no fixing automatically. Table row will be generated on the next page if it doesn't have enough space and if there is still not enough space it will just go into the border and the text is lost. I am thinking of a workaround but I am not sure exactly how it can be done.
My think is as follows:
If I am able to check how many lines of text can fit in cell with the given string I can create a variable and increase it every time I add text. with the excess of text I can simply create a new row (which will be automatically be added on the next page) and thus fixing my problem. Even if I am not counting lines, is there a way to check if the row becomes too large for the current page? If at a given time I can check if the cell is too large and will be automatically sent to the next page I can trim the string up to the point it will fit, save the remaining words that didn't fit and maximise the space within the page.
this is how the document is generated currently
Is there a way to workaround this? That white space is useless and a waste of resources when it comes to a 30-40 pages document.
One extreme option: Make the layout in your code and use PDFsharp to draw the text.
See also:
https://forum.pdfsharp.net/viewtopic.php?f=8&t=3192
A MigraDoc cell can contain a mix of different fonts with different font attributes (regular, bold, ...) and sizes. Measuring the size and creating a new row can become complicated if you mix different fonts, but it can be simple if you only use a single font for your cell.
See also:
https://forum.pdfsharp.net/viewtopic.php?f=8&t=3196
The space problem with tables occur if table rows are rather large (more than just one or two lines of text). Maybe tables are not the best option to present the information. How strict are your requirements? Can you get away from tables?
The solution that finally worked was as follows:
set up the style for the document including the header
depending on the data used create a for-loop which will input the desired rows in the table
top of the loop must add a row in the document
save in a variable how many pages the document currently contains(initially declare as 1 before entering the loop)
clone the document checking if the document you are passing contains the same number or more than the current document. If the document contains more pages means that the row you inputted exceeds the page. I was able to achieve this by rendering the document every time I was adding a new row.
an inner loop is necessary to trim the text within the row. The way I did it is split the text into sentences and if it contains more than 3 sentences trim, otherwise just let go to the next page.
make sure you always delete the last row on the inner loop otherwise you will end up with the same data
It might not be the most efficient way but it renders 30+ pages documents in tables under 2 seconds on Azure servers. I hope this helps someone at some point.
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.
If I have a long string of text in which the font size and family is adjustable, and it gets texttrimmed a few lines into the TextBlock's window, how do I get the spot or IndexOf or whatever of the point where the string is cut off?
I guess one way to put this is, like an article that spans two pages, I would like to get the indexof the end of the first page so I can know the next word in the article to begin on the second page.
You could search for the cutoff point by iteratively calling GetPositionFromCharIndex.
In a Crystal report I am passing two text strings from C# application. Both parameters are text string paragraphs basically which can have any no of words in them.
The issue is I am not able to manage spacing between both paragraphcs. As they are dynamic I can't fix their hieghts. If there is more text passed one top paragraphc over laps the bottom paragraph but if there is less text in top paragraph report shows big area as empty space.
What ever the amount of text may be, the requriement is paragrachs should have constant space between them (two line breaks). Please guide me how I can manage it.
Thanks
Put these fields in different subsections.
Put those Parameteres inside a Text Object and then set Can Grow property of the Text Object as True.
Try this and get back with your results.
One of my applications deals with MS Word and Document creation/editing/formatting. I am using Office 2007 w/ VS 2008, and i'm coding against the Microsoft.Office.Interop.Word library, which seems to work with either 2003 or 2008.
I create a Textbox in a Document using the Document.Shapes.AddTextbox method, and then filling it with text. I'd like to be able to programmatically determine whether or not the text fits within the textbox, and if it doesn't, then reduce the font size until it does.
I've tried a couple different methods:
1) using the bool Shape.TextFrame.Overflowing property
while (textbox.TextFrame.Overflowing) // adjust font size
however, this returns TRUE even though when I open the document I can see the text fits in the box.
2) checking the X/Y position of the last character of the text, and seeing if that coordinate falls within the textbox boundaries
lastCharX = System.Convert.ToSingle (tb.TextFrame.TextRange.Characters.Last.get_Information (WdInformation.wdHorizontalPositionRelativeToPage));
lastCharY = System.Convert.ToSingle (tb.TextFrame.TextRange.Characters.Last.get_Information (WdInformation.wdVerticalPositionRelativeToPage));
bool outsideFrameBoundaries = lastCharX + lastCharWidth > frameBoundaryX || lastCharY + lastCharHeight > frameBoundaryY;
however, this returns X/Y that are almost always inside the box, though when I open the document I can't see the character because it doesn't fit in the box.
So I'm running out of ideas here, and i'm asking if anybody else has gone through this before and if they have suggestions for dealing with the inaccurate mess that is the word interop?
I came up with a solution.
It started when I figured out a method to Word's madness. When I get the X/Y coordinates for a character, and that character exists outside of the textbox area, then Word actually returns the correct X value but the Y value is the Y value of the last visible line on the textbox.
So I scan all characters starting from the end, and if I find duplicate coordinates then I know that there is overflow. I also have to check if the Y-value + the font size is greater than the bottom bound of the textbox. But this seems to work pretty reliably (if slowly) for detecting if a textbox is overflowing. Once I determine if it's overflowing, then I keep decreasing the font size until it is not.