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.
Related
I'm looking for a code-how that can bold selective words and/or lines of text within one of WPF's RichTextBoxes, so that, for example, I could have code that ensures the word bananabread would be automatically set to bold whenever it were typed. Another example of this could be setting an entire line to bold if it begins with the word "Therefore."
I'm aware that you can bold specific lines via XAML, and I know that pressing Ctrl + B can bold specific words while in the editor itself, but how can I go about doing this through C#?
I use a Header in my Migradoc documents. Right now I just add a Paragraph to the Header but it doesnt really fit my needs as I want to have lets say two texts that have a different Alignment. For example:
Middle-ALigned.Text Right-Aligned-Text
second line second line
Before I used two textframes and added them to the section (not as Header). That worked somehow but cant be the right choice as I want to print the text on every page and thats what headers are for.
So the question is how do I align the two texts differently in one paragraph or how do I get two paragraphs to appear on the same height in the header.
I hope someone can help with that.
Cheers
Keep it Simple: Use a Tab Stop
The best way to do this is the same as you would do in most word processing tools: with a right-aligned tab-stop, placed on the right margin of the page, with the "left" text, being center-aligned. This is pretty straight forward, but I couldn't find the "full" solution anywhere, so here's what you need:
// Grab the current section, and other settings
var section = documentWrapper.CurrentSection;
var footer = section.Footers.Primary;
var reportMeta = documentWrapper.AdminReport.ReportMeta;
// Format, then add the report date to the footer
var footerDate = string.Format("{0:MM/dd/yyyy}", reportMeta.ReportDate);
var footerP = footer.AddParagraph(footerDate);
// Add "Page X of Y" on the next tab stop.
footerP.AddTab();
footerP.AddText("Page ");
footerP.AddPageField();
footerP.AddText(" of ");
footerP.AddNumPagesField();
// The tab stop will need to be on the right edge of the page, just inside the margin
// We need to figure out where that is
var tabStopPosition =
documentWrapper.CurrentPageWidth
- section.PageSetup.LeftMargin
- section.PageSetup.RightMargin;
// Clear all existing tab stops, and add our calculated tab stop, on the right
footerP.Format.TabStops.ClearAll();
footerP.Format.TabStops.AddTabStop(tabStopPosition, TabAlignment.Right);
The hardest part of this, is figuring out what your tab stop position should be. Because I'm boring and really like encapsulation, I dynamically calculate the tab stop position, based on the page width, less the horizontal page margins. However, getting the current page width wasn't as easy as I'd thought it'd be, because I'm using PageFormat to set the page dimensions.
Next Challenge: Getting Your Page Width, Dynamically
I really hate having tightly coupled code (think: fan-in and fan-out), so even though I know at this point in time what my page width is, even to the point of hard-coding it, I still want to hard code it in only a single place, then refer to that one place everywhere else.
I keep a custom "has-a"/wrapper class to keep this stuff encapsulated into; That's documentWrapper in my code here. Additionally, I don't expose any of the PDFSharp/MigraDoc types to the rest of my application, so I'm using ReportMeta as a way to communicate settings.
Now for some code. When I setup the section, I'm using the MigraDoc PageFormat to define the size of my page for the current section:
// The tab stop will need to be on the right edge of the page, just inside the margin
// We need to figure out where that is
var tabStopPosition =
documentWrapper.CurrentPageWidth
- section.PageSetup.LeftMargin
- section.PageSetup.RightMargin;
// Clear all existing tab stops, and add our calculated tab stop, on the right
footerP.Format.TabStops.ClearAll();
footerP.Format.TabStops.AddTabStop(tabStopPosition / 2, TabAlignment.Center);
footerP.Format.TabStops.AddTabStop(tabStopPosition, TabAlignment.Right);
footerP.Format.Alignment = ParagraphAlignment.Center;
What's really important here, is that I'm storing the CurrentPageWidth, this becomes really important when setting up our tab stops. The CurrentPageWidth property, is simply a MigraDoc Unit type. I am able to determine what this is by using MigraDoc's PageSetup.GetPageSize with my chosen PageFormat.
Results
You can add TextFrames to the header - then they will appear on every page.
Or use one paragraph as header. Use TabStops to position the text (as in Word there are left-aligned, center-aligned, and right-aligned TabStops. With TabStops you have to deal with the linebreaks like this:
(TabStop)Middle Text(TabStop)RightText(LineBreak)(TabStop)MT Second Line(TabStop)RT Second Line.
See also:
https://stackoverflow.com/a/29250830/1015447
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
I wanted to find a way to set the document level properties in MigraDoc. For example I want to set all margins (top, left, right, bottom) to 5 or want to set the font for whole PDF document once. I don't want to set them in each section or paragraph. I know I can set them in sections but my document will have three different sections (header, contents and footer) therefore it is very annoying to repeat the same code for setting same properties in each section.
Moreover, I have set top margin to 5 for header section however top margin seems to be more than 5 (looks like at least 10). Thanks for help.
Margins set for the first section are inherited by the following sections. If you need the same margins for all sections, only set them for the first section.
Use a Style to set the font. Many styles are set by default (like in word), but you can add more styles as needed.
All styles are derived from the Normal style. Set the font for Normal only to change the font for the complete document.
To use a different style, specify its stylename at the paragraph.
See also:
http://pdfsharp.net/wiki/HelloMigraDoc-sample.ashx
(and the other samples)
Re Top Margin: some fonts reserve space for an ascender (accents, diacritical marks, ...) that may make the top margin look bigger than it is.
In my project I want to count lines displayed by richtextbox in C# with word wrap property set true. For example, in richtextbox, I write a text, and when text reaches the width of the richtextbox, then it automatically goes to second line. So what happens is the text contains actually one line but it is displayed in two lines. So I want to know how can I count this as two lines instead of one? Help will be really appreciated.
You may go for RichTextBox.GetLineFromCharIndex Method
Retrieves the line number from the
specified character position within
the text of the RichTextBox control. If WordWrap is set to false, no portion of the line wraps to the next, and the method returns 0 for the specified character index.
Also, check out this link.