iText. How to adjust header width (C#)? - c#

I need adjust header width of the table created with iText. Column width set with table.SetWidths(lstMaxCount.ToArray()) method, that is standard way to do this, but is there way to adjust column header width to avoid break line?
Here is how it look like now:

I think one solution would be to make the header display on 2 rows for the columns with small width.
My suggestion would be to split PackageNumber column name in two words, and put a new line inside:
"Package" + Environment.NewLine + "Number"
Make your header height enough to fit 2 lines of text in it.
Set the PdfPCell's property NoWrap = false
There are also another options to wrap a text on multiple lines. You can use Paragraphs and Chunks. You can take a look here: http://itextpdf.com/examples/iia.php?id=35enter link description here

Related

How to set data to resize depending on columns and vise versa inside datagridview using C#?

I have one problem. When ever I try to print my datagridview it always splits in half, so what I wanna do is to find a way to set length of column name adapt to data inside the column or to set that data adapts to column name. Its not the best explanation but take a look at the pictures:
This is what I have now:
This is what I want:
So basically I want the name of the column and data inside the rows to be visible but to take as minimum space as they can, depending on what length is bigger, If column name is bigger, adapt to that, if data length is bigger, adapt to that. Any solution for my problem?
Set the following property:
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
See here the documentation for DataGridViewAutoSizeColumnsMode member AllCells:
The column widths adjust to fit the contents of all cells in the
columns, including header cells.

PDFsharp MigraDoc set height of element

Is there a way to set fixed height of an element? Could be a table, row or section. This element is dynamically generated from database and it can have a variable number of rows. I need to do that, because the section below needs to be in a fixed position for print out. I am using WPF v1.31. I know it is not the latest, but it's an addition to a quite old application.
You can set the height of a Paragraph or a table Row.
I think you cannot set the height of a Table - but that will be the sum of the heights of all rows. Automatic page breaks will make things complicated if a table does not fit a single page.
A Section always starts on a new page.
TextFrame can be used to place text at a fixed position. Depending on the requirements, this could be simple or complicated.
You can prepare a document to let MigraDoc determine sizes and positions. Then you code can decide whether the items with the fixed position will be on the same page or on a new page.
Here is sample code that shows how to show the progress while creating a PDF:
http://forum.pdfsharp.net/viewtopic.php?f=8&t=3172
The same technique can be used to stitch several MigraDoc documents together to create a single PDF. If I understand your requirements correctly, this could be the way to go - without setting the height of any elements.

How to set a min width before word-wrap inside an Asp.net Grid View column iif that columns text is at least certain length. ex 50 words

...without knowing how many columns the grid view may have or which columns will contain a lot of text. (Auto resize all other columns)
I have a grid view on a webpage that is generated from a database and it displays different columns in different orders depending on the user or user groups. Typically, it is displaying somewhere between 15 and 30 columns. For some user/user groups all of the columns can fit on the screen without any text wrapping too much, for others even after the grid view auto sizes all of the columns to be as small as possible it doesn’t all fit on the screen requiring a horizontal scroll bar and it’s then forcing the columns with large amount of text to wrap after only one or two words.
I am trying to figure out if there is a way to stop a column from resizing to a tiny size if its content is really long and instead wrap only after a certain size (assuming that the content of that column is large enough to require the column to be that “certain size” to begin with) however I can’t know which column is going to have a ton of words since each user / user group can modify which columns they use, which are displayed, and what each column is called. (So I can’t hard code a specific column to be a minimum/specific width)
Example
If for example a column has text that is long than say, 50 words, I want to set that column to only word wrap after at least 4 or 5 words have already been displayed on the first line (or a certain pixel size) But if a column is smaller than that I want the column to become as small as possible so that as many rows / columns can be visible on the screen as possible. I don’t mind the horizontal scroll but I am trying to get the wrapped text to not wrap more than 5 or so lines. (Currently it’s wrapping like 15-30 lines leaving 1 -2 words on a line)
Example – What I want
UserGroup1
This is what I would like to happen (The column with the long text is kept large enough to read multiple words before wrapping
Example -- What I’m currently getting
UserGroup1 (This only happens to users groups who have a ton of columns, other user groups are able to fit everything on the screen without ridiculous word wrap)
Example of what I'm currently getting -- Row with lots of columns is word wrapping every word or two causing the row to take up ton of space on the site. (Made image a bit smaller since its so tall)
This User/User group also has so many columns set to display that it has a horizontal scroll making it difficult for users to get to easily read the data.
Additional Example
Example of a different user group who has less columns and a different order.
Description
This is an example of a different user/user groups gridview display. This user/user group has chosen to have a lot less columns and all of the columns have no problem fitting on the page. This gridview does not have a horizontal scroll bar and already wraps nicely due to less columns.
This grid view automatically resizes the smaller columns and makes the column with more data bigger because it doesn’t need to try to fit a ton of columns on the page. This example is similar to the "What I want" example, except it has less columns so the description column is wider.

AutoResize Not Working Properly When ColumnHeader Is Longest String

dgvSampled.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
I'm trying to size the columns with the AllCells mode. The problem is that when the longest string in the column is the header, a buffer is left over.
Compare the Requested column to the Coil # column. Why does the Coil # column size itself perfectly to its content, but the Requested column sizes itself too large for its header title?
After making the columns unable to be sorted, they are now being sized as I expected them to be in the first place.
From the documentation (emphasis mine):
AllCells: The column widths adjust to fit the contents of all cells in the columns, including header cells.
From your description, it seems that what you want is DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader

Trimming header's captions in DevExpress' GridView(6.3v)

I am having the problem with setting character elipsis triming, both with word wrapping option in GridView component.
I have changed the height of the header to about 40 px, then set: HeaderPanel.TextOptions.
Trimming to: EllipsisCharacter.
I saw then that single line is trimmed with ellipsis added - successfully.
Next step was to add word wrapping to Wrap. Then ellipsis is never added and
I can see only words of the header caption which fits in the width of the column.
How Can I correctly wrap the header with ellipsis being added when the caption doesn't fit?
Thanks
Wrap and elipsis are rivals. You can use either one or the other.

Categories